From 95d15f7a9ddf3c938bf0d9255cf157535555aa6f Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 13 Jul 2021 15:32:45 +0000 Subject: [PATCH 1/2] Change sql query to check 'IF' table ' NOT EXISTS' --- src/sqlite/external_servers_preferences.sql | 2 +- src/sqlite/external_servers_privacy_preferences.sql | 2 +- src/sqlite/notification_preferences.sql | 2 +- src/sqlite/privacy_preferences.sql | 2 +- src/sqlite/security_preferences.sql | 2 +- src/sqlite/users.sql | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sqlite/external_servers_preferences.sql b/src/sqlite/external_servers_preferences.sql index 00b72e4..cdc1c5e 100644 --- a/src/sqlite/external_servers_preferences.sql +++ b/src/sqlite/external_servers_preferences.sql @@ -1,6 +1,6 @@ -- external_servers_preferences definition -CREATE TABLE external_servers_preferences ( +CREATE TABLE IF NOT EXISTS external_servers_preferences ( id BLOB NOT NULL PRIMARY KEY, external_servers BLOB NOT NULL, external_servers_limit TEXT NOT NULL, diff --git a/src/sqlite/external_servers_privacy_preferences.sql b/src/sqlite/external_servers_privacy_preferences.sql index 43c530c..d3565c5 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 BLOB NOT NULL PRIMARY KEY, discovery BLOB NOT NULL, discovery_user_limit TEXT NOT NULL, diff --git a/src/sqlite/notification_preferences.sql b/src/sqlite/notification_preferences.sql index 953f50c..89f0679 100644 --- a/src/sqlite/notification_preferences.sql +++ b/src/sqlite/notification_preferences.sql @@ -1,6 +1,6 @@ -- notification_preferences definition -CREATE TABLE notification_preferences ( +CREATE TABLE IF NOT EXISTS notification_preferences ( id BLOB 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)), diff --git a/src/sqlite/privacy_preferences.sql b/src/sqlite/privacy_preferences.sql index 445bf03..6444d6f 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 BLOB NOT NULL PRIMARY KEY, discovery BLOB NOT NULL, discovery_user_limit TEXT NOT NULL, diff --git a/src/sqlite/security_preferences.sql b/src/sqlite/security_preferences.sql index 50ce979..5fcd6d4 100644 --- a/src/sqlite/security_preferences.sql +++ b/src/sqlite/security_preferences.sql @@ -1,6 +1,6 @@ -- security_preferences definition -CREATE TABLE "security_preferences" ( +CREATE TABLE IF NOT EXISTS "security_preferences" ( id BLOB NOT NULL PRIMARY KEY, account_tokens TEXT NOT NULL, password_hash TEXT NOT NULL, diff --git a/src/sqlite/users.sql b/src/sqlite/users.sql index 66500e7..f8cb143 100644 --- a/src/sqlite/users.sql +++ b/src/sqlite/users.sql @@ -1,6 +1,6 @@ -- users definition -CREATE TABLE users ( +CREATE TABLE IF NOT EXISTS users ( id BLOB NOT NULL PRIMARY KEY, user_name TEXT NOT NULL, display_name TEXT, From 018b5af67cc62471d405a31ed0a95b65b91d6e3f Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 16 Jul 2021 06:54:12 +0000 Subject: [PATCH 2/2] add redout capabilities --- src/sqlite/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sqlite/mod.rs b/src/sqlite/mod.rs index 06e2738..9c9d493 100644 --- a/src/sqlite/mod.rs +++ b/src/sqlite/mod.rs @@ -26,4 +26,13 @@ pub async fn load_template(sqlite_handle: &mut SqliteConnection) -> sqlx::Result include_str!("external_servers_privacy_preferences.sql"), include_str!("external_servers_preferences.sql"), )).execute(sqlite_handle).await -} \ No newline at end of file +} + +pub async fn add_test_user(sqlite_handle: &mut SqliteConnection)-> 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) +} +