somnia/lib.rs
1//! # somnia — Type-safe SurrealDB ORM
2//!
3//! ```ignore
4//! use somnia::{SomniaClient, SurrealRecord, Thing};
5//! use serde::{Deserialize, Serialize};
6//!
7//! #[derive(SurrealRecord, Serialize, Deserialize)]
8//! #[table("asset")]
9//! struct Asset {
10//! #[field(thing)]
11//! id: Thing<Asset>,
12//! name: String,
13//! #[field(name = "content_type")]
14//! content_type: Option<String>,
15//! file_size: Option<i64>,
16//! }
17//!
18//! async fn example() -> Result<(), SomniaError> {
19//! let db = SomniaClient::connect("ws://localhost:8000", "root", "root", "ns", "db").await?;
20//!
21//! // Typed column accessors are generated by the derive macro:
22//! let videos: Vec<Asset> = db.query(
23//! &Asset::table()
24//! .select(Asset::all())
25//! .filter(Asset::name().eq("video/mp4".to_string()))
26//! .filter(Asset::file_size().gt(1024 * 1024))
27//! .limit(10)
28//! ).await?;
29//!
30//! let db = db;
31//! Ok(())
32//! }
33//! ```
34
35pub mod auth;
36pub mod connection;
37pub mod live;
38pub mod migrate;
39
40pub use auth::Credentials;
41pub use connection::{SomniaClient, SomniaError};
42pub use live::{Action, LiveQueryStream, Notification};
43pub use migrate::{MigrationStatus, Migrator};
44pub use somnia_core::{
45 col,
46 expr::{
47 Closure, Column, ColumnMeta, ColumnSet, DynExpr, IfExpr, KnnExpr, Literal, MatchesExpr,
48 Order, Param, Path, SurrealQL,
49 },
50 field, ident,
51 query::{
52 Batch, Create, DefineAnalyzer, DefineEvent, DefineFunction, DefineIndex, DefineParam,
53 Delete, For, Insert, LetVar, Relate, RelateEdge, Returning, Search, Select, Table,
54 Transaction, Update, VectorSearch,
55 },
56 types::{Key, SurrealEdge, SurrealRecord, SurrealSchema, Thing},
57 DynExprBox, Func, Grouped, Ident, NoneLit, Projection, Raw, RecordLink,
58};
59pub use somnia_derive::{SurrealEdge, SurrealRecord};