Struct Route

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

Statement route.

PgDog uses this to decide where a query should be sent to. Read statements are sent to a replica, while write ones are sent the primary. If the cluster has more than one shard, the statement can be sent to a specific database, or all of them.

§Example

use pgdog_plugin::{Shard, ReadWrite, Route};

// This sends the query to the primary database of shard 0.
let route = Route::new(Shard::Direct(0), ReadWrite::Write);

// This sends the query to all shards, routing them to a replica
// of each shard, if any are configured.
let route = Route::new(Shard::All, ReadWrite::Read);

// No routing information is available. PgDog will ignore it
// and make its own decision.
let route = Route::unknown();

Implementations§

Source§

impl Route

Source

pub fn new(shard: Shard, read_write: ReadWrite) -> Route

Create new route.

§Arguments
  • shard: Which shard the statement should be sent to.
  • read_write: Does the statement read or write data. Read statements are sent to a replica. Write statements are sent to the primary.
Source

pub fn unknown() -> Route

Create new route with no sharding or read/write information. Use this if you don’t want your plugin to do query routing. Plugins that do something else with queries, e.g., logging, metrics, can return this route.

Source

pub fn block() -> Route

Block the query from being sent to a database. PgDog will abort the query and return an error to the client, telling them which plugin blocked it.

Trait Implementations§

Source§

impl Default for Route

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for Route

Source§

type Target = PdRoute

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<PdRoute> for Route

Source§

fn from(value: PdRoute) -> Self

Converts to this type from the input type.
Source§

impl From<Route> for PdRoute

Source§

fn from(value: Route) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Route

§

impl RefUnwindSafe for Route

§

impl Send for Route

§

impl Sync for Route

§

impl Unpin for Route

§

impl UnwindSafe for Route

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.