diff --git a/src/sqlite/external_servers_preferences.sql b/src/sqlite/external_servers_preferences.sql index 2daae2e..005c38c 100644 --- a/src/sqlite/external_servers_preferences.sql +++ b/src/sqlite/external_servers_preferences.sql @@ -1,8 +1,8 @@ -- external_servers_preferences definition -CREATE TABLE external_servers_preferences ( +CREATE TABLE IF NOT EXISTS external_servers_preferences ( id TEXT NOT NULL PRIMARY KEY, external_servers BLOB NOT NULL, external_servers_limit TEXT NOT NULL, CONSTRAINT external_servers_preferences_FK FOREIGN KEY (id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE -); \ No newline at end of file +); diff --git a/src/sqlite/external_servers_privacy_preferences.sql b/src/sqlite/external_servers_privacy_preferences.sql index f0711f5..5e7cffe 100644 --- a/src/sqlite/external_servers_privacy_preferences.sql +++ b/src/sqlite/external_servers_privacy_preferences.sql @@ -1,6 +1,6 @@ -- external_servers_privacy_preferences definition -CREATE TABLE external_servers_privacy_preferences ( +CREATE TABLE IF NOT EXISTS external_servers_privacy_preferences ( id TEXT NOT NULL PRIMARY KEY, discovery BLOB NOT NULL, discovery_user_limit TEXT NOT NULL, @@ -13,4 +13,4 @@ CREATE TABLE external_servers_privacy_preferences ( info_user_limit TEXT NOT NULL, info_server_limit TEXT NOT NULL, CONSTRAINT external_servers_privacy_preferences_FK FOREIGN KEY (id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE -); \ No newline at end of file +); diff --git a/src/sqlite/mod.rs b/src/sqlite/mod.rs index edbbc00..694bc6d 100644 --- a/src/sqlite/mod.rs +++ b/src/sqlite/mod.rs @@ -25,4 +25,13 @@ pub async fn load_template(sqlite_handle: &SqlitePool) -> sqlx::Result sqlx::Result{ + sqlx::query("insert into users values('1923123','Elierik','erikeli',1,2,3);").execute(sqlite_handle).await +} + +pub async fn sqlite_out(sqlite_handle: &mut SqliteConnection, query:&str, index:usize) -> Result { + sqlx::query(query).fetch_one(sqlite_handle).await.unwrap().try_get(index) +} + diff --git a/src/sqlite/notification_preferences.sql b/src/sqlite/notification_preferences.sql index 6056365..41c4c8b 100644 --- a/src/sqlite/notification_preferences.sql +++ b/src/sqlite/notification_preferences.sql @@ -1,8 +1,8 @@ -- notification_preferences definition -CREATE TABLE notification_preferences ( +CREATE TABLE IF NOT EXISTS notification_preferences ( id TEXT NOT NULL PRIMARY KEY, lock_details BOOLEAN DEFAULT 0 NOT NULL CHECK (lock_details IN (0, 1)), do_not_disturb BOOLEAN DEFAULT 0 NOT NULL CHECK (do_not_disturb IN (0, 1)), CONSTRAINT notification_preferences_FK FOREIGN KEY (id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE -); \ No newline at end of file +); diff --git a/src/sqlite/privacy_preferences.sql b/src/sqlite/privacy_preferences.sql index b2ccdf5..20a0b35 100644 --- a/src/sqlite/privacy_preferences.sql +++ b/src/sqlite/privacy_preferences.sql @@ -1,6 +1,6 @@ -- privacy_preferences definition -CREATE TABLE privacy_preferences ( +CREATE TABLE IF NOT EXISTS privacy_preferences ( id TEXT NOT NULL PRIMARY KEY, discovery BLOB NOT NULL, discovery_user_limit TEXT NOT NULL, @@ -13,4 +13,4 @@ CREATE TABLE privacy_preferences ( info_user_limit TEXT NOT NULL, info_server_limit TEXT NOT NULL, CONSTRAINT privacy_preferences_FK FOREIGN KEY (id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE -); \ No newline at end of file +); diff --git a/src/sqlite/security_preferences.sql b/src/sqlite/security_preferences.sql index fd081a8..2523a8b 100644 --- a/src/sqlite/security_preferences.sql +++ b/src/sqlite/security_preferences.sql @@ -1,8 +1,8 @@ -- security_preferences definition -CREATE TABLE "security_preferences" ( +CREATE TABLE IF NOT EXISTS "security_preferences" ( id TEXT NOT NULL PRIMARY KEY, account_tokens TEXT NOT NULL, password_hash TEXT NOT NULL, CONSTRAINT NewTable_FK FOREIGN KEY (id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE -); \ No newline at end of file +); diff --git a/src/sqlite/users.sql b/src/sqlite/users.sql index 468c0ac..9b4e4f3 100644 --- a/src/sqlite/users.sql +++ b/src/sqlite/users.sql @@ -1,10 +1,10 @@ -- users definition -CREATE TABLE users ( +CREATE TABLE IF NOT EXISTS users ( id TEXT NOT NULL PRIMARY KEY, user_name TEXT NOT NULL, display_name TEXT, activated BOOLEAN DEFAULT 0 NOT NULL CHECK (activated IN (0, 1)), created INTEGER NOT NULL, last_online INTEGER -); \ No newline at end of file +);