Add database structure
This commit is contained in:
parent
28e4ae478e
commit
925164e21d
2 changed files with 35 additions and 0 deletions
17
db/connector.py
Normal file
17
db/connector.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
|
||||||
|
user = os.environ['DB_USER']
|
||||||
|
password = os.environ['DB_PASSWORD']
|
||||||
|
host = os.environ['DB_HOST']
|
||||||
|
port = os.environ['DB_PORT']
|
||||||
|
database = os.environ['DB_DATABASE']
|
||||||
|
|
||||||
|
|
||||||
|
def get_connection():
|
||||||
|
return create_engine(
|
||||||
|
url="mysql+pymysql://{0}:{1}@{2}:{3}/{4}".format(
|
||||||
|
user, password, host, port, database
|
||||||
|
)
|
||||||
|
)
|
18
db/model/image_table.py
Normal file
18
db/model/image_table.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import sqlalchemy as db
|
||||||
|
|
||||||
|
from db import connector
|
||||||
|
|
||||||
|
engine = connector.create_engine
|
||||||
|
|
||||||
|
metadata_obj = db.MetaData()
|
||||||
|
|
||||||
|
profile = db.Table(
|
||||||
|
'images',
|
||||||
|
metadata_obj,
|
||||||
|
db.Column('id', db.Integer, primary_key=True),
|
||||||
|
db.Column('location', db.String),
|
||||||
|
db.Column('copyright', db.String),
|
||||||
|
db.Column('date_added', db.TIMESTAMP),
|
||||||
|
)
|
||||||
|
|
||||||
|
metadata_obj.create_all(engine)
|
Loading…
Reference in a new issue