{"id":16731239,"url":"https://github.com/rohit-chouhan/pysql","last_synced_at":"2025-03-21T21:31:16.194Z","repository":{"id":37269004,"uuid":"377961455","full_name":"rohit-chouhan/pysql","owner":"rohit-chouhan","description":"PySQL is database framework for Python (v3.x) Language, Which is based on Python module mysql.connector, this module can help you to make your code more short and more easier.","archived":false,"fork":false,"pushed_at":"2024-01-20T17:00:03.000Z","size":552,"stargazers_count":16,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T05:23:36.503Z","etag":null,"topics":["ai","database","framework","mysql","python","sql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rohit-chouhan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-17T21:10:20.000Z","updated_at":"2023-10-05T09:03:35.000Z","dependencies_parsed_at":"2023-10-15T01:56:58.672Z","dependency_job_id":"6915b860-7a49-416d-bf01-e8bb7b60da32","html_url":"https://github.com/rohit-chouhan/pysql","commit_stats":{"total_commits":4085,"total_committers":2,"mean_commits":2042.5,"dds":0.0002447980416157014,"last_synced_commit":"9cdb1a219003eeb90d4b504950c49940d9963aff"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit-chouhan%2Fpysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit-chouhan%2Fpysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit-chouhan%2Fpysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rohit-chouhan%2Fpysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rohit-chouhan","download_url":"https://codeload.github.com/rohit-chouhan/pysql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244874168,"owners_count":20524576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","database","framework","mysql","python","sql"],"created_at":"2024-10-12T23:36:21.773Z","updated_at":"2025-03-21T21:31:15.729Z","avatar_url":"https://github.com/rohit-chouhan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[](https://luciopaiva.com/markdown-toc/)\n![PySQL Framework](https://i.ibb.co/3FmsWch/mWQTLXjU.gif)\n\nPySQL is database framework for Python (v3.x) Language, Which is based on Python module mysql.connector, this module can help you to make your code more short and more easier. Before using this framework you must have knowledge about list, tuple, set, dictionary because all codes are designed using it. It's totally free and open source.\n## Tutorial Video in English ([Watch Now](https://www.youtube.com/watch?v=8SQcq0a_UEg))\n[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/8SQcq0a_UEg/mqdefault.jpg)](https://www.youtube.com/watch?v=8SQcq0a_UEg)\n## Installation\nBefore we said that this framework is based on mysql.connector so you have to install mysql.connector first on your system. Then you can import pysql and enjoy coding!\n\u003e python -m pip install mysql-connector-python\n\n\nAfter Install mysql.connector successfully create Python file download/install pysql on the same dir where you want to create program. You can clone is using git or npm command, and you can also downlaod manually from repository site.\n\n#### PyPi Command\nGo to [https://pypi.org/project/pysql-framework/](https://pypi.org/project/pysql-framework/) or use command\n```sh\npip install pysql-framework\n```\n\n#### Git Command\n```sh\ngit clone https://github.com/rohit-chouhan/pysql\n```\n#### Npm Command\nGo to [https://www.npmjs.com/package/pysql](https://www.npmjs.com/package/pysql) or use command\n```sh\n$ npm i pysql\n```\n\n#### Snippet Extention for VS Code\nInstall From Here [https://marketplace.visualstudio.com/items?itemName=rohit-chouhan.pysql](https://marketplace.visualstudio.com/items?itemName=rohit-chouhan.pysql)\n\n[![IMAGE ALT TEXT HERE](https://i.ibb.co/L9LNWb8/pysql.png)](https://marketplace.visualstudio.com/items?itemName=rohit-chouhan.pysql)\n# Table of contents\n  - [Connecting a Server](#connecting-a-server)\n  - [Create a Database in Server](#create-a-database-in-server)\n  - [Drop  Database](#drop--database)\n  - [Connecting a Database](#connecting-a-database)\n  - [Creating Table in Database](#creating-table-in-database)\n  - [Drop Table in Database](#drop-table-in-database)\n  - [Selecting data from Table](#selecting-data-from-table)\n  - [Add New Column to Table](#add-new-column-to-table)\n  - [Modify Column to Table](#modify-column-to-table)\n  - [Drop Column from Table](#drop-column-from-table)\n  - [Manual Execute Query](#manual-execute-query)\n  - [Inserting data](#inserting-data)\n  - [Updating data](#updating-data)\n  - [Deleting data](#deleting-data)\n\n\n### Connecting a Server\n------------\nTo connect a database with localhost server or phpmyadmin, use connect method to establish your python with database server.\n\n```python\nimport pysql\n\ndb = pysql.connect(\n\t\"host\",\n\t\"username\",\n\t\"password\"\n )\n```\n### Create a Database in Server\n------------\nCreating database in server, to use this method\n\n```python\nimport pysql\n\ndb = pysql.connect(\n\t\"host\",\n\t\"username\",\n\t\"password\"\n )\n pysql.createDb(db,\"demo\")\n #execute: CREATE DATABASE demo\n```\n### Drop  Database\n------------\nTo drop database use this method .\n##### Syntex Code -\n```python\npysql.dropDb([connect_obj,\"table_name\"])\n```\n##### Example Code -\n```python\npysql.dropDb([db,\"demo\"])\n#execute:DROP DATABASE demo\n```\n### Connecting a Database\n------------\nTo connect a database with localhost server or phpmyadmin, use connect method to establish your python with database server.\n\n```python\nimport pysql\n\ndb = pysql.connect(\n\t\"host\",\n\t\"username\",\n\t\"password\",\n\t\"database\"\n )\n```\n### Creating Table in Database\n------------\nTo create table in database use this method to pass column name as key and data type as value.\n##### Syntex Code -\n```python\n\npysql.createTable([db,\"table_name_to_create\"],{\n    \"column_name\":\"data_type\", \n    \"column_name\":\"data_type\"\n})\n```\n##### Example Code -\n```python\n\npysql.createTable([db,\"details\"],{\n    \"id\":\"int(11) primary\", \n     \"name\":\"text\", \n    \"email\":\"varchar(50)\",\n    \"address\":\"varchar(500)\"\n})\n```\n##### 2nd Example Code -\nUse can use any Constraint with Data Value\n```python\n\npysql.createTable([db,\"details\"],{\n    \"id\":\"int NOT NULL PRIMARY KEY\", \n     \"name\":\"varchar(20) NOT NULL\", \n    \"email\":\"varchar(50)\",\n    \"address\":\"varchar(500)\"\n})\n```\n### Drop Table in Database\n------------\nTo drop table in database use this method .\n##### Syntex Code -\n```python\npysql.dropTable([connect_obj,\"table_name\"])\n```\n##### Example Code -\n```python\npysql.dropTable([db,\"users\"])\n#execute:DROP TABLE users\n```\n### Selecting data from Table\n------------\nFor Select data from table, you have to mention the connector object with table name. pass column names in set.\n##### Syntex `For All Data (*)`-\n```python\nrecords = pysql.selectAll([db,\"table_name\"])\nfor x in records:\n  print(x)\n```\n##### Example - -\n```python\nrecords = pysql.selectAll([db,\"details\"])\nfor x in records:\n  print(x)\n#execute: SELECT * FROM details\n```\n##### Syntex `For Specific Column`-\n```python\nrecords = pysql.select([db,\"table_name\"],{\"column\",\"column\"})\nfor x in records:\n  print(x)\n```\n##### Example - -\n```python\nrecords = pysql.select([db,\"details\"],{\"name\",\"email\"})\nfor x in records:\n  print(x)\n#execute: SELECT name, email FROM details\n```\n\n##### Syntex `Where and Where Not`-\n```python\n#For Where Column=Data\nrecords = pysql.selectWhere([db,\"table_name\"],{\"column\",\"column\"},(\"column\",\"data\"))\n\n#For Where Not Column=Data (use ! with column)\nrecords = pysql.selectWhere([db,\"table_name\"],{\"column\",\"column\"},(\"column!\",\"data\"))\nfor x in records:\n  print(x)\n```\n##### Example - -\n```python\nrecords = pysql.selectWhere([db,\"details\"],{\"name\",\"email\"},(\"county\",\"india\"))\nfor x in records:\n  print(x)\n#execute: SELECT name, email FROM details WHERE country='india'\n```\n### Add New Column to Table\n------------\nTo add column in table, use this method to pass column name as key and data type as value.\nNote: you can only add one column only one call\n##### Syntex Code -\n```python\n\npysql.addColumn([db,\"table_name\"],{\n    \"column_name\":\"data_type\"\n})\n```\n##### Example Code -\n```python\n\npysql.addColumn([db,\"details\"],{\n    \"email\":\"varchar(50)\"\n})\n#execute: ALTER TABLE details ADD email varchar(50);\n```\n### Modify Column to Table\n------------\nTo modify data type of column table, use this method to pass column name as key and data type as value.\n##### Syntex Code -\n```python\npysql.modifyColumn([db,\"table_name\"],{\n    \"column_name\":\"new_data_type\"\n})\n```\n##### Example Code -\n```python\npysql.modifyColumn([db,\"details\"],{\n    \"email\":\"text\"\n})\n#execute: ALTER TABLE details MODIFY COLUMN email text;\n```\n### Drop Column from Table\n------------\nNote: you can only add one column only one call\n##### Syntex Code -\n```python\npysql.dropColumn([db,\"table_name\"],\"column_name\")\n```\n##### Example Code -\n```python\npysql.dropColumn([db,\"details\"],\"name\")\n#execute: ALTER TABLE details DROP COLUMN name\n```\n### Manual Execute Query\n------------\nTo execute manual SQL Query to use this method.\n##### Syntex Code -\n```python\npysql.query(connector_object,your_query)\n```\n##### Example Code -\n```python\npysql.query(db,\"INSERT INTO users (name) VALUES ('Rohit')\")\n```\n\n### Inserting data\n------------\nFor Inserting data in database, you have to mention the connector object with table name, and data as sets.\n##### Syntex -\n```python\ndata = \t{\n\t\"db_column\":\"Data for Insert\",\n\t\"db_column\":\"Data for Insert\"\n}\npysql.insert([db,\"table_name\"],data)\n```\n##### Example Code -\n```python\ndata = \t{\n\t\"name\":\"Komal Sharma\",\n\t\"contry\":\"India\"\n}\npysql.insert([db,\"users\"],data)\n```\n\n### Updating data\n------------\nFor Update data in database, you have to mention the connector object with table name, and data as tuple.\n##### Syntex `For Updating All Data`-\n```python\ndata = (\"column\",\"data to update\")\npysql.updateAll([db,\"users\"],data)\n```\n##### Example - -\n```python\ndata = (\"name\",\"Rohit\")\npysql.updateAll([db,\"users\"],data)\n#execute: UPDATE users SET name='Rohit'\n```\n##### Syntex `For Updating Data (Where and Where Not)`-\n```python\ndata = (\"column\",\"data to update\")\n#For Where Column=Data\nwhere = (\"column\",\"data\")\n\n#For Where Not Column=Data (use ! with column)\nwhere = (\"column!\",\"data\")\npysql.update([db,\"users\"],data,where)\n```\n##### Example - \n```python\ndata = (\"name\",\"Rohit\")\nwhere = (\"id\",1)\npysql.update([db,\"users\"],data,where)\n#execute: UPDATE users SET name='Rohit' WHERE id=1\n```\n### Deleting data\n------------\nFor Delete data in database, you have to mention the connector object with table name.\n##### Syntex `For Delete All Data`-\n```python\npysql.deleteAll([db,\"table_name\"])\n```\n##### Example - -\n```python\npysql.deleteAll([db,\"users\"])\n#execute: DELETE FROM users\n```\n##### Syntex `For Deleting Data (Where and Where Not)`-\n```python\nwhere = (\"column\",\"data\")\n\npysql.delete([db,\"table_name\"],where)\n```\n##### Example - \n```python\n#For Where Column=Data\nwhere = (\"id\",1)\n\n#For Where Not Column=Data (use ! with column)\nwhere = (\"id!\",1)\npysql.delete([db,\"users\"],where)\n#execute: DELETE FROM users WHERE id=1\n```\n## --- Finish ---\n#### Change Logs\n```sh\n[19/06/2021]\n - ConnectSever() removed and merged to Connect()\n - deleteAll() [Fixed]\n - dropTable() [Added]\n - dropDb() [Added]\n \n[20/06/2021]\n - Where Not Docs [Added]\n```\n\nThe module is designed by [Rohit Chouhan](https://www.linkedin.com/in/itsrohitchouhan/), contact us for any bug report, feature or business inquiry.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohit-chouhan%2Fpysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frohit-chouhan%2Fpysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frohit-chouhan%2Fpysql/lists"}