forked from william10240/py_fanhao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
57 lines (48 loc) · 1.84 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
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'SunCoder'
import time,os
from peewee import Model,PrimaryKeyField,CharField,CharField,IntegerField
from Base import getconfig, APP_PATH
# from peewee import MySQLDatabase
# db = SqliteDatabase(host=getconfig('db', 'host'),
# user=getconfig('db', 'user'),
# passwd=getconfig('db', 'passwd'),
# database=getconfig('db', 'database'),
# charset=getconfig('db', 'charset'),
# port=int(getconfig('db', 'port'))
# )
from peewee import SqliteDatabase
db = SqliteDatabase(os.path.join(APP_PATH, 'fan.db'))
class BaseModel(Model):
class Meta:
database = db
class fanhao(BaseModel):
id = PrimaryKeyField(primary_key=True)
code = CharField(64)
title = CharField(128)
star = CharField(64,null=True)
starcode = CharField(64,null=True)
img = CharField(128,null=True)
fname = CharField(128,null=True)
ima = IntegerField(default=0)
iface = IntegerField(default=0)
starnum = IntegerField(default=0)
updateTime = IntegerField(default=int(time.time()))
downed = IntegerField(default=0)
if __name__ == '__main__':
# print(dir(fanhao._meta))
# print('fanhao的类型是:',type(fanhao._meta.database))
# print('是MySQLDatabase吗:',isinstance(fanhao._meta.database,MySQLDatabase))
# print('是SqliteDatabase吗:',isinstance(fanhao._meta.database,SqliteDatabase))
# print('数据表是否存在:',fanhao.table_exists())
# if not fanhao.table_exists():
# print('开始创建数据表')
# fanhao.create_table()
# print('再次检测数据表是否存在:',fanhao.table_exists())
print(fanhao.table_exists())
# ps = fanhao.select()
# for p in ps:
# print(p)
# print(ps.count())
#fanhao.create_table()