feat(nbstore): improve nbstore (#9512)

This commit is contained in:
EYHN
2025-01-06 09:38:03 +00:00
parent a2563d2180
commit 46c8c4a408
103 changed files with 3337 additions and 3423 deletions
+25 -13
View File
@@ -1,28 +1,32 @@
use chrono::NaiveDateTime;
use super::storage::{Result, SqliteDocStorage};
use super::DocClock;
use super::{error::Result, storage::SqliteDocStorage};
impl SqliteDocStorage {
pub async fn get_peer_remote_clocks(&self, peer: String) -> Result<Vec<DocClock>> {
sqlx::query_as!(
let result = sqlx::query_as!(
DocClock,
"SELECT doc_id, remote_clock as timestamp FROM peer_clocks WHERE peer = ?",
peer
)
.fetch_all(&self.pool)
.await
.await?;
Ok(result)
}
pub async fn get_peer_remote_clock(&self, peer: String, doc_id: String) -> Result<DocClock> {
sqlx::query_as!(
let result = sqlx::query_as!(
DocClock,
"SELECT doc_id, remote_clock as timestamp FROM peer_clocks WHERE peer = ? AND doc_id = ?",
peer,
doc_id
)
.fetch_one(&self.pool)
.await
.await?;
Ok(result)
}
pub async fn set_peer_remote_clock(
@@ -48,13 +52,15 @@ impl SqliteDocStorage {
}
pub async fn get_peer_pulled_remote_clocks(&self, peer: String) -> Result<Vec<DocClock>> {
sqlx::query_as!(
let result = sqlx::query_as!(
DocClock,
"SELECT doc_id, pulled_remote_clock as timestamp FROM peer_clocks WHERE peer = ?",
peer
)
.fetch_all(&self.pool)
.await
.await?;
Ok(result)
}
pub async fn get_peer_pulled_remote_clock(
@@ -62,14 +68,16 @@ impl SqliteDocStorage {
peer: String,
doc_id: String,
) -> Result<DocClock> {
sqlx::query_as!(
let result = sqlx::query_as!(
DocClock,
"SELECT doc_id, pulled_remote_clock as timestamp FROM peer_clocks WHERE peer = ? AND doc_id = ?",
peer,
doc_id
)
.fetch_one(&self.pool)
.await
.await?;
Ok(result)
}
pub async fn set_peer_pulled_remote_clock(
@@ -95,24 +103,28 @@ impl SqliteDocStorage {
}
pub async fn get_peer_pushed_clocks(&self, peer: String) -> Result<Vec<DocClock>> {
sqlx::query_as!(
let result = sqlx::query_as!(
DocClock,
"SELECT doc_id, pushed_clock as timestamp FROM peer_clocks WHERE peer = ?",
peer
)
.fetch_all(&self.pool)
.await
.await?;
Ok(result)
}
pub async fn get_peer_pushed_clock(&self, peer: String, doc_id: String) -> Result<DocClock> {
sqlx::query_as!(
let result = sqlx::query_as!(
DocClock,
"SELECT doc_id, pushed_clock as timestamp FROM peer_clocks WHERE peer = ? AND doc_id = ?",
peer,
doc_id
)
.fetch_one(&self.pool)
.await
.await?;
Ok(result)
}
pub async fn set_peer_pushed_clock(