mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-07 15:33:45 -04:00
sqlite: Rename utils::ConnectionExt to SqliteKeyValueStoreConnExt
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Benjamin Bouvier
parent
6e369aecc9
commit
6e62f8b269
@@ -45,7 +45,7 @@ use crate::{
|
||||
error::{Error, Result},
|
||||
get_or_create_store_cipher,
|
||||
utils::{
|
||||
load_db_version, repeat_vars, Key, SqliteAsyncConnExt, SqliteConnectionExt as _,
|
||||
load_db_version, repeat_vars, Key, SqliteAsyncConnExt, SqliteKeyValueStoreConnExt,
|
||||
SqliteObjectStoreExt as _,
|
||||
},
|
||||
OpenStoreError,
|
||||
|
||||
@@ -185,20 +185,6 @@ impl SqliteAsyncConnExt for SqliteAsyncConn {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait SqliteConnectionExt {
|
||||
fn set_kv(&self, key: &str, value: &[u8]) -> rusqlite::Result<()>;
|
||||
}
|
||||
|
||||
impl SqliteConnectionExt for rusqlite::Connection {
|
||||
fn set_kv(&self, key: &str, value: &[u8]) -> rusqlite::Result<()> {
|
||||
self.execute(
|
||||
"INSERT INTO kv VALUES (?1, ?2) ON CONFLICT (key) DO UPDATE SET value = ?2",
|
||||
(key, value),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait SqliteTransactionExt {
|
||||
fn chunk_large_query_over<Query, Res>(
|
||||
&self,
|
||||
@@ -255,6 +241,32 @@ impl<'a> SqliteTransactionExt for Transaction<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait for a [`rusqlite::Connection`] that contains a key-value
|
||||
/// table named `kv`.
|
||||
///
|
||||
/// The table should be created like this:
|
||||
///
|
||||
/// ```sql
|
||||
/// CREATE TABLE "kv" (
|
||||
/// "key" TEXT PRIMARY KEY NOT NULL,
|
||||
/// "value" BLOB NOT NULL
|
||||
/// );
|
||||
/// ```
|
||||
pub(crate) trait SqliteKeyValueStoreConnExt {
|
||||
/// Store the given value for the given key.
|
||||
fn set_kv(&self, key: &str, value: &[u8]) -> rusqlite::Result<()>;
|
||||
}
|
||||
|
||||
impl SqliteKeyValueStoreConnExt for rusqlite::Connection {
|
||||
fn set_kv(&self, key: &str, value: &[u8]) -> rusqlite::Result<()> {
|
||||
self.execute(
|
||||
"INSERT INTO kv VALUES (?1, ?2) ON CONFLICT (key) DO UPDATE SET value = ?2",
|
||||
(key, value),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub(crate) trait SqliteObjectStoreExt: SqliteAsyncConnExt {
|
||||
async fn get_kv(&self, key: &str) -> rusqlite::Result<Option<Vec<u8>>> {
|
||||
|
||||
Reference in New Issue
Block a user