A very simple python object oriented orm layer
Each object has methods: .create() .update() and .fetch()
To add a new field to a class:
- add it to class, initialize with needed type like this
location = "" ##
x = 0 ##
- add ## after the field, this indicates that field is persistable
- first field that has ## will be primary key
- run python remake.py.
To add a new class:
- create name.py class file in objects/ folder
- add a field table that is the same as file name without extension
- add fields, initialize them and put ## after
- run python remake.py
Then you can create the object and set the new field an call .create() method and it will be persisted in the table with the newly added field like this:
u = User()
u.username = "bob"
u.password = "123ss"
u.email = "[email protected]"
u.ip = "123.123.123.123"
u.create()
To update an object you have to set its idfield and additional fields, then call .update() on it.
u = User()
u.username = "bob"
u.password = "ness"
u.email = "[email protected]"
u.update()
new values will be saved to object with username "bob"
To fetch an object you have to set its idfield and call .fetch()
u = User()
u.username = "bob"
u.fetch()
print u.email
user will be searched by username and full object will be returned