mirror of
https://github.com/Relintai/pandemonium_demo_projects.git
synced 2024-12-21 13:56:50 +01:00
New simple database demo project.
This commit is contained in:
parent
1d8a77ea51
commit
124ab95723
88
database/database_simple/Main.gd
Normal file
88
database/database_simple/Main.gd
Normal file
@ -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)))
|
6
database/database_simple/Main.tscn
Normal file
6
database/database_simple/Main.tscn
Normal file
@ -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 )
|
7
database/database_simple/default_env.tres
Normal file
7
database/database_simple/default_env.tres
Normal file
@ -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 )
|
BIN
database/database_simple/icon.png
Normal file
BIN
database/database_simple/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
35
database/database_simple/icon.png.import
Normal file
35
database/database_simple/icon.png.import
Normal file
@ -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
|
25
database/database_simple/project.pandemonium
Normal file
25
database/database_simple/project.pandemonium
Normal file
@ -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"
|
@ -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://WebServerSimple.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://WebRoot.gd" type="Script" id=2]
|
[ext_resource path="res://WebRoot.gd" type="Script" id=2]
|
||||||
|
@ -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]
|
[sub_resource type="ProceduralSky" id=1]
|
||||||
|
|
||||||
|
@ -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]
|
[ext_resource path="res://templates/LoginPageTD.phtpl" type="HTMLTemplateData" id=1]
|
||||||
|
|
||||||
|
@ -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]
|
[ext_resource path="res://templates/RegisterDefaultPageTD.phtpl" type="HTMLTemplateData" id=1]
|
||||||
|
|
||||||
|
@ -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]
|
[ext_resource path="res://templates/RegisterSuccessPageTD.phtpl" type="HTMLTemplateData" id=1]
|
||||||
|
|
||||||
|
@ -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]
|
[ext_resource path="res://templates/Root.phtpl" type="HTMLTemplateData" id=1]
|
||||||
|
|
||||||
|
@ -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]
|
[ext_resource path="res://templates/SettingsPageTP.phtpl" type="HTMLTemplateData" id=1]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user