Justin-Kuehn / flask-sqlalchemy

Adds SQLAlchemy support to Flask

Home Page:https://flask-sqlalchemy.palletsprojects.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Installing

Install and update using pip:

$ pip install -U Flask-SQLAlchemy

A Simple Example

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

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


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True, nullable=False)
    email = db.Column(db.String, unique=True, nullable=False)


db.session.add(User(username="Flask", email="example@example.com"))
db.session.commit()

users = User.query.all()

Links

About

Adds SQLAlchemy support to Flask

https://flask-sqlalchemy.palletsprojects.com/

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 100.0%