pub struct SyncAdapter<A: DatabaseAdapter> { /* private fields */ }Expand description
Blocking wrapper around any DatabaseAdapter.
SyncAdapter owns a dedicated multi-threaded Tokio runtime and exposes
every async adapter method as a synchronous blocking call. This lets you
use Rusticx in non-async code (CLI tools, scripts, test harnesses) without
managing a runtime yourself.
§Example
ⓘ
use rusticx::prelude::*;
let rt = tokio::runtime::Runtime::new().unwrap();
let adapter = rt.block_on(PostgresAdapter::connect_url("postgres://localhost/mydb"))?;
let sync = SyncAdapter::new(adapter)?;
let schema = TableSchema::from_model::<User>();
sync.create_table(&schema)?;
let rows = sync.find(&QueryBuilder::table("users"))?;Implementations§
Source§impl<A: DatabaseAdapter> SyncAdapter<A>
impl<A: DatabaseAdapter> SyncAdapter<A>
pub fn new(adapter: A) -> Result<Self>
pub fn ping(&self) -> Result<()>
pub fn create_table(&self, schema: &TableSchema) -> Result<()>
pub fn insert(&self, table: &str, row: Row) -> Result<Row>
pub fn insert_many(&self, table: &str, rows: Vec<Row>) -> Result<u64>
pub fn find(&self, query: &QueryBuilder) -> Result<Vec<Row>>
pub fn find_one(&self, query: &QueryBuilder) -> Result<Option<Row>>
pub fn update(&self, query: &QueryBuilder) -> Result<u64>
pub fn delete(&self, query: &QueryBuilder) -> Result<u64>
pub fn count(&self, query: &QueryBuilder) -> Result<u64>
pub fn execute_raw(&self, sql: &str, bindings: Vec<Value>) -> Result<u64>
pub fn query_raw(&self, sql: &str, bindings: Vec<Value>) -> Result<Vec<Row>>
Auto Trait Implementations§
impl<A> !Freeze for SyncAdapter<A>
impl<A> RefUnwindSafe for SyncAdapter<A>where
A: RefUnwindSafe,
impl<A> Send for SyncAdapter<A>
impl<A> Sync for SyncAdapter<A>
impl<A> Unpin for SyncAdapter<A>where
A: Unpin,
impl<A> UnsafeUnpin for SyncAdapter<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for SyncAdapter<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more