Example #1
0
# -*- coding: utf-8 -*-
from flask import Flask
import sqlalchemy as sa
from alchemist.db import models

# Export named attributes.
__all__ = ["application"]

# Create a new flask application context.
application = Flask(__name__)

# Configure the application.
application.config["DATABASES"] = {"default": "sqlite:///:memory:"}


class Wall(models.Model):

    id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)


class Block(models.Model):

    id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
Example #2
0
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
# Configurações das conexões
app.config["DATABASES"] = {
    "testes": "sqlite:///test.db",
    "producao": "sqlite:///prod.db",
    "desenvolvimento": "sqlite:///dev.db",
}
# Configuração da conexão padrão
app.config["SQLALCHEMY_DATABASE_URI"] = app.config["DATABASES"]["testes"]
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

# Visualizar no terminal as execuções das querys
app.config["SQLALCHEMY_ECHO"] = True

db = SQLAlchemy(app)

# Cria uma nova conexão
# http://flask-sqlalchemy.pocoo.org/2.1/api/#flask.ext.sqlalchemy.SQLAlchemy.make_connector
def conectar_db(nome_db):
    app.config["SQLALCHEMY_DATABASE_URI"] = app.config["DATABASES"][nome_db]
    db.make_connector(app)


#
# Model
#
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)