Skip to main content

Sqlx

Struct Sqlx 

Source
pub struct Sqlx<DB: Dialect> { /* private fields */ }
Expand description

The fastauth adapter over a sqlx pool. Sqlx::new(pool) infers the database from the pool: a PgPool gives Sqlx<Postgres>, a SqlitePool gives Sqlx<Sqlite>.

Query text is rendered once per query shape and cached; values are always bind parameters. Clones share the pool and the cache.

Implementations§

Source§

impl<DB: Dialect> Sqlx<DB>

Source

pub fn new(pool: Pool<DB>) -> Self

Wraps a pool. Tables keep their plain names (user, session, …).

Source

pub fn table_prefix(self, prefix: impl Into<String>) -> Self

Prefixes every table name: .table_prefix("fa_") stores fa_user, fa_session, …

Source

pub fn rename(self, table: impl Into<String>, to: impl Into<String>) -> Self

Stores table under another name, e.g. .rename("user", "accounts") to keep an existing users table name. The table prefix doesn’t apply to a renamed table.

Source

pub fn pool(&self) -> &Pool<DB>

The pool, for the app’s own queries.

Source§

impl Sqlx<Postgres>

Source

pub fn schema(self, schema: impl Into<String>) -> Self

The Postgres schema for fastauth’s tables. Default: the connection’s search_path. The migrator creates the schema if it doesn’t exist.

Trait Implementations§

Source§

impl<DB: Dialect> Adapter for Sqlx<DB>

Source§

type Tx = SqlxTx<DB>

Source§

async fn begin(&self) -> DbResult<SqlxTx<DB>>

Source§

async fn introspect(&self) -> DbResult<LiveSchema>

Reads the live schema for the migrator. Adapters without DDL return Unsupported.
Source§

async fn apply(&self, plan: &MigrationPlan) -> DbResult<()>

Applies a migration plan computed by the migrator.
Source§

fn render_sql(&self, plan: &MigrationPlan) -> DbResult<String>

Renders a plan as SQL for fastauth generate. Non-SQL adapters return Unsupported.
Source§

async fn session_with_user( &self, q: SessionWithUser<'_>, ) -> DbResult<Option<(Row, Row)>>

Session plus user in one call. The default does two lookups; SQL adapters override.
Source§

impl<DB: Dialect> Clone for Sqlx<DB>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<DB: Dialect> Debug for Sqlx<DB>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<DB: Dialect> Queries for Sqlx<DB>

Source§

async fn insert(&self, q: Insert<'_>) -> DbResult<Row>

Source§

async fn find_one(&self, q: Select<'_>) -> DbResult<Option<Row>>

Source§

async fn find_many(&self, q: Select<'_>) -> DbResult<Vec<Row>>

Source§

async fn update(&self, q: Update<'_>) -> DbResult<u64>

Source§

async fn delete(&self, q: Delete<'_>) -> DbResult<u64>

Source§

async fn count(&self, q: Select<'_>) -> DbResult<u64>

Auto Trait Implementations§

§

impl<DB> !RefUnwindSafe for Sqlx<DB>

§

impl<DB> !UnwindSafe for Sqlx<DB>

§

impl<DB> Forget for Sqlx<DB>

§

impl<DB> Freeze for Sqlx<DB>
where Pool<DB>: Freeze, Option<Arc<Mutex<Transaction<'static, DB>>>>: Freeze,

§

impl<DB> Move for Sqlx<DB>

§

impl<DB> Send for Sqlx<DB>
where Pool<DB>: Send, Option<Arc<Mutex<Transaction<'static, DB>>>>: Send,

§

impl<DB> Sync for Sqlx<DB>
where Pool<DB>: Sync, Option<Arc<Mutex<Transaction<'static, DB>>>>: Sync,

§

impl<DB> Unpin for Sqlx<DB>
where Pool<DB>: Unpin, Option<Arc<Mutex<Transaction<'static, DB>>>>: Unpin,

§

impl<DB> UnsafeUnpin for Sqlx<DB>
where Pool<DB>: UnsafeUnpin, Option<Arc<Mutex<Transaction<'static, DB>>>>: UnsafeUnpin,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more