Uiro depends on SQLAlchemy, a powerful ORM for python. It only provides these features:
It’s same with SQLAlchemy. Just using Base/Session provided by Uiro to creating tables automatically.
import sqlalchemy as sa
from uiro.db import Base, Session
class MyModel(Base):
__tablename__ = 'mymodel'
query = Session.query_property()
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String(255))
def __init__(self, name):
self.name = name
And using like this:
>>> import transaction
>>> with transaction.manager:
... Session.add(MyModel(name='spam'))
You can see SQLAlchemy and zope.sqlalchemy documentation to learn more.
You can initialize DB with following gearbox command:
gearbox initdb
This command is to create tables to specified database.
To change database to use, specify that URL to sqlalchemy.url setting in .ini file:
sqlalchemy.url = sqlite:///default.db