-
Notifications
You must be signed in to change notification settings - Fork 80
/
model.py
54 lines (42 loc) · 1.78 KB
/
model.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from sqlalchemy import Column, Integer, String, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///report.db')
Base = declarative_base()
def get_session():
return sessionmaker(bind=engine)()
class Buy(Base):
__tablename__ = 'buy'
id = Column(Integer, primary_key=True)
dt = Column(String(), nullable=False)
code = Column(String(), nullable=False)
name = Column(String(), nullable=False)
price = Column(Integer(), nullable=False)
amount = Column(Integer(), nullable=False)
features = Column(String(), nullable=True)
def __repr__(self):
return "[Buy][{dt}] {name}({code}): {price} {amount}".format(
dt=self.dt, name=self.name, code=self.code, price=self.price, amount=self.amount
)
class Sell(Base):
__tablename__ = 'sell'
id = Column(Integer, primary_key=True)
dt = Column(String(), nullable=False)
code = Column(String(), nullable=False)
name = Column(String(), nullable=False)
price = Column(Integer(), nullable=False)
amount = Column(Integer(), nullable=False)
decision = Column(String(), nullable=False)
features = Column(String(), nullable=True)
def __repr__(self):
return "[Sell][{dt}] {name}({code}): {price} {amount} {decision}".format(
dt=self.dt, name=self.name, code=self.code, price=self.price, amount=self.amount,
decision=self.decision
)
if __name__ == '__main__':
Base.metadata.create_all(engine)
session = get_session()
session.add(Buy(dt='20170803093010', code='000000', name='A', price=1000, amount=10))
session.commit()
print(session.query(Buy).first())