Skip to main content

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 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_sqlorm-0.1.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_sqlorm-0.1.2-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file flask_sqlorm-0.1.2.tar.gz.

File metadata

  • Download URL: flask_sqlorm-0.1.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-40-generic

File hashes

Hashes for flask_sqlorm-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0ad33c73837db649f7c5770b36ce867226701899ea0ca48cde1c8cf62a761e45
MD5 337315e3b061cebb19f9fb2c52a53467
BLAKE2b-256 46392200c02ec16a156b5a2d668c85f02ca8bfdc2f0559074f19a207f1aa8ad7

See more details on using hashes here.

File details

Details for the file flask_sqlorm-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: flask_sqlorm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-40-generic

File hashes

Hashes for flask_sqlorm-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 70599a2af503cf31798c79d177abf57d899aec54876e1012e1b77c0dc9f24707
MD5 ffb6673cce2b85c518ac369817eecd22
BLAKE2b-256 3311c3928ee9abeef09151bd9f0dcf3b8f1ea24a7f743f5e4a02a755096424a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page