2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -24,7 +24,7 @@
In [1]:
```
```py
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Date, Float, Integer, String
@@ -48,7 +48,7 @@ class Order(Base):
In [2]:
```
```py
import datetime
order = Order(order_id='A0004', date=datetime.date.today(), symbol='MSFT', quantity=-1000, price=187.54)
@@ -58,14 +58,14 @@ order = Order(order_id='A0004', date=datetime.date.today(), symbol='MSFT', quant
In [3]:
```
```py
order.get_cost()
```
Out[3]:
```
```py
-187540.0
```
@@ -73,7 +73,7 @@ Out[3]:
In [4]:
```
```py
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
@@ -87,7 +87,7 @@ session = Session()
In [5]:
```
```py
session.add(order)
session.commit()
@@ -97,13 +97,13 @@ session.commit()
In [6]:
```
```py
for row in engine.execute("SELECT * FROM orders"):
print row
```
```
```py
(u'A0001', u'2013-12-01', u'AAPL', 1000, 203.4)
(u'A0002', u'2013-12-01', u'MSFT', 1500, 167.5)
(u'A0003', u'2013-12-02', u'GOOG', 1500, 167.5)
@@ -115,13 +115,13 @@ for row in engine.execute("SELECT * FROM orders"):
In [7]:
```
```py
for order in session.query(Order).filter(Order.symbol=="AAPL"):
print order.order_id, order.date, order.get_cost()
```
```
```py
A0001 2013-12-01 203400.0
```
@@ -130,20 +130,20 @@ A0001 2013-12-01 203400.0
In [8]:
```
```py
order_2 = session.query(Order).filter(Order.order_id=='A0002').first()
```
In [9]:
```
```py
order_2.symbol
```
Out[9]:
```
```py
u'MSFT'
```