-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
44 lines (30 loc) · 1.21 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pymysql
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('mysql+mysqlconnector://root:password@localhost/chengyu',
encoding='utf-8', echo=False, pool_size=100, pool_recycle=10)
Base = declarative_base()
# 定义User对象:
class Chengyu(Base):
# 表的名字:
__tablename__ = 'chengyu'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(255))
py = Column(String(1024)) # 全拼音
jumplink = Column(String(255))
spy = Column(String(32)) # 首字拼音
add_time = Column(DateTime, default=func.now())
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.name)
if __name__ == '__main__':
# 创建DBSession类型:
Base.metadata.create_all(engine) # 创建表
# connection = pymysql.connect(host='localhost',
# port=3306,
# user='root',
# passwd='password',
# db='chengyu',
# charset='utf8mb4',
# cursorclass=pymysql.cursors.DictCursor)
#
# cursor = connection.cursor()