Package: dori-orm
My ORMIt's a simple ORM built with Python and sqlite.This is not a real ORM to use in your project.Use My ORMYou can see sample codes inexamples.py.I will be glad if you cooperate in the development of this project 😊Install My ORMpip install dori-ormImportsImport DB, ResultConfig, operators and columns from thedori-ormlibrary.DB: For create classes and database table.ResultConfig: Change the result, e.g. ordering and limit.operators: SQL operators like AND, OR, NOTcolumns: To create table columns with specificdata typeandconstraints. For exampleage = columns.Integer(nullable=False)meansage INTEGER NOT NULLfromdori_ormimportDB,ResultConfigfromdori_orm.operatorsimportAND,OR,NOTfromdori_ormimportcolumnsCreate TableCreate class and inheritance fromDB, tables created automatically in database(set db name with file name) when you inheritance from DB, you can define class variable and usecolumnsto create table column.classPerson(DB):name=columns.Text(nullable=False)family=columns.Text(nullable=False)age=columns.Integer()phone=columns.Integer()salary=columns.Real(default=100_000)classSchool(DB):name=columns.VarChar(nullable=False,unique=True)created_at=columns.Date()address=columns.Text()students_count=columns.SmallInt(default=300)classStudent(DB):person=columns.ForeignKey(Person)school=columns.ForeignKey(School)class_name=columns.VarChar()Insert DataInsert data to table with create instance from class. this code create two row in database with this arguments.person1=Person(name='Mohammad',family='Dori',age=20,phone=1234567890,salary=110_000,)print(person1.age)# 20person2=Person(name='John',family='Gits',age=30,phone=1234567890,)Select DataSelect rows from table.allmethod select all rows from table.getmethod, select all rows with defined columns.filtermethod select all rows that match the given conditions.print(Person.all())# Result:[<'id':1,'name':'Mohammad','family':'Dori','age':20,'phone':1234567890,'salary':110000.0>,<'id':2,'name':'John','family':'Gits','age':30,'phone':1234567890,'salary':100000.0>]print(Person.get('id','name','family'))# Result:[<'id':1,'name':'Mohammad','family':'Dori'>,<'id':2,'name':'John','family':'Gits'>]print(Person.filter(id=1,name='Mohammad'))# Result:[<'id':1,'name':'Mohammad','family':'Dori','age':20,'phone':1234567890,'salary':110000.0>]Advance FilteringYou can use operators in filter method. like AND, OR, NOT, BETWEEN, LIKE, IN, =, !=, <, <=, >, >=.AND: e.g.AND(x='', y=123)that meansx='' AND y=123rows=Person.filter(AND(id=2,name='Ali'))OR: e.g.OR(x='', y=123)that meansx='' OR y=123rows=Person.filter(OR(id=2,name='Ali'))NOT: e.g.NOT(OR(x='', y=123))that meansNOT (x='' OR y=123)rows=Person.filter(NOT(AND(id=2,name='Ali')))You can use another operator in operator.rows=Person.filter(OR(OR(name='Ali',id=2),OR(salary=10,age=20)))BETWEEN: Return row, if it value between x and y.print(Person.filter(id__between=(2,8)))LIKE: Use pattern with % and _ to filter rows.print(Person.filter(name__like='Mo%',config=ResultConfig(limit=2,order_by='age',)))lt: less than, means<print(Person.filter(id__lt=5))lte: less than or equal, means<=print(Person.filter(id__lte=5))gt: greater than, means>print(Person.filter(id__gt=5))gte: greater than or equal, means>=print(Person.filter(id__gte=5))not: not equal, means!=print(Person.filter(id__n=5))You can use any filter together.print(Person.filter(OR(id__n=5,name__in=('Mohammad','Salar'),age__gte=8)))Result Methodsresult.count()return count of results.result.first()return first row in result.result.last()return last row in result.not_mohammad=Person.filter(name__n='Mohammad')print(not_mohammad.count())print(not_mohammad.first())print(not_mohammad.last())Iterate on result.forrowinnot_mohammad:print(row.name)row.remove()# row.update(...)Update Rowperson1=Person(name='Mohammad',family='Dori',age=20,phone=1234567890,salary=110_000,)print(person1)person1.update(name='Salar')print(person1)Table Class Methodmax: Return maximum value of column.print(Person.max('salary'))min: Return minimum value of column.print(Person.min('salary'))sum: Return sum of column values.print(Person.sum('salary'))avg: Return average of column values.print(Person.avg('salary'))count: Return count of rows in table.print(Person.count())first: Return first row of table.print(Person.first())last: Return last row of table.print(Person.last())Result configurationlimitLimit the number of result rows.order_byOrder result by columns.reverseUse with order_by, False means sort ASC and True means sort DESC.print(Person.all(config=ResultConfig(order_by='id',reverse=True)))print(Person.get(config=ResultConfig(limit=5)))Foreign Keyperson1=Person(name='Mohammad',family='Dori',age=20,phone=1234567890,salary=110_000,)school1=School(name='The Sample School',created_at='2002-01-04',address='1600 Amphitheatre Parkway in Mountain View, California',)print(school1)student=Student(person=person1,school=school1,class_name='A3',)print(school1.id)print(person1.id)print(student)Change EasyRemoveclass_namecolumn and add gpa column. now add a row to table.classStudent(DB):person=columns.ForeignKey(Person)school=columns.ForeignKey(School)gpa=columns.TinyInt(default=20)person1=Person(name='Mohammad',family='Dori',age=20,phone=1234567890,salary=110_000,)school1=School(name='The Sample School',created_at='2002-01-04',address='1600 Amphitheatre Parkway in Mountain View, California',)print(school1)student=Student(person=person1,school=school1,gpa=10,)print(school1.id)print(person1.id)print(student)See All Query Usageprint(Person.queries())LinksDownload Source Code:Click HereMy Github Account:Click Here