#!/usr/bin/python # # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Object InterFace Manual # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # author: # surajsinghbisht054@gmail.com # https://www.bitforestinfo.com # # # About sqlorm: # A Python object relational mapper for SQLite3. # # Reference: https://www.sqlite.org/lang.html # https://docs.python.org/3/library/sqlite3.html # # Import: # from sqlorm import Model, Field #
Output : [1]
Input : [2]
# Import Module fromsqlormimport Field, Model
Output : [2]
Input : [3]
# Creating A Database Models Structure # # Here, "TestingDataBase" is used as default Sqlite Database File Name classTestingDataBase(Model): # Creating New Table. Name="AboutTeachers" classAboutTeachers: # Creating 4 Columns. Name = Name, Age, Income, Phone # #Columns Datatype Name = Field.String Age = Field.Integer Income = Field.Integer Phone = Field.LongInt #
# Creating New Table. Name="AboutBooks" classAboutBooks: # Creating 4 Columns. Name = Name, Price, Class # # Columns DataType Name = Field.String Price = Field.Integer Class = Field.String #
# Creating New Table. Name="AboutStudents" classAboutStudents: # Creating 4 Columns. Name = Name, Age, Class, Phone # #Columns Datatype Name = Field.String Age = Field.Integer Class = Field.String Phone = Field.LongInt #
Output : [3]
Input : [4]
# # ===================================== # =========== DataBase ================ # ===================================== # # connect(path="", dbname=None) --> Connect To Database # close() --> Close Database # save() --> Save All Changes # get_db_names() --> Get Default Database Name # get_all_columns_(TableName) --> Get All Columns Name List # get_all_table_with_class() --> Get All Tables With Class Object As Dictonery # get_all_tables_name() --> Get All Tables Name # get_tables() --> Get All Tables Object # Table(name=None) --> Get Table Object # # Create Object For InterFace DBase = TestingDataBase()
# Connect To DataBase DBase.connect() # or # DBase.connect(dbname="Testing_DataBase")
# Get All Columns Names From Tables for table in DBase.get_all_tables_name(): print"Table Name : {}".format(table) print DBase.get_all_columns_(table) # As List
# Default Database Name print DBase.get_db_names()
Output : [7]
TestingDataBase
Input : [8]
# # # ===================================== # ============= Table ================= # ===================================== # # new() --> New Row Interface # insert(**kwargs) --> Insert New Values Into Row, id argument Required # update(id=None, data={}) --> Update Values Into Row # delete(id) --> Delete Row , Id argument Required # search(**kwargs) --> Search Row Object InterFace # get_all() --> Get All Row Object InterFace as list # has(id) --> Check Row # columns_name() --> Get All Columns Names As List # save() --> Save All Changes # get_tables_name() --> Get Current Object Table Name # table_access(TableName) --> Change Current Object Table Access # # # Get Table Interface t = DBase.Table(name="AboutTeachers") # or t = DBase.get_tables()["AboutTeachers"]
print t
Output : [8]
<TableControls:AboutTeachers>
Input : [9]
# # ===================================== # ============= Row =================== # ===================================== # # get_all() --> Get All Values In Dictionery # set_all(**kwargs) --> Set Values # save() --> Save Changes Into Database # # # Create New Row Object Interface nr = t.new()
# Save Data Values In Database nr.save() # # You Don't Need To Create New Row Object Again And Again. # Because After Saving Data., # Row Object Interface Reset Automatically. # And Then You Can Use Object
Output : [12]
True
Input : [13]
# Get All Values From Row Object Interface After Saving print nr.get_all()