Skip to main content

tauri_plugin_libsql/
models.rs

1use serde::{Deserialize, Serialize};
2
3/// Cipher types for encryption
4#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
5#[serde(rename_all = "kebab-case")]
6pub enum Cipher {
7    #[serde(rename = "aes256cbc", alias = "aes256-cbc")]
8    Aes256Cbc,
9}
10
11#[cfg(feature = "encryption")]
12impl From<Cipher> for libsql::Cipher {
13    fn from(cipher: Cipher) -> Self {
14        match cipher {
15            Cipher::Aes256Cbc => libsql::Cipher::Aes256Cbc,
16        }
17    }
18}
19
20/// Encryption configuration for database
21#[derive(Debug, Clone, Deserialize, Serialize)]
22#[serde(rename_all = "camelCase")]
23pub struct EncryptionConfig {
24    pub cipher: Cipher,
25    pub key: Vec<u8>,
26}
27
28#[cfg(feature = "encryption")]
29impl From<EncryptionConfig> for libsql::EncryptionConfig {
30    fn from(config: EncryptionConfig) -> Self {
31        libsql::EncryptionConfig::new(config.cipher.into(), bytes::Bytes::from(config.key))
32    }
33}
34
35/// Options for loading a database
36#[derive(Debug, Deserialize, Serialize)]
37#[serde(rename_all = "camelCase")]
38pub struct LoadOptions {
39    /// Database path. For local files: "sqlite:myapp.db". For pure remote: "libsql://…"
40    pub path: String,
41    /// Optional encryption configuration (local databases only)
42    pub encryption: Option<EncryptionConfig>,
43    /// Remote database URL for embedded replica mode (e.g. "libsql://mydb.turso.io")
44    pub sync_url: Option<String>,
45    /// Auth token for remote/Turso connections
46    pub auth_token: Option<String>,
47}
48
49/// Result of an execute operation
50#[derive(Debug, Clone, Deserialize, Serialize)]
51#[serde(rename_all = "camelCase")]
52pub struct QueryResult {
53    /// Number of rows affected
54    pub rows_affected: u64,
55    /// Last inserted row ID
56    pub last_insert_id: i64,
57}
58
59// Keep ping for backwards compatibility
60#[derive(Debug, Deserialize, Serialize)]
61#[serde(rename_all = "camelCase")]
62pub struct PingRequest {
63    pub value: Option<String>,
64}
65
66#[derive(Debug, Clone, Default, Deserialize, Serialize)]
67#[serde(rename_all = "camelCase")]
68pub struct PingResponse {
69    pub value: Option<String>,
70}