-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoubandb.py
More file actions
29 lines (21 loc) · 693 Bytes
/
Copy pathdoubandb.py
File metadata and controls
29 lines (21 loc) · 693 Bytes
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
# -*- coding:utf-8 -*-
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer, String, Text
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
engine = create_engine(
'mysql+pymysql://root:root@127.0.0.1:3306/test',
echo=True
)
class Book(Base):
__tablename__ = 'book'
id = Column(Integer(), primary_key=True, autoincrement=True)
name = Column(String(64))
info = Column(String(64))
intro = Column(Text())
rating_num = Column(String(16))
rating_people = Column(String(16))
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
sess = Session()