Metadata-Version: 2.1
Name: flask-sqlorm
Version: 0.1.2
Summary: Flask integration for sqlorm
Home-page: https://github.com/hyperflask/flask-sqlorm
License: MIT
Author: Maxime Bouroumeau-Fuseau
Author-email: maxime.bouroumeau@gmail.com
Requires-Python: >=3.10,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: flask (>=3.0.0,<4.0.0)
Requires-Dist: sqlorm-py (>=0.2.2,<0.3.0)
Project-URL: Repository, https://github.com/hyperflask/flask-sqlorm
Description-Content-Type: text/markdown

# Flask-SQLORM

Flask integration for [sqlorm](https://github.com/hyperflask/sqlorm)

## Setup

Install:

    $ pip install flask-sqlorm

Setup:

```python
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:

```python
class Task(db.Model):
    id: db.PrimaryKey[int]
    title: str
    done: bool = db.Column(default=False)
```

Start a transaction using the db object:

```python
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 as `find_one` but throw a 404 when no results are returned
 - `get_or_404`: same as `get` 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.
