-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
35 lines (25 loc) · 837 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
32
33
34
35
"""
NQueens Model
@author: Andrés Hernández
"""
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
DATABASE_URI = 'postgres+psycopg2://user:pass@db:5432/solutions'
Base = declarative_base()
engine = create_engine(DATABASE_URI, echo=True)
def create_session():
Session = sessionmaker(bind=engine)
return Session()
def create_db():
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
def delete_db():
Base.metadata.drop_all(engine)
class Solution(Base):
__tablename__ = 'solutions'
id = Column(Integer, primary_key=True)
nqueen = Column(Integer)
solution = Column(String)
def __str__(self):
return "<ID: {}, NQueen: {}, Solution: {}>".format(self.id,self.nqueen,self.solution)