Basic Usage
AutoDLA works with models, to start, you'll need to first build a usable model that inherits from Object:
from autodla import Object, primary_key
class User(Object):
id: primary_key = primary_key.auto_increment()
name: str
age: int
WARNING: For model definition there is 1 rule to ensure good data integrity:
- Each Model should have one and only one field of type
primary_key(idin this case)
If you try to use this, it will fail, as the main focus of the library is to interact with a DataBase, you need a DataBase connection, we'll use PostgreSQL for this example.
We need to instanciate the DataBase and then attach the Model into it.
from autodla.dbs import PostgresDB, MemoryDB
# MemoryDB is purely in-memory. PostgresDB keeps a local SQLite store and
# automatically syncs it to PostgreSQL.
db = MemoryDB() # or PostgresDB()
db.attach([User])
Done!
You now can use your object as you would normally and the changes are going to be reflected on the DataBase, enjoy!
Uses
Create a user
Retrieve all users
Integrity of python id for the percieved same object
This example is available in the repository