diff --git a/database/database_simple/Main.gd b/database/database_simple/Main.gd new file mode 100644 index 0000000..6f5c809 --- /dev/null +++ b/database/database_simple/Main.gd @@ -0,0 +1,88 @@ +extends Node + +export(String) var database_location : String = "user://database.sqlite" + +func _ready() -> void: + DatabaseManager.connect("initialized", self, "on_databases_initialized", [], CONNECT_ONESHOT) + + var d : Directory = Directory.new() + var bd : String = database_location.get_base_dir() + var loc : String = d.get_filesystem_abspath_for(bd).append_path(database_location.get_file()) + + PLogger.log_message("Database file location: " + loc) + PLogger.log_message("(Editor->Project->Open User Data Folder)") + + var file : File = File.new() + if !file.file_exists(loc): + PLogger.log_message("Database file doesn't exists, will run migrations!") + PLogger.log_message("(Editor->Project->Open User Data Folder)") + call_deferred("migrate") + else: + DatabaseManager.call_deferred("initialized") + + var db : SQLite3Database = SQLite3Database.new() + db.connection_string = loc + DatabaseManager.add_database(db) + +func migrate() -> void: + PLogger.log_message("Running migrations!") + DatabaseManager.connect("migration", self, "_migration") + DatabaseManager.migrate(true, false, 0) + + DatabaseManager.call_deferred("initialized") + +func on_databases_initialized() -> void: + # Load sessions after the databases are initialized + # This happens on the Main node. + call_deferred("load_data") + +func _migration(clear: bool, should_seed: bool, pseed: int) -> void: + randomize() + + var tb : TableBuilder = DatabaseManager.ddb.get_connection().get_table_builder() + + tb.create_table("data_table"); + tb.integer("id").auto_increment().next_row(); + tb.varchar("data_varchar", 60).not_null().next_row(); + tb.text("data_text").not_null().next_row(); + tb.integer("data_int").not_null().next_row(); + tb.real_double("data_double").not_null().next_row(); + tb.primary_key("id"); + tb.ccreate_table(); + tb.run_query(); + + print("Running:") + print(tb.result) + + var qb : QueryBuilder = DatabaseManager.ddb.get_connection().get_query_builder() + + for i in range(10): + qb.reset() + + qb.insert("data_table", "data_varchar,data_text,data_int,data_double").values() + qb.vals("vc" + str(randi())) + qb.vals("text" + str(randi())) + qb.vali(randi()) + qb.vald(randf() * 100000) + qb.cvalues() + qb.end_command() + + qb.run_query() + + print("Running:") + print(qb.result) + +func load_data() -> void: + print("Querying data from table:") + + var qb : QueryBuilder = DatabaseManager.ddb.get_connection().get_query_builder() + + var qr : QueryResult = qb.select("id,data_varchar,data_text,data_int,data_double").from("data_table").run() + + while qr.next_row(): + print("ROW:") + print("id: " + str(qr.get_cell_int(0))) + print("data_varchar: " + str(qr.get_cell(1))) + print("data_text: " + str(qr.get_cell(2))) + print("data_int: " + str(qr.get_cell_int(3))) + print("data_double: " + str(qr.get_cell_double(4))) diff --git a/database/database_simple/Main.tscn b/database/database_simple/Main.tscn new file mode 100644 index 0000000..85dfcb0 --- /dev/null +++ b/database/database_simple/Main.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3] + +[ext_resource path="res://Main.gd" type="Script" id=4] + +[node name="Main" type="Node"] +script = ExtResource( 4 ) diff --git a/database/database_simple/default_env.tres b/database/database_simple/default_env.tres new file mode 100644 index 0000000..8419635 --- /dev/null +++ b/database/database_simple/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment3D" load_steps=2 format=3] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/database/database_simple/icon.png b/database/database_simple/icon.png new file mode 100644 index 0000000..5eaa3d1 Binary files /dev/null and b/database/database_simple/icon.png differ diff --git a/database/database_simple/icon.png.import b/database/database_simple/icon.png.import new file mode 100644 index 0000000..a4c02e6 --- /dev/null +++ b/database/database_simple/icon.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/database/database_simple/project.pandemonium b/database/database_simple/project.pandemonium new file mode 100644 index 0000000..03d8d43 --- /dev/null +++ b/database/database_simple/project.pandemonium @@ -0,0 +1,25 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +[application] + +config/name="Database Simple" +run/main_scene="res://Main.tscn" +config/icon="res://icon.png" + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +vram_compression/import_etc=true +vram_compression/import_etc2=false +environment/default_environment="res://default_env.tres" diff --git a/web/users_sqlite_bootstrap_templated/Main.tscn b/web/users_sqlite_bootstrap_templated/Main.tscn index 501d38a..5ce7e8b 100644 --- a/web/users_sqlite_bootstrap_templated/Main.tscn +++ b/web/users_sqlite_bootstrap_templated/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=16 format=2] +[gd_scene load_steps=16 format=3] [ext_resource path="res://WebServerSimple.gd" type="Script" id=1] [ext_resource path="res://WebRoot.gd" type="Script" id=2] diff --git a/web/users_sqlite_bootstrap_templated/default_env.tres b/web/users_sqlite_bootstrap_templated/default_env.tres index 4f08e8f..8419635 100644 --- a/web/users_sqlite_bootstrap_templated/default_env.tres +++ b/web/users_sqlite_bootstrap_templated/default_env.tres @@ -1,4 +1,4 @@ -[gd_resource type="Environment3D" load_steps=2 format=2] +[gd_resource type="Environment3D" load_steps=2 format=3] [sub_resource type="ProceduralSky" id=1] diff --git a/web/users_sqlite_bootstrap_templated/templates/LoginPage.tres b/web/users_sqlite_bootstrap_templated/templates/LoginPage.tres index 766b4cf..c911b21 100644 --- a/web/users_sqlite_bootstrap_templated/templates/LoginPage.tres +++ b/web/users_sqlite_bootstrap_templated/templates/LoginPage.tres @@ -1,4 +1,4 @@ -[gd_resource type="HTMLTemplate" load_steps=3 format=2] +[gd_resource type="HTMLTemplate" load_steps=3 format=3] [ext_resource path="res://templates/LoginPageTD.phtpl" type="HTMLTemplateData" id=1] diff --git a/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPage.tres b/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPage.tres index 4165be5..c266ea8 100644 --- a/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPage.tres +++ b/web/users_sqlite_bootstrap_templated/templates/RegisterDefaultPage.tres @@ -1,4 +1,4 @@ -[gd_resource type="HTMLTemplate" load_steps=3 format=2] +[gd_resource type="HTMLTemplate" load_steps=3 format=3] [ext_resource path="res://templates/RegisterDefaultPageTD.phtpl" type="HTMLTemplateData" id=1] diff --git a/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPage.tres b/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPage.tres index 12e39d6..1b171d4 100644 --- a/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPage.tres +++ b/web/users_sqlite_bootstrap_templated/templates/RegisterSuccessPage.tres @@ -1,4 +1,4 @@ -[gd_resource type="HTMLTemplate" load_steps=3 format=2] +[gd_resource type="HTMLTemplate" load_steps=3 format=3] [ext_resource path="res://templates/RegisterSuccessPageTD.phtpl" type="HTMLTemplateData" id=1] diff --git a/web/users_sqlite_bootstrap_templated/templates/Root.tres b/web/users_sqlite_bootstrap_templated/templates/Root.tres index 51afb5f..79cd69d 100644 --- a/web/users_sqlite_bootstrap_templated/templates/Root.tres +++ b/web/users_sqlite_bootstrap_templated/templates/Root.tres @@ -1,4 +1,4 @@ -[gd_resource type="HTMLTemplate" load_steps=3 format=2] +[gd_resource type="HTMLTemplate" load_steps=3 format=3] [ext_resource path="res://templates/Root.phtpl" type="HTMLTemplateData" id=1] diff --git a/web/users_sqlite_bootstrap_templated/templates/SettingsPage.tres b/web/users_sqlite_bootstrap_templated/templates/SettingsPage.tres index 063b3de..edf3ea8 100644 --- a/web/users_sqlite_bootstrap_templated/templates/SettingsPage.tres +++ b/web/users_sqlite_bootstrap_templated/templates/SettingsPage.tres @@ -1,4 +1,4 @@ -[gd_resource type="HTMLTemplate" load_steps=3 format=2] +[gd_resource type="HTMLTemplate" load_steps=3 format=3] [ext_resource path="res://templates/SettingsPageTP.phtpl" type="HTMLTemplateData" id=1]