Skip to main content

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:

  • 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

  • #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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

crud_generator-1.0.1-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page