Flask Sqlalchemy Save

Adds SQLAlchemy support to Flask

Project README

Flask-SQLAlchemy

Flask-SQLAlchemy is an extension for Flask_ that adds support for SQLAlchemy_ to your application. It aims to simplify using SQLAlchemy with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.

.. _Flask: https://palletsprojects.com/p/flask/ .. _SQLAlchemy: https://www.sqlalchemy.org

Installing

Install and update using pip_:

.. code-block:: text

$ pip install -U Flask-SQLAlchemy

.. _pip: https://pip.pypa.io/en/stable/getting-started/

A Simple Example

.. code-block:: python

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.sqlite"

class Base(DeclarativeBase):
  pass

db = SQLAlchemy(app, model_class=Base)

class User(db.Model):
    id: Mapped[int] = mapped_column(db.Integer, primary_key=True)
    username: Mapped[str] = mapped_column(db.String, unique=True, nullable=False)

with app.app_context():
    db.create_all()

    db.session.add(User(username="example"))
    db.session.commit()

    users = db.session.execute(db.select(User)).scalars()

Contributing

For guidance on setting up a development environment and how to make a contribution to Flask-SQLAlchemy, see the contributing guidelines_.

.. _contributing guidelines: https://github.com/pallets-eco/flask-sqlalchemy/blob/main/CONTRIBUTING.rst

The Pallets organization develops and supports Flask-SQLAlchemy and other popular packages. In order to grow the community of contributors and users, and allow the maintainers to devote more time to the projects, please donate today_.

.. _please donate today: https://palletsprojects.com/donate

Open Source Agenda is not affiliated with "Flask Sqlalchemy" Project. README Source: pallets-eco/flask-sqlalchemy
Stars
4,136
Open Issues
18
Last Commit
4 weeks ago
License

Open Source Agenda Badge

Open Source Agenda Rating