forked from realpython/flask-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
executable file
·31 lines (25 loc) · 955 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
# from sqlalchemy import Column, Integer, String
# from app import db
engine = create_engine('sqlite:///database.db', echo=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
# Set your classes here.
'''
class User(Base):
__tablename__ = 'Users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(120), unique=True)
email = db.Column(db.String(120), unique=True)
password = db.Column(db.String(30))
def __init__(self, name=None, password=None):
self.name = name
self.password = password
'''
# Create tables.
Base.metadata.create_all(bind=engine)