fix: remove surrealdb and clean up

This commit is contained in:
reya 2024-02-05 07:46:41 +07:00
parent 3ba870be4b
commit 7bd6f6a8db
7 changed files with 11 additions and 1650 deletions

1577
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,7 @@ rust-version = "1.70"
tauri-build = { version = "2.0.0-alpha", features = [] }
[dependencies]
nostr = "0.27"
nostr-sdk = "0.27"
nostr-sqlite = "0.27"
nostr-sdk = { version = "0.27", features = ["sqlite"] }
tokio = { version = "1", features = ["full"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
@ -39,7 +37,6 @@ tauri-plugin-upload = "2.0.0-alpha"
tauri-plugin-window-state = "2.0.0-alpha"
tauri-plugin-theme = { git = "https://github.com/wyhaya/tauri-plugin-theme" }
webpage = { version = "2.0", features = ["serde"] }
surrealdb = { version = "1.1.1", features = ["kv-rocksdb"] }
[target.'cfg(not(target_os = "linux"))'.dependencies]
keyring = "2"

View File

@ -1,4 +1,3 @@
pub mod db;
pub mod folder;
pub mod opg;
pub mod secret;

View File

@ -1,23 +0,0 @@
use crate::model::*;
use crate::AppState;
use tauri::State;
#[tauri::command(async)]
pub async fn create_account(
pubkey: String,
app_state: State<'_, AppState>,
) -> Result<Vec<Record>, ()> {
let db = app_state.db.lock().await;
let created: Vec<Record> = db
.create("account")
.content(Account {
id: None,
pubkey,
is_active: true,
})
.await
.expect("Create account failed");
Ok(created)
}

View File

@ -4,23 +4,15 @@
)]
pub mod commands;
pub mod model;
pub mod nostr;
use nostr_sdk::{Client, ClientBuilder};
use nostr_sqlite::SQLiteDatabase;
use nostr_sdk::prelude::*;
use std::sync::Arc;
use surrealdb::{
engine::local::{Db, RocksDb},
Surreal,
};
use tauri::Manager;
use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_theme::ThemePlugin;
use tokio::sync::Mutex;
pub struct AppState {
pub db: Mutex<Surreal<Db>>,
pub nostr: Arc<Client>,
}
@ -32,17 +24,6 @@ fn main() {
let config_dir = app.path().app_config_dir().unwrap();
tauri::async_runtime::spawn(async move {
// Create app db connection
let db = Surreal::new::<RocksDb>(config_dir.join("lume.db"))
.await
.expect("Initialize app db failed");
// Select namespace and db
db.use_ns("lume")
.use_db("app")
.await
.expect("Open app db failed");
// Create database connection
let nostr_db = SQLiteDatabase::open(config_dir.join("nostr.db"))
.await
@ -67,7 +48,6 @@ fn main() {
// Init global state
handle.manage(AppState {
db: Mutex::new(db),
nostr: client.into(),
})
});

View File

@ -1,28 +0,0 @@
use serde::{Deserialize, Serialize};
use surrealdb::sql::Thing;
#[derive(Debug, Serialize)]
pub struct Account {
pub id: Option<Thing>,
pub pubkey: String,
pub is_active: bool,
}
#[derive(Debug, Serialize)]
pub struct Column {
pub id: Option<Thing>,
pub title: String,
pub content: String,
pub kind: i32,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Record {
#[allow(dead_code)]
pub id: Thing,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AffectedRows {
pub rows_affected: u64,
}

View File

@ -1,8 +1,5 @@
use crate::AppState;
use nostr::nips::nip19::ToBech32;
use nostr::secp256k1::SecretKey;
use nostr::{FromBech32, Keys, Result};
use nostr_sdk::ClientSigner;
use nostr_sdk::prelude::*;
use tauri::State;
#[derive(serde::Serialize)]