Struct Glue

Source
pub struct Glue {
    pub primary: String,
    pub tempdb: TempDB,
    /* private fields */
}
Expand description

§Glue

Glue is the interface for interacting with MultiSQL; a Glue instance comprises any number of stores, each with their own identifier. Once built, one will typically interact with Glue via queries.

There is a number of ways to deposit queries however, depending on the desired output:

  • Glue::execute() – Might be considered the most generic. Replies with a Result<Payload> (payload being the response from any type of query).
  • Glue::execute_many() – Same as execute() but will find any number of seperate queries in given text and provide a Vec in response.
  • Glue::select_as_string() – Provides data, only for SELECT queries, as Strings (rather than Values).
  • [Glue::select_as_json()] – Provides data, only for SELECT queries, as one big String; generally useful for webby interactions.

Fields§

§primary: String§tempdb: TempDB

Implementations§

Source§

impl Glue

Source

pub async fn auto_increment( &mut self, database: &Option<String>, table_name: &str, columns: &[Column], rows: &mut [Row], ) -> Result<()>

Source§

impl Glue

Source

pub async fn ast_delete( &mut self, table_name: &ObjectName, selection: &Option<Expr>, ) -> Result<Payload>

Source§

impl Glue

Source

pub async fn ast_insert( &mut self, table_name: &ObjectName, columns: &[Ident], source: &Query, expect_data: bool, ) -> Result<Payload>

Source

pub async fn true_insert( &mut self, database: &Option<String>, table: &str, columns: &[&str], rows: Vec<Vec<Value>>, labels: Option<Vec<String>>, expect_data: bool, ) -> Result<Payload>

Source

pub async fn insert_data( &mut self, database: &Option<String>, table_name: &str, rows: Vec<Row>, ) -> Result<()>

Source§

impl Glue

Source

pub async fn ast_update( &mut self, table: &TableWithJoins, selection: &Option<Expr>, assignments: &[Assignment], ) -> Result<Payload>

Source§

impl Glue

Source

pub async fn ast_alter_table( &mut self, name: &ObjectName, operation: &AlterTableOperation, ) -> Result<()>

Source§

impl Glue

Source

pub async fn ast_drop( &mut self, object_type: &ObjectType, names: &[ObjectName], if_exists: bool, ) -> Result<()>

Source§

impl Glue

Source

pub async fn ast_truncate(&mut self, table_name: &ObjectName) -> Result<()>

Source§

impl Glue

Source

pub async fn ast_create_index( &mut self, table: &ObjectName, name: &ObjectName, columns: &[OrderByExpr], unique: bool, if_not_exists: bool, ) -> Result<()>

Source§

impl Glue

Source

pub async fn ast_create_table( &mut self, name: &ObjectName, column_defs: &[ColumnDef], if_not_exists: bool, ) -> Result<()>

Source

pub async fn add_table( &mut self, database: Option<String>, schema: Schema, if_not_exists: bool, ) -> Result<()>

Source§

impl Glue

Source

pub async fn ast_create_view( &mut self, name: &ObjectName, query: &Box<Query>, or_replace: bool, ) -> Result<()>

Source§

impl Glue

Source

pub async fn execute_query(&mut self, statement: &Query) -> Result<Payload>

Source§

impl Glue

Source

pub async fn explain(&self, object: &ObjectName) -> Result<Payload>

Source§

impl Glue

Source

pub async fn ast_procedure( &mut self, name: &Ident, parameters: &[Expr], ) -> Result<Payload>

Source§

impl Glue

Source

pub async fn get_columns( &self, table: ComplexTableName, ) -> Result<Vec<ColumnInfo>>

Source

