mirror of
https://github.com/ByteAtATime/raycast-linux.git
synced 2025-09-11 16:36:26 +00:00
feat(snippets): initialize snippet db
This commit creates the initial backend infrastructure for the snippets feature. It sets up the core data model, a dedicated `SnippetManager` for database interactions using `rusqlite`, and integrates it into the Tauri application state.
This commit is contained in:
parent
21cd217a26
commit
1a2fa36a79
4 changed files with 60 additions and 4 deletions
36
src-tauri/src/snippets/manager.rs
Normal file
36
src-tauri/src/snippets/manager.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use crate::error::AppError;
|
||||
use rusqlite::{Connection, Result as RusqliteResult};
|
||||
use std::sync::Mutex;
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
pub struct SnippetManager {
|
||||
db: Mutex<Connection>,
|
||||
}
|
||||
|
||||
impl SnippetManager {
|
||||
pub fn new(app_handle: AppHandle) -> Result<Self, AppError> {
|
||||
let data_dir = app_handle
|
||||
.path()
|
||||
.app_local_data_dir()
|
||||
.map_err(|_| AppError::DirectoryNotFound)?;
|
||||
let db_path = data_dir.join("snippets.sqlite");
|
||||
let db = Connection::open(db_path)?;
|
||||
Ok(Self { db: Mutex::new(db) })
|
||||
}
|
||||
|
||||
pub fn init_db(&self) -> RusqliteResult<()> {
|
||||
let db = self.db.lock().unwrap();
|
||||
db.execute(
|
||||
"CREATE TABLE IF NOT EXISTS snippets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
keyword TEXT NOT NULL UNIQUE,
|
||||
content TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
)",
|
||||
[],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1 +1,3 @@
|
|||
pub mod input_manager;
|
||||
pub mod input_manager;
|
||||
pub mod manager;
|
||||
pub mod types;
|
13
src-tauri/src/snippets/types.rs
Normal file
13
src-tauri/src/snippets/types.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Clone, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Snippet {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub keyword: String,
|
||||
pub content: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue