Flask integration for sqlorm
Project description
Flask-SQLORM
Flask integration for sqlorm
Setup
Install:
$ pip install flask-sqlorm
Setup:
from flask import Flask
from flask_sqlorm import FlaskSQLORM
app = Flask()
db = FlaskSQLORM(app, "sqlite://:memory:")
Usage
All exports from the sqlorm
package are available from the extension instance.
Define some models:
class Task(db.Model):
id: db.PrimaryKey[int]
title: str
done: bool = db.Column(default=False)
Start a transaction using the db object:
with db:
Task.create(title="first task")
In views, the current session is available using db.session
Configuration
Configure the sqlorm engine using the extension's constructor or init_app()
. Configuration of the engine is performed using the URI method.
Additional engine parameters can be provided as keyword arguments.
Configuration can also be provided via the app config under the SQLORM_
namespace. Use SQLORM_URI
to define the database URI.
Additional utilities provided by Flask-SQLORM
Model classes have the additional methods:
find_one_or_404
: same asfind_one
but throw a 404 when no results are returnedget_or_404
: same asget
but throw a 404 when no results are returned
Managing the schema
Some CLI commands are available under the db command group. Check out flask db --help
for a list of subcommands.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_sqlorm-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa09f69f0b44e914d488311179f43b4bc553e5e94f3d7f780553485f2b41e7b8 |
|
MD5 | 4e786a43ccc8895fa94df5179452cb2d |
|
BLAKE2b-256 | 45c4f2c7191e50fa09f94252c48726e8c0670ed51f292267de993a71059a3442 |