pub fn get_view_columns<'life0, 'life1, 'life_self, 'async_recursion>( &'life_self self, view_name: &'life0 str, database: &'life1 Option<String>, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<String>>>> + 'async_recursion>>
where 'life0: 'async_recursion, 'life1: 'async_recursion, 'life_self: 'async_recursion,

Source§

impl Glue

Source

pub async fn get_view_data( &self, view_name: &str, database: &Option<String>, ) -> Result<Option<(Vec<String>, Vec<Vec<Value>>)>>

Source

pub async fn get_view_query( &self, view_name: &str, database: &Option<String>, ) -> Result<Option<Select>>

Source§

impl Glue

Source

pub fn get_rows<'life0, 'life1, 'life2, 'life_self, 'async_recursion>( &'life_self self, table: &'life0 str, database: &'life1 Option<String>, index_filter: &'life2 Option<IndexFilter>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<Value>>>> + 'async_recursion>>
where 'life0: 'async_recursion, 'life1: 'async_recursion, 'life2: 'async_recursion, 'life_self: 'async_recursion,

Source

pub async fn get_view_rows( &self, view_name: &str, database: &Option<String>, ) -> Result<Option<Vec<Vec<Value>>>>

Source

pub async fn get_table_rows( &self, table: &str, database: &Option<String>, index_filter: &Option<IndexFilter>, ) -> Result<Vec<Vec<Value>>>

Source§

impl Glue

Source

pub async fn select(&self, plan: Plan) -> Result<(Vec<String>, Vec<Vec<Value>>)>

Source

pub async fn select_query( &self, query: Select, order_by: Vec<OrderByExpr>, ) -> Result<(Vec<String>, Vec<Vec<Value>>)>

Source§

impl Glue

Source

pub fn from_body<'life_self, 'async_recursion>( &'life_self mut self, body: SetExpr, order_by: Vec<OrderByExpr>, ) -> Pin<Box<dyn Future<Output = Result<(Vec<String>, Vec<Vec<Value>>)>> + 'async_recursion>>
where 'life_self: 'async_recursion,

Source§

impl Glue

Source

pub fn ast_query<'life_self, 'async_recursion>( &'life_self mut self, query: Query, ) -> Pin<Box<dyn Future<Output = Result<(Vec<String>, Vec<Vec<Value>>)>> + 'async_recursion>>
where 'life_self: 'async_recursion,

Source§

impl Glue

Source

pub async fn set_variable( &mut self, variable: &Ident, value: &[SetVariableValue], ) -> Result<()>

Source§

impl Glue

Source

pub fn get_database( &self, db_ref: &Option<String>, ) -> Result<MutexGuard<'_, Box<DatabaseInner>>>

Source

pub fn get_mut_database( &mut self, db_ref: &Option<String>, ) -> Result<&mut Box<DatabaseInner>>

Source

pub fn get_database_list(&self) -> Vec<&String>

Source§

impl Glue

§Insert (INSERT)
Source

pub fn insert( &mut self, database: Option<&str>, table: &str, columns: &[&str], recipes: Vec<Vec<Recipe>>, ) -> Result<Payload>

Source§

impl Glue

§Select (SELECT)
Source

pub fn select_json(&mut self, query: &str) -> Result<JSONValue>

Only for SELECT queries.

Output is one big serde_json::Value, wrapped in a Result.

Generally useful for webby interactions.

Source

pub fn select_as_string(&mut self, query: &str) -> Result<Vec<Vec<String>>>

Only for SELECT queries.

Source

pub fn select_as_csv(&mut self, query: &str) -> Result<String>

Only for SELECT queries.

Source§

impl Glue

§Creation of new interfaces
Source

pub fn new(name: String, database: Database) -> Self

Creates a Glue instance with just one Database.

Source

pub fn new_multi(databases: HashMap<String, Database>) -> Self

Creates a Glue instance with access to all provided storages. Argument is: Vec<(Identifier, Database)>

Source

pub fn new_multi_glue(glues: Vec<Glue>) -> Self

Merges existing Glue instances

Source

pub fn extend_many_glues(&mut self, glues: Vec<Glue>)

Merge existing Glue with Vec of other Glues For example:

use multisql::{SledDatabase, Database, Glue};
let storage = SledDatabase::new("data/example_location/example")
  .map(Database::new_sled)
  .expect("Database Creation Failed");
let mut glue = Glue::new(String::from("main"), storage);

glue.execute_many("
  DROP TABLE IF EXISTS test;
  CREATE TABLE test (id INTEGER);
  INSERT INTO test VALUES (1),(2);
  SELECT * FROM test WHERE id > 1;
");

let other_storage = SledDatabase::new("data/example_location/example_other")
  .map(Database::new_sled)
  .expect("Database Creation Failed");
let mut other_glue = Glue::new(String::from("other"), other_storage);

glue.extend_many_glues(vec![other_glue]);
Source

pub fn extend_glue(&mut self, glue: Glue)

Source

pub fn try_extend_from_path( &mut self, database_name: String, database_path: String, ) -> Result<bool>

Extend using a [Path] String which represents a path Guesses the type of database based on the extension Returns bool of whether action was taken

Source

pub fn extend(&mut self, database_name: String, database: Database) -> bool

Extend Glue by single database Returns bool of whether action was taken

Source

pub fn reduce(&mut self, database_name: &String) -> bool

Opposite of Glue::extend, removes database Returns bool of whether action was taken

Source§

impl Glue

Source§

impl Glue

§Execute (Generic)
Source

pub fn execute(&mut self, query: &str) -> Result<Payload>

Will execute a single query.

Source

pub fn execute_many(&mut self, query: &str) -> Result<Vec<Payload>>

Will execute a set of queries.

Source

pub fn execute_parsed(&mut self, query: Query) -> Result<Payload>

Will execute a pre-parsed query (see Glue::pre_parse() for more).

Source

pub fn pre_parse(query: &str) -> Result<Vec<Query>>

Provides a parsed query to execute later. Particularly useful if executing a small query many times as parsing is not (computationally) free.

Source§

impl Glue

§Insert (INSERT)
Source

pub fn insert_vec( &mut self, table_name: String, columns: Vec<String>, rows: Vec<Vec<Value>>, ) -> Result<Payload>

Auto Trait Implementations§

§

impl Freeze for Glue

§

impl RefUnwindSafe for Glue

§

impl !Send for Glue

§

impl !Sync for Glue

§

impl Unpin for Glue

§

impl UnwindSafe for Glue

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<Core, Value> ConvertFrom<Value> for Core
where Value: Convert<Core> + Clone,

Source§

fn convert_from(value: Value) -> Result<Core, Error>

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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = 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.