From 433ecf39eea6965f029e6a9ee942827ca3eaf001 Mon Sep 17 00:00:00 2001 From: snowy Date: Sat, 2 Mar 2024 02:44:11 +0800 Subject: [PATCH] update: Liteyuki ORM --- db_test2.py | 63 ----------------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 db_test2.py diff --git a/db_test2.py b/db_test2.py deleted file mode 100644 index 84b4d4ab..00000000 --- a/db_test2.py +++ /dev/null @@ -1,63 +0,0 @@ -import json -import random - -from src.api.data import LiteModel, SqliteORMAdapter - - -class Score(LiteModel): - subject: str - score: int - - -class Student(LiteModel): - name: str - age: str - sex: str - scores: list[Score] = [] - - -class Teacher(LiteModel): - name: str - age: str - - -class Class(LiteModel): - name: str - students: list[Student] - test_json: dict[str, Student] = {'张三': Student} - - -class University(LiteModel): - name: str - address: str - rank: int = 0 - classes: list[Class] = [] - students: list[Student] = [] - - -cqupt = University(name='重庆邮电大学', address='重庆', rank=100) -pku = University(name='北京大学', address='北京', rank=1) -cqu = University(name='重庆大学', address='重庆', rank=10) - -student_name_list = ['张三', '李四', '王五', '赵六', '钱七', '孙八', '周九', '吴十'] -student_list = [Student(name=name, age=19, sex=random.choice(['男', '女'])) for name in student_name_list] -# 构建复杂模型进行数据库测试 -cqupt.students = student_list -cqupt.classes = [Class(name='软件工程', students=student_list, test_json={name: student for name, student in zip(student_name_list, student_list)})] -for student in student_list: - student.scores = [Score(subject='语文', score=random.randint(60, 100)), Score(subject='数学', score=random.randint(60, 100)), - Score(subject='英语', score=random.randint(60, 100))] - student.scores.append(Score(subject='物理', score=random.randint(60, 100))) - student.scores.append(Score(subject='化学', score=random.randint(60, 100))) - student.scores.append(Score(subject='生物', score=random.randint(60, 100))) - student.scores.append(Score(subject='历史', score=random.randint(60, 100))) - student.scores.append(Score(subject='地理', score=random.randint(60, 100))) - student.scores.append(Score(subject='政治', score=random.randint(60, 100)) - ) -print(json.dumps(cqupt.dict(), indent=4, ensure_ascii=False)) -db = SqliteORMAdapter('test2.db') -db.auto_migrate(University, Class, Student, Score) -db.save(cqupt) - -# 查询测试 -db.first(University, 'name = ?', '重庆邮电大学') \ No newline at end of file