This will generate a crud operations (crud.py) for your Database tables.
Project description
crud_generator
This will generate a crud operations (crud.py) for your Database tables.
How to Use:
Step 1:
- from crud_generator import generate_crud
- generate_crud(tablename, attributes) is the function which will create crud_tablename.py file
- Table name and attributes/column name are the only two parameters to be passed.
- Eg: generate_crud("Employee","Name,Age,Employee_code,Salary")
- then this will automatically create py file.
Step 2:
-
functions created by the functions are
#First:
-
def create_conn():
-
this function is an empty function where you can create your connections. You can choose any DB, import library accordingly.
-
Following is the code which you will get.
-
def create_conn():
-
pass
-
#Enter your connection code
-
#Example: for postgresql
-
#conn = psycopg2.connect(database = "testdb", user = "postgres", password = "pass123", host = "127.0.0.1", port = "5432")
-
#then return conn
#Second:
-
def create_tablename(values):
-
this function will perform insert operation in table.
-
Here, you just need to pass values of the attributes
-
Eg: create_Employee("""'Alex',26,'EMP_2760',29000""") #Name,Age,Employee_code,Salary
-
You can see the sql query in CLI
-
Ensure to pass values as raw input.
#Third:
-
def read_Employee(condition="1=1"):
-
this function will perform read operation in table.
-
Here, if you don't pass any parameters it will return all records or you can pass any condition.
-
Eg: read_Employee("Salary=2900 and Employee_code='EMP_2760'") # condition similary to that in where clause can be passed here.
-
You can see the sql query in CLI
#Fourth:
-
def update_Employee(values,condition="1=1"):
-
this function will perform update operation in table.
-
Here, if you don't pass any condition it will perform update on all records or you can pass any condition.
-
Here, you can pass values like "salary=30000", just like you pass in sql.
-
Eg: update_Employee("Salary=30000","Name='Alex'") # condition similary to that in where clause can be passed here and values like that in update statement.
-
You can see the sql query in CLI
#Fifth:
-
def delete_Employee(condition="1=1"):
-
this function will perform delete operation in table.
-
Here, if you don't pass any parameters it will delete all records or you can pass any condition.
-
Eg: delete_Employee("Salary=2900 and Employee_code='EMP_2760'") # condition similary to that in where clause can be passed here.
-
You can see the sql query in CLI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crud_generator-1.0.2-py3-none-any.whl.
File metadata
- Download URL: crud_generator-1.0.2-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c541adbd4aa0930d5d9f070be902da9e488a13dd316bf72b6b083a70179ac77f
|
|
| MD5 |
c1087c458e2695c13274368c10d2e501
|
|
| BLAKE2b-256 |
e325b360baed4619ec12b47ecc17ddbf0545a70ffcf57d1774c74957844893f7
|