A small Python ORM built on top of SQLite from scratch: metaclasses, field descriptors, and a query builder.
- Define models as plain classes (
class Student(Model): ...) IntegerField,TextFieldwithprimary_key/nullablesupport- Auto table creation based on model structure (
Model.create_table()) - CRUD operations:
save(),delete() - Filtered queries:
Model.select().where(...).execute()
- Python 3
- sqlite3 (standard library)
python main.pyDemonstrates table creation, inserting records, filtered selects, updating, and deleting — all on an in-memory database (:memory:).
class Student(Model):
id = IntegerField(primary_key=True)
name = TextField(nullable=False)
age = IntegerField()
faculty = TextField()
Database.connect(":memory:")
Student.create_table()
student = Student(name="John Doe", age=20, faculty="CS")
student.save()
cs_students = Student.select().where(faculty="CS").execute()MIT