Struct JoinTables

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

Represents a collection of join tables in a database.

§Example

use safety_postgres::access::join_tables::JoinTables;

let mut join_tables = JoinTables::new();

join_tables.add_join_table(
    "",
    "joined_table",
    &vec!["joined_table_c1"],
    &vec!["main_table_c1"]).expect("add joined table failed");

let join_text = join_tables.get_joined_text();
let expected_text =
    "INNER JOIN joined_table ON main_table_name.main_table_c1 = joined_table.joined_table_c1";

assert_eq!(join_text, expected_text.to_string());

Implementations§

Source§

impl JoinTables

Source

pub fn new() -> Self

Create a new instance of JoinTables.

Source

pub fn add_join_table( &mut self, schema: &str, table_name: &str, join_columns: &[&str], destination_columns: &[&str], ) -> Result<&mut Self, JoinTableError>

Adds a join table to the instance.

§Arguments
  • schema - The schema name for the new join table (input “” if there is no schema_name).
  • table_name - The table name for the new join table.
  • join_columns - The names of the columns in the joined table.
  • destination_columns - The names of the columns in the main(base) table.
§Errors

Returns a JoinTableError if there is an error adding the join table.

§Examples
use safety_postgres::access::join_tables::JoinTables;

let mut join_tables = JoinTables::new();

join_tables.add_join_table("public", "users", &["id"], &["user_id"]).expect("adding join table failed");
let joined_text = join_tables.get_joined_text();

assert_eq!(joined_text, "INNER JOIN public.users ON main_table_name.user_id = public.users.id");
Source

pub fn get_joined_text(&self) -> String

Returns the joined text generated from the given join information.

§Examples
use safety_postgres::access::join_tables::JoinTables;

let mut obj = JoinTables::new();
obj.add_join_table("", "category", &["id"], &["cid"])
    .expect("adding join table failed");
let joined_text = obj.get_joined_text();
println!("Joined Text: {}", joined_text);
// This will display:
// "Joined Text: INNER JOIN main_table_name ON main_table_name.cid = category.id"
§Returns

Returns a String that represents the joined text generated.

Source

pub fn is_tables_empty(&self) -> bool

Checks if the tables collection is empty.

§Returns

Returns true if the tables collection is empty, false otherwise.

Trait Implementations§

Source§

impl Clone for JoinTables

Source§

fn clone(&self) -> JoinTables

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V