Struct tiny_web::sys::db::DB

source ·
pub struct DB { /* private fields */ }
Expand description

Responsible for working with postgresql database:

Properties

  • client: Option<tokio_postgres::Client> - Client for connection to database;
  • sql_conn: tokio_postgres::Config - Connection config;
  • tls: Option<MakeTlsConnector> - Use tls for connection when sslmode=require;
  • zone: Option<String> - Time zone to init database;
  • prepare: Vec<DBStatement> - Prepare statement to database.

Implementations§

source§

impl DB

source

pub async fn new(config: Arc<DBConfig>) -> DB

Initializes a new object DB

Parameters
  • config: Arc<DBConfig> - database configuration.
Return
  • DB - new DB object
source

pub async fn connect(&mut self) -> bool

Connect to the database

Return
  • true - the connection was successful;
  • false - the connection was fail.
source

pub async fn query_params( &mut self, query: &str, params: &[&(dyn ToSql + Sync)] ) -> Option<Vec<Row>>

Execute query to database with paramaters

Parmeters
  • query: &str - SQL query;
  • params: &[&(dyn ToSql + Sync)] - Array of params.
Return
  • Option::None - When error query or diconnected;
  • Option::Some(Vec<Row>) - Get result.
source

pub async fn query_raw(&mut self, query: &str) -> Option<Vec<Row>>

Execute query to database and return a raw result

Parmeters
  • query: &str - SQL query;
  • params: &[&(dyn ToSql + Sync)] - Array of params.
Return
  • Option::None - When error query or diconnected;
  • Option::Some(Vec<Row>) - Results.
source

pub async fn query(&mut self, query: &str, assoc: bool) -> Option<Vec<Data>>

Execute query to database

Parmeters
  • query: &str - SQL query;
  • params: &[&(dyn ToSql + Sync)] - Array of params.
Return
  • Option::None - When error query or diconnected;
  • Option::Some(Vec<Data>) - Results.
source

pub async fn query_fast( &mut self, index: usize, params: &[&(dyn ToSql + Sync)] ) -> Option<Vec<Row>>

Execute prepare query to database

Parmeters
  • index: usize - index of prepare query;
  • params: &[&(dyn ToSql + Sync)] - Array of params.
Return
  • Option::None - When error query or diconnected;
  • Option::Some(Vec<Row>) - Results.

Trait Implementations§

source§

impl Debug for DB

source§

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

Formats the value using the given formatter.

Auto Trait Implementations§

§

impl !RefUnwindSafe for DB

§

impl Send for DB

§

impl Sync for DB

§

impl Unpin for DB

§

impl !UnwindSafe for DB

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

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