-
Notifications
You must be signed in to change notification settings - Fork 0
Models
Models (database objects, schemas, mapping) are sadly in flux. But the flux is towards using SQLAlchemy.
New modeling is powered by SQLAlchemy, which has lots of great documentation.
Currently object mapping is defined in giveaminute/models.py
.
In order to map to old models that are already defined in the database, the following sort of definition will create the object mapping:
class Project (Base):
__tablename__ = 'project'
__table_args__ = {'autoload': True}
See installation (Mac or Ubuntu) for details. But overall, run the following to get the schema installed:
python giveaminute/models.py
Something like the following (needs better information):
session = Controller.get_session()
query = session.query(ModelName)
Schemas are actual SQL table definitions found in sql/models.sql
. (There are some updates in sql/migrations/
)
To create a new models.sql
, use a command similar to:
mysqldump --no-data -u USER_NAME -p DB_NAME | sed 's/\(.*ENGINE.*AUTO_INCREMENT=\).*/\10;/g' > sql/models-temp.sql
Make sure to create migration files in sql/migrations/
and update CHANGLOG.txt
and UPGRADE.txt
.
Object modeling happens in multiple files in the giveaminute/
directory. There is a file for each major object.
Querying is done with web.py's database methods. For instance:
sql = 'select * from user where user_id = $userId'
data = db.query(sql, { 'userId': some_id })
The db
object is created in the base controller (framework/controller.py
) which is passed around, or retrieved with Controller.get_db()
.