From 1907c3b9e2223005697fca88abc051c72d67531d Mon Sep 17 00:00:00 2001 From: dusoleil Date: Mon, 29 Aug 2022 06:32:29 -0400 Subject: store database in user space --- data_model/db_update.gd | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 data_model/db_update.gd (limited to 'data_model/db_update.gd') diff --git a/data_model/db_update.gd b/data_model/db_update.gd new file mode 100644 index 0000000..595f1bc --- /dev/null +++ b/data_model/db_update.gd @@ -0,0 +1,23 @@ +class_name db_update + +static func update(DBMS): + while true: + var version = get_version(DBMS) + match version: + [0,1,0]: break + _: exec_sql_file(DBMS, "res://data_model/schema.sql") + #insert_test_data(DBMS) + +static func get_version(DBMS): + var version = DBMS.query("select * from Version", []) + return [0,0,0] if version.size() == 0 else [version[0]['major'],version[0]['minor'],version[0]['patch']] + +static func exec_sql_file(DBMS, file): + var f = File.new() + f.open(file, File.READ) + var sql = f.get_as_text() + f.close() + DBMS.query(sql,[]) + +static func insert_test_data(DBMS): + exec_sql_file(DBMS, "res://data_model/test_data.sql") -- cgit v1.2.3