DB

Struct DB 

Source
pub struct DB {}
Expand description

A struct that represents a database.

Implementations§

Source§

impl DB

Source

pub fn exist_db(db_name: &str) -> bool

Checks whether a database exists.

§Arguments
  • db_name - The name of the database to check.
§Returns
  • bool - true if the database exists, false otherwise.
Source

pub fn exist(table_name: &str) -> bool

Checks whether a table exists in the database.

§Arguments
  • table_name - The name of the table to check.
§Returns
  • bool - true if the table exists, false otherwise.
Source

pub fn exist_schema(table_name: &str, schema: &str) -> bool

Checks whether a table exists in the database.

§Arguments
  • table_name - The name of the table to check.
  • schema - Optional. The name of the schema to check in.
§Returns
  • bool - true if the table exists, false otherwise.
Source

pub fn exec(sql: &str) -> i32

Executes an SQL statement and returns the number of rows affected.

§Arguments
  • sql - The SQL statement to execute.
§Returns
  • i32 - The number of rows affected by the statement.
Source

pub fn transaction(query: DBQuery) -> bool

Executes a list of SQL statements as a single transaction.

§Arguments
  • query - A list of SQL statements to execute.
§Returns
  • bool - true if the transaction was successful, false otherwise.
Source

pub fn transaction_async(query: DBQuery, callback: Box<dyn FnMut(bool)>)

Executes a list of SQL statements as a single transaction asynchronously.

§Arguments
  • sqls - A list of SQL statements to execute.
  • callback - A callback function that is invoked when the transaction is executed, receiving the result of the transaction.
§Returns
  • bool - true if the transaction was successful, false otherwise.
Source

pub fn query(sql: &str, with_columns: bool) -> DBRecord

Executes an SQL query and returns the results as a list of rows.

§Arguments
  • sql - The SQL statement to execute.
  • with_column - Whether to include column names in the result.
§Returns
  • DBRecord - A list of rows returned by the query.
Source

pub fn query_with_params( sql: &str, params: &Array, with_columns: bool, ) -> DBRecord

Executes an SQL query and returns the results as a list of rows.

§Arguments
  • sql - The SQL statement to execute.
  • params - A list of values to substitute into the SQL statement.
  • with_column - Whether to include column names in the result.
§Returns
  • DBRecord - A list of rows returned by the query.
Source

pub fn insert(table_name: &str, values: DBParams)

Inserts a row of data into a table within a transaction.

§Arguments
  • table_name - The name of the table to insert into.
  • values - The values to insert into the table.
§Returns
  • bool - true if the insertion was successful, false otherwise.
Source

pub fn exec_with_records(sql: &str, values: DBParams) -> i32

Executes an SQL statement and returns the number of rows affected.

§Arguments
  • sql - The SQL statement to execute.
  • values - Lists of values to substitute into the SQL statement.
§Returns
  • i32 - The number of rows affected by the statement.
Source

pub fn query_with_params_async( sql: &str, params: &Array, with_columns: bool, callback: Box<dyn FnMut(DBRecord)>, )

Executes an SQL query asynchronously and returns the results as a list of rows.

§Arguments
  • sql - The SQL statement to execute.
  • params - Optional. A list of values to substitute into the SQL statement.
  • with_column - Optional. Whether to include column names in the result. Default is false.
  • callback - A callback function that is invoked when the query is executed, receiving the results as a list of rows.
Source

pub fn insert_async( table_name: &str, values: DBParams, callback: Box<dyn FnMut(bool)>, )

Inserts a row of data into a table within a transaction asynchronously.

§Arguments
  • table_name - The name of the table to insert into.
  • values - The values to insert into the table.
  • callback - A callback function that is invoked when the insertion is executed, receiving the result of the insertion.
Source

pub fn exec_async(sql: &str, values: DBParams, callback: Box<dyn FnMut(i64)>)

Executes an SQL statement with a list of values within a transaction asynchronously and returns the number of rows affected.

§Arguments
  • sql - The SQL statement to execute.
  • values - A list of values to substitute into the SQL statement.
  • callback - A callback function that is invoked when the statement is executed, recieving the number of rows affected.

Auto Trait Implementations§

§

impl Freeze for DB

§

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