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
impl JoinTables
Sourcepub fn add_join_table(
&mut self,
schema: &str,
table_name: &str,
join_columns: &[&str],
destination_columns: &[&str],
) -> Result<&mut Self, JoinTableError>
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");
Sourcepub fn get_joined_text(&self) -> String
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.
Sourcepub fn is_tables_empty(&self) -> bool
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
impl Clone for JoinTables
Source§fn clone(&self) -> JoinTables
fn clone(&self) -> JoinTables
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for JoinTables
impl RefUnwindSafe for JoinTables
impl Send for JoinTables
impl Sync for JoinTables
impl Unpin for JoinTables
impl UnwindSafe for JoinTables
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more