-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
28 lines (26 loc) · 1.13 KB
/
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
from sqlalchemy import *
from sqlalchemy.orm import (scoped_session, sessionmaker, relationship,
backref)
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('oracle://santosh:[email protected]:1521/xe', convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
# We will need this for querying
Base.query = db_session.query_property()
class CustomerModel(Base):
__tablename__ = 'demo_customers'
customer_id = Column(Integer,primary_key=True)
cust_first_name = Column(Unicode)
cust_last_name = Column(Unicode)
class OrderModel(Base):
__tablename__ = 'demo_orders'
order_id = Column('order_id',Integer,primary_key=True)
order_total = Column('order_total',Float)
customer_id = Column(Integer, ForeignKey('demo_customers.customer_id'))
customer = relationship(
CustomerModel,
backref = backref('demo_customers',
uselist = True,
cascade = 'delete,all'))