Skip to content

A tiny object mapping between Python objects and SQLite rows.

Notifications You must be signed in to change notification settings

revliscano/sqlite-mini-object-mapping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLite Mini Object Mapping

I made this little project inspired by the way Django connects models to a database. With this in mind, I wanted to make it possible that by declaring and using Python classes, I could save and retrieve objects of that class, from a database (SQLite, in this case).

With the following code there will be a new record on a table called (automatically) my_model.

from model import Model


class MyModel(Model):
    field_a = Field('text')
    field_b = Field('text')


instance = MyModel(field_a='foo', field_b='bar')
my_model_repository = ModelRepository(MyModel)

my_model_repository.add(instance)

To make this possible, I highlight the use of Python's descriptors and metaclasses, which were the aspects that I wanted to practice the most with the development of this project.

About

A tiny object mapping between Python objects and SQLite rows.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages