This commit is contained in:
27942
2025-10-13 10:20:23 +08:00
parent 567500f91a
commit 48028edf56
5 changed files with 216 additions and 96 deletions

4
models/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from peewee import *
# 连接到 SQLite 数据库,如果文件不存在会自动创建
db = SqliteDatabase('database.db')

33
models/weex.py Normal file
View 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]
)