Skip to content

CruelSoftware/ORM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ORM

simple ORM to work with sqlite database (not for production usage for now)

Project contains 3 modules to work with, add to your project and use like in example.py app, you will need sqlite database.

  1. Module 'connection' contains Connection class
usage:
>> db_instance = Connection(path_to_database) # opens database instance
>> db_instance.execute(sql_query) # execute sql query
  1. Module tables contains two functions:
create_table() - returns sql query which should create table on execute
drop_table() - returns sql query which should drop table on execute
  1. Module models contains Model class and fields classes:

To add new model, create class inherited from Model as in example app. Available fields for now: CharField, Integer, Text, Bool.

class User(Model):
    id = fields.Integer(primary_key=True, auto_increment=True)
    firstname = fields.CharField(max_length=30)

Execute query with create_table:

>> db_instance.execute(create_table(User))

To drop:

>> db_instance.execute(drop_table(User))

Also you may select and save data as in example app.

Fields are situated right in class, not in constructor, so this modules need rework before use in production, something like model manager must be added, or maybe getattr setattr methods override (in this case all getters/setters in class should be reworked to set attributes with dict to avoid problems, values should be located in some kind of dictonary).

About

simple ORM to work with sqlite database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages