use serde::{Deserialize, Serialize};
use surrealdb::RecordId as SurrealRecordId;
use surrealdb::sql::Thing;
macro_rules! with_db {
($self:expr, $db:ident, $body:expr) => {
match &$self.conn {
SurrealConnection::Embedded($db) => $body,
SurrealConnection::Network($db) => $body,
}
};
}
mod connection;
mod knowledge;
mod lookups;
mod queries;
mod relationships;
mod trait_impl;
pub use connection::SurrealConnection;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tag {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_at: Option<String>,
}
#[derive(Debug, Clone)]
pub(crate) struct RecordId(Thing);
impl RecordId {
fn new(table: &str, id: &str) -> Self {
Self(Thing::from((table, id)))
}
fn as_thing(&self) -> &Thing {
&self.0
}
fn into_thing(self) -> Thing {
self.0
}
fn to_record_id(&self) -> SurrealRecordId {
SurrealRecordId::from((self.0.tb.as_str(), self.0.id.to_string().as_str()))
}
}
pub struct SurrealDatabase {
conn: SurrealConnection,
}
#[derive(Debug, Deserialize)]
struct ExistsRow {
id: String,
}
#[cfg(test)]
mod tests;