DDL单独抽取出来

This commit is contained in:
ZaneYork 2024-09-12 10:37:29 +08:00
parent 818008fc74
commit 1b61b35c03
2 changed files with 45 additions and 33 deletions

45
db/ddl.sql Normal file
View File

@ -0,0 +1,45 @@
create table main.menu
(
name text
constraint menu_pk
primary key,
label text,
order_num integer,
expression text
);
create table main.roll_result
(
datestr text
constraint roll_result_pk
primary key,
value text
);
create table main.sqlite_master
(
type TEXT,
name TEXT,
tbl_name TEXT,
rootpage INT,
sql TEXT
);
create table main.user_menu
(
user text,
menu text,
datestr text,
nickname text,
primary key (user, datestr),
constraint user_menu_pk
unique (nickname, datestr)
);
create table main.users
(
nickname text
constraint users_pk
primary key
);

View File

@ -6,39 +6,6 @@ from utils import get_user
db_path = './data.sqlite3'
ddl_db = sqlite3.connect(db_path)
ddl_cursor = ddl_db.cursor()
try:
ddl_cursor.execute('''
create table if not exists user_menu
(
user text,
menu text,
datestr text,
primary key (user, datestr)
)
''')
ddl_cursor.execute('''
create table if not exists roll_result
(
datestr text primary key,
value text
)
''')
ddl_cursor.execute('''
create table if not exists menu
(
name text primary key,
label text,
order_num integer,
expression text
)
''')
ddl_db.commit()
finally:
ddl_cursor.close()
ddl_db.close()
def get_user_menu() -> tuple[str, str]:
"""