Skip to main content

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 connection;
36pub mod migrate;
37
38pub use connection::{SomniaClient, SomniaError};
39pub use migrate::{MigrationStatus, Migrator};
40pub use somnia_core::{
41    col,
42    expr::{Column, ColumnMeta, ColumnSet, DynExpr, Order, SurrealQL},
43    field, ident,
44    query::{Batch, Create, Delete, Insert, Relate, RelateEdge, Returning, Select, Table, Update},
45    types::{Key, SurrealEdge, SurrealRecord, SurrealSchema, Thing},
46    DynExprBox, Func, Grouped, Ident, NoneLit, Projection, Raw, RecordLink,
47};
48pub use somnia_derive::SurrealRecord;