Skip to main content

DatabaseSessionStore

Struct DatabaseSessionStore 

Source
pub struct DatabaseSessionStore { /* private fields */ }
Expand description

Sessions in a table.

The right default for more than one instance: every process reads the same rows, so a user stays logged in wherever the load balancer sends them.

Implementations§

Source§

impl DatabaseSessionStore

Source

pub fn new(db: Database) -> Self

A store over db, with two-hour sessions.

Source

pub fn with_lifetime(self, lifetime: Duration) -> Self

Sessions expiring after lifetime.

Source

pub fn migrations() -> Migrator

The migration this driver needs.

Merge it into the application’s migrator:

ⓘ
Migrator::new()
    .create_table::<User>("0001_create_users")
    .merge(DatabaseSessionStore::migrations())
Source

pub async fn prune(&self) -> Result<u64>

Remove every expired row. Returns how many.

Trait Implementations§

Source§

impl Debug for DatabaseSessionStore

Source§

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

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

impl SessionStore for DatabaseSessionStore

Source§

fn name(&self) -> &str

A label for diagnostics — "memory", "database", "cache", "cookie".
Source§

fn read<'a>(&'a self, id: &'a str) -> BoxFuture<'a, Result<Option<SessionData>>>

The data for this id, or None if it is unknown or expired.
Source§

fn write<'a>( &'a self, id: &'a str, data: &'a SessionData, ) -> BoxFuture<'a, Result<()>>

Write the data back, refreshing its expiry.
Source§

fn destroy<'a>(&'a self, id: &'a str) -> BoxFuture<'a, Result<()>>

Remove a session.
Source§

fn gc(&self) -> BoxFuture<'_, Result<u64>>

Discard every expired session. Called periodically, not per request.
Source§

fn is_client_side(&self) -> bool

Whether the session travels in the cookie rather than being stored here. Read more
Source§

fn encode(&self, id: &str, data: &SessionData) -> Result<String>

The cookie value carrying this session. Read more
Source§

fn decode(&self, value: &str) -> Result<(String, Option<SessionData>)>

Recover a session id — and, for a client-side store, its data — from a cookie value. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

fn event_name() -> &'static str
where Self: Sized,

A human-readable name, used by wildcard listeners and log output. Always the Rust type path; see the trait docs.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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