dededdew
This commit is contained in:
4
models/__init__.py
Normal file
4
models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from peewee import *
|
||||
|
||||
# 连接到 SQLite 数据库,如果文件不存在会自动创建
|
||||
db = SqliteDatabase('database.db')
|
||||
33
models/weex.py
Normal file
33
models/weex.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from peewee import *
|
||||
|
||||
from models import db
|
||||
|
||||
|
||||
class Weex(Model):
|
||||
id = IntegerField(primary_key=True)
|
||||
open = FloatField(null=True)
|
||||
high = FloatField(null=True)
|
||||
low = FloatField(null=True)
|
||||
close = FloatField(null=True)
|
||||
|
||||
class Meta:
|
||||
database = db
|
||||
table_name = 'weex'
|
||||
|
||||
# 连接到数据库
|
||||
db.connect()
|
||||
|
||||
# 创建表(如果表不存在)
|
||||
db.create_tables([Weex])
|
||||
|
||||
# 示例数据
|
||||
data = ['100', '101', '99', '100.5', 1]
|
||||
|
||||
# 使用 get_or_create 方法插入数据
|
||||
Weex.get_or_create(
|
||||
id=data[1],
|
||||
open=data[0],
|
||||
high=data[1],
|
||||
low=data[2],
|
||||
close=data[3]
|
||||
)
|
||||
Reference in New Issue
Block a user