Skip to main content

SyncAdapter

Struct SyncAdapter 

Source
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>

Source

pub fn new(adapter: A) -> Result<Self>

Source

pub fn ping(&self) -> Result<()>

Source

pub fn create_table(&self, schema: &TableSchema) -> Result<()>

Source

pub fn insert(&self, table: &str, row: Row) -> Result<Row>

Source

pub fn insert_many(&self, table: &str, rows: Vec<Row>) -> Result<u64>

Source

pub fn find(&self, query: &QueryBuilder) -> Result<Vec<Row>>

Source

pub fn find_one(&self, query: &QueryBuilder) -> Result<Option<Row>>

Source

pub fn update(&self, query: &QueryBuilder) -> Result<u64>

Source

pub fn delete(&self, query: &QueryBuilder) -> Result<u64>

Source

pub fn count(&self, query: &QueryBuilder) -> Result<u64>

Source

pub fn execute_raw(&self, sql: &str, bindings: Vec<Value>) -> Result<u64>

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.