From c1a45ebc305cc3b589027ed08621825c94b583ee Mon Sep 17 00:00:00 2001 From: myOmikron Date: Thu, 28 Mar 2024 17:13:11 +0100 Subject: [PATCH 01/16] Restricted lifetimes --- src/lib.rs | 62 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c7e65d5..8868a5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,32 +46,54 @@ pub mod value; mod db_specific; -use rorm_declaration::imr::{Annotation, DbType}; +use rorm_declaration::imr::Annotation; +use rorm_declaration::imr::DbType; use crate::aggregation::SelectAggregator; -use crate::alter_table::{AlterTable, AlterTableData, AlterTableImpl, AlterTableOperation}; +use crate::alter_table::AlterTable; +use crate::alter_table::AlterTableData; +use crate::alter_table::AlterTableImpl; +use crate::alter_table::AlterTableOperation; use crate::conditional::Condition; +use crate::create_column::CreateColumnImpl; #[cfg(feature = "mysql")] use crate::create_column::CreateColumnMySQLData; #[cfg(feature = "postgres")] use crate::create_column::CreateColumnPostgresData; #[cfg(feature = "sqlite")] use crate::create_column::CreateColumnSQLiteData; -use crate::create_column::{CreateColumnImpl, SQLAnnotation}; -use crate::create_index::{CreateIndex, CreateIndexData, CreateIndexImpl}; -use crate::create_table::{CreateTable, CreateTableData, CreateTableImpl}; -use crate::create_trigger::{ - SQLCreateTrigger, SQLCreateTriggerOperation, SQLCreateTriggerPointInTime, -}; -use crate::delete::{Delete, DeleteData, DeleteImpl}; -use crate::drop_table::{DropTable, DropTableData, DropTableImpl}; -use crate::insert::{Insert, InsertData, InsertImpl}; -use crate::join_table::{JoinTableData, JoinTableImpl, JoinType}; +use crate::create_column::SQLAnnotation; +use crate::create_index::CreateIndex; +use crate::create_index::CreateIndexData; +use crate::create_index::CreateIndexImpl; +use crate::create_table::CreateTable; +use crate::create_table::CreateTableData; +use crate::create_table::CreateTableImpl; +use crate::create_trigger::SQLCreateTrigger; +use crate::create_trigger::SQLCreateTriggerOperation; +use crate::create_trigger::SQLCreateTriggerPointInTime; +use crate::delete::Delete; +use crate::delete::DeleteData; +use crate::delete::DeleteImpl; +use crate::drop_table::DropTable; +use crate::drop_table::DropTableData; +use crate::drop_table::DropTableImpl; +use crate::insert::Insert; +use crate::insert::InsertData; +use crate::insert::InsertImpl; +use crate::join_table::JoinTableData; +use crate::join_table::JoinTableImpl; +use crate::join_table::JoinType; use crate::on_conflict::OnConflict; use crate::ordering::OrderByEntry; -use crate::select::{Select, SelectData, SelectImpl}; -use crate::select_column::{SelectColumnData, SelectColumnImpl}; -use crate::update::{Update, UpdateData, UpdateImpl}; +use crate::select::Select; +use crate::select::SelectData; +use crate::select::SelectImpl; +use crate::select_column::SelectColumnData; +use crate::select_column::SelectColumnImpl; +use crate::update::Update; +use crate::update::UpdateData; +use crate::update::UpdateImpl; use crate::value::Value; /** @@ -383,7 +405,10 @@ impl DBImpl { pub fn delete<'until_build, 'post_query>( &self, table_name: &'until_build str, - ) -> impl Delete<'until_build, 'post_query> { + ) -> impl Delete<'until_build, 'post_query> + where + 'post_query: 'until_build, + { let d = DeleteData { model: table_name, lookup: vec![], @@ -408,7 +433,10 @@ impl DBImpl { pub fn update<'until_build, 'post_query>( &self, table_name: &'until_build str, - ) -> impl Update<'until_build, 'post_query> { + ) -> impl Update<'until_build, 'post_query> + where + 'post_query: 'until_build, + { let d = UpdateData { model: table_name, on_conflict: OnConflict::ABORT, From 884221ee10a3739a40eeeb0f24187c9c83c6fa85 Mon Sep 17 00:00:00 2001 From: myOmikron Date: Thu, 28 Mar 2024 17:16:01 +0100 Subject: [PATCH 02/16] Updated version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 878845f..f05c374 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rorm-sql" -version = "0.8.2" +version = "0.8.3" edition = "2021" keywords = ["database", "abstraction-layer", "sqlite", "postgres", "mysql"] categories = ["database"] From f60a75f8850655914f83e8de10be7a17cdee5fb9 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Sat, 1 Jun 2024 23:01:50 +0200 Subject: [PATCH 03/16] Made condition a Cow --- src/conditional.rs | 8 +++---- src/join_table.rs | 11 ++++----- src/lib.rs | 56 +++++++++++++++------------------------------- 3 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/conditional.rs b/src/conditional.rs index 3125901..1f6eb1d 100644 --- a/src/conditional.rs +++ b/src/conditional.rs @@ -39,7 +39,7 @@ pub trait BuildCondition<'a>: 'a { /** This enum represents all available ternary expression. */ -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum TernaryCondition<'a> { /// Between represents "{} BETWEEN {} AND {}" from SQL Between(Box<[Condition<'a>; 3]>), @@ -72,7 +72,7 @@ impl<'a> BuildCondition<'a> for TernaryCondition<'a> { /** This enum represents a binary expression. */ -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum BinaryCondition<'a> { /// Representation of "{} = {}" in SQL Equals(Box<[Condition<'a>; 2]>), @@ -133,7 +133,7 @@ impl<'a> BuildCondition<'a> for BinaryCondition<'a> { /** This enum represents all available unary conditions. */ -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum UnaryCondition<'a> { /// Representation of SQL's "{} IS NULL" IsNull(Box>), @@ -177,7 +177,7 @@ impl<'a> BuildCondition<'a> for UnaryCondition<'a> { /** This enum represents a condition tree. */ -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum Condition<'a> { /// A list of [Condition]s, that get expanded to "{} AND {} ..." Conjunction(Vec>), diff --git a/src/join_table.rs b/src/join_table.rs index 16db45a..aeececa 100644 --- a/src/join_table.rs +++ b/src/join_table.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::fmt::{Display, Formatter, Write}; use crate::conditional::{BuildCondition, Condition}; @@ -63,13 +64,13 @@ pub trait JoinTable<'post_query> { - `s`: Mutable reference to String to write to. - `lookup`: List of values for bind parameter. */ - fn build(self, s: &mut String, lookup: &mut Vec>); + fn build(&self, s: &mut String, lookup: &mut Vec>); } /** Data of a JOIN expression. */ -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Clone)] pub struct JoinTableData<'until_build, 'post_query> { /// Type of the join operation pub join_type: JoinType, @@ -78,7 +79,7 @@ pub struct JoinTableData<'until_build, 'post_query> { /// Alias for the join table pub join_alias: &'until_build str, /// Condition to apply the join on - pub join_condition: &'until_build Condition<'post_query>, + pub join_condition: Cow<'until_build, Condition<'post_query>>, } /** @@ -86,7 +87,7 @@ Representation of the JOIN expression Should only be constructed via [DBImpl::join_table]. */ -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Clone)] pub enum JoinTableImpl<'until_build, 'post_query> { /** SQLite representation of a JOIN expression. @@ -108,7 +109,7 @@ pub enum JoinTableImpl<'until_build, 'post_query> { impl<'until_build, 'post_query> JoinTable<'post_query> for JoinTableImpl<'until_build, 'post_query> { - fn build(self, s: &mut String, lookup: &mut Vec>) { + fn build(&self, s: &mut String, lookup: &mut Vec>) { match self { #[cfg(feature = "sqlite")] JoinTableImpl::SQLite(d) => write!( diff --git a/src/lib.rs b/src/lib.rs index 8868a5b..ff443a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,54 +46,34 @@ pub mod value; mod db_specific; -use rorm_declaration::imr::Annotation; -use rorm_declaration::imr::DbType; +use std::borrow::Cow; + +use rorm_declaration::imr::{Annotation, DbType}; use crate::aggregation::SelectAggregator; -use crate::alter_table::AlterTable; -use crate::alter_table::AlterTableData; -use crate::alter_table::AlterTableImpl; -use crate::alter_table::AlterTableOperation; +use crate::alter_table::{AlterTable, AlterTableData, AlterTableImpl, AlterTableOperation}; use crate::conditional::Condition; -use crate::create_column::CreateColumnImpl; #[cfg(feature = "mysql")] use crate::create_column::CreateColumnMySQLData; #[cfg(feature = "postgres")] use crate::create_column::CreateColumnPostgresData; #[cfg(feature = "sqlite")] use crate::create_column::CreateColumnSQLiteData; -use crate::create_column::SQLAnnotation; -use crate::create_index::CreateIndex; -use crate::create_index::CreateIndexData; -use crate::create_index::CreateIndexImpl; -use crate::create_table::CreateTable; -use crate::create_table::CreateTableData; -use crate::create_table::CreateTableImpl; -use crate::create_trigger::SQLCreateTrigger; -use crate::create_trigger::SQLCreateTriggerOperation; -use crate::create_trigger::SQLCreateTriggerPointInTime; -use crate::delete::Delete; -use crate::delete::DeleteData; -use crate::delete::DeleteImpl; -use crate::drop_table::DropTable; -use crate::drop_table::DropTableData; -use crate::drop_table::DropTableImpl; -use crate::insert::Insert; -use crate::insert::InsertData; -use crate::insert::InsertImpl; -use crate::join_table::JoinTableData; -use crate::join_table::JoinTableImpl; -use crate::join_table::JoinType; +use crate::create_column::{CreateColumnImpl, SQLAnnotation}; +use crate::create_index::{CreateIndex, CreateIndexData, CreateIndexImpl}; +use crate::create_table::{CreateTable, CreateTableData, CreateTableImpl}; +use crate::create_trigger::{ + SQLCreateTrigger, SQLCreateTriggerOperation, SQLCreateTriggerPointInTime, +}; +use crate::delete::{Delete, DeleteData, DeleteImpl}; +use crate::drop_table::{DropTable, DropTableData, DropTableImpl}; +use crate::insert::{Insert, InsertData, InsertImpl}; +use crate::join_table::{JoinTableData, JoinTableImpl, JoinType}; use crate::on_conflict::OnConflict; use crate::ordering::OrderByEntry; -use crate::select::Select; -use crate::select::SelectData; -use crate::select::SelectImpl; -use crate::select_column::SelectColumnData; -use crate::select_column::SelectColumnImpl; -use crate::update::Update; -use crate::update::UpdateData; -use crate::update::UpdateImpl; +use crate::select::{Select, SelectData, SelectImpl}; +use crate::select_column::{SelectColumnData, SelectColumnImpl}; +use crate::update::{Update, UpdateData, UpdateImpl}; use crate::value::Value; /** @@ -468,7 +448,7 @@ impl DBImpl { join_type: JoinType, table_name: &'until_build str, join_alias: &'until_build str, - join_condition: &'until_build Condition<'post_query>, + join_condition: Cow<'until_build, Condition<'post_query>>, ) -> JoinTableImpl<'until_build, 'post_query> { let d = JoinTableData { join_type, From 6c4862c9bf061bbb460caf7a34d1ec923cbec601 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Tue, 3 Sep 2024 11:47:05 +0200 Subject: [PATCH 04/16] Updated libsqlite3-sys to the current version used by sqlx --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f05c374..16afb93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ serde_json = { version = "~1" } uuid = { version = "~1" } # SQlite bindings for printf -libsqlite3-sys = { version = "~0.26", optional = true } +libsqlite3-sys = { version = "~0.28", optional = true } # Bitvec support bit-vec = { version = "~0.6", optional = true } From ed2027b53dd33b7857cc61837093cc3b8e491ec4 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Fri, 6 Sep 2024 20:19:14 +0200 Subject: [PATCH 05/16] Fixed warning about unknown #[cfg] --- build.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/build.rs b/build.rs index 1a95d7e..64b7aa5 100644 --- a/build.rs +++ b/build.rs @@ -1,12 +1,8 @@ -use rustc_version::{version_meta, Channel}; +use rustc_version::{version_meta, Channel, VersionMeta}; fn main() { - // Set cfg flags depending on release channel - let channel = match version_meta().unwrap().channel { - Channel::Stable => "CHANNEL_STABLE", - Channel::Beta => "CHANNEL_BETA", - Channel::Nightly => "CHANNEL_NIGHTLY", - Channel::Dev => "CHANNEL_DEV", - }; - println!("cargo:rustc-cfg={channel}") + println!("cargo::rustc-check-cfg=cfg(CHANNEL_NIGHTLY)"); + if matches!(version_meta(), Ok(VersionMeta { channel: Channel::Nightly, .. })) { + println!("cargo:rustc-cfg=CHANNEL_NIGHTLY"); + } } From 39991ac0fbdb693a8227e4852eadc3c54a9b6748 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Sat, 28 Dec 2024 12:32:00 +0100 Subject: [PATCH 06/16] Upgrade libsqlite-sys --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 16afb93..803a810 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ serde_json = { version = "~1" } uuid = { version = "~1" } # SQlite bindings for printf -libsqlite3-sys = { version = "~0.28", optional = true } +libsqlite3-sys = { version = "~0.30", optional = true } # Bitvec support bit-vec = { version = "~0.6", optional = true } From dcbd91f9a6fc8a8e46ce157adf167c989a519012 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Thu, 20 Feb 2025 14:51:35 +0100 Subject: [PATCH 07/16] Removed unnecessary lifetimes --- src/alter_table.rs | 4 +--- src/create_column.rs | 4 +--- src/drop_table.rs | 2 +- src/insert.rs | 2 +- src/join_table.rs | 4 +--- src/select_column.rs | 2 +- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/alter_table.rs b/src/alter_table.rs index 095bba6..5464564 100644 --- a/src/alter_table.rs +++ b/src/alter_table.rs @@ -80,9 +80,7 @@ pub enum AlterTableImpl<'until_build, 'post_build> { Postgres(AlterTableData<'until_build, 'post_build>), } -impl<'until_build, 'post_build> AlterTable<'post_build> - for AlterTableImpl<'until_build, 'post_build> -{ +impl<'post_build> AlterTable<'post_build> for AlterTableImpl<'_, 'post_build> { fn build(self) -> Result>)>, Error> { match self { #[cfg(feature = "sqlite")] diff --git a/src/create_column.rs b/src/create_column.rs index 2738e58..8be3366 100644 --- a/src/create_column.rs +++ b/src/create_column.rs @@ -101,9 +101,7 @@ pub enum CreateColumnImpl<'until_build, 'post_build> { Postgres(CreateColumnPostgresData<'until_build, 'post_build>), } -impl<'until_build, 'post_build> CreateColumn<'post_build> - for CreateColumnImpl<'until_build, 'post_build> -{ +impl<'post_build> CreateColumn<'post_build> for CreateColumnImpl<'_, 'post_build> { fn build(self, s: &mut String) -> Result<(), Error> { match self { #[cfg(feature = "sqlite")] diff --git a/src/drop_table.rs b/src/drop_table.rs index 4bb5d62..06f1634 100644 --- a/src/drop_table.rs +++ b/src/drop_table.rs @@ -46,7 +46,7 @@ pub enum DropTableImpl<'until_build> { Postgres(DropTableData<'until_build>), } -impl<'until_build> DropTable for DropTableImpl<'until_build> { +impl DropTable for DropTableImpl<'_> { fn if_exists(mut self) -> Self { match self { #[cfg(feature = "sqlite")] diff --git a/src/insert.rs b/src/insert.rs index 1858eaa..78b94b8 100644 --- a/src/insert.rs +++ b/src/insert.rs @@ -69,7 +69,7 @@ pub enum InsertImpl<'until_build, 'post_build> { Postgres(InsertData<'until_build, 'post_build>), } -impl<'until_build, 'post_build> Insert<'post_build> for InsertImpl<'until_build, 'post_build> { +impl<'post_build> Insert<'post_build> for InsertImpl<'_, 'post_build> { fn rollback_transaction(mut self) -> Self { match self { #[cfg(feature = "sqlite")] diff --git a/src/join_table.rs b/src/join_table.rs index aeececa..434052d 100644 --- a/src/join_table.rs +++ b/src/join_table.rs @@ -106,9 +106,7 @@ pub enum JoinTableImpl<'until_build, 'post_query> { Postgres(JoinTableData<'until_build, 'post_query>), } -impl<'until_build, 'post_query> JoinTable<'post_query> - for JoinTableImpl<'until_build, 'post_query> -{ +impl<'post_query> JoinTable<'post_query> for JoinTableImpl<'_, 'post_query> { fn build(&self, s: &mut String, lookup: &mut Vec>) { match self { #[cfg(feature = "sqlite")] diff --git a/src/select_column.rs b/src/select_column.rs index b773adc..8620d80 100644 --- a/src/select_column.rs +++ b/src/select_column.rs @@ -47,7 +47,7 @@ pub enum SelectColumnImpl<'until_build> { Postgres(SelectColumnData<'until_build>), } -impl<'until_build> SelectColumn for SelectColumnImpl<'until_build> { +impl SelectColumn for SelectColumnImpl<'_> { fn build(&self, s: &mut String) { match self { #[cfg(feature = "sqlite")] From a79c915158dd84554ccd3827673e97ae9c3980ff Mon Sep 17 00:00:00 2001 From: gammelalf Date: Wed, 9 Apr 2025 08:42:27 +0200 Subject: [PATCH 08/16] Published v0.9.0 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 803a810..a5196af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rorm-sql" -version = "0.8.3" +version = "0.9.0" edition = "2021" keywords = ["database", "abstraction-layer", "sqlite", "postgres", "mysql"] categories = ["database"] @@ -33,7 +33,7 @@ ipnetwork = { version = "~0.20", optional = true } # Mac Address support mac_address = { version = "~1", optional = true } -rorm-declaration = { version = "0.4.0", path = "../rorm-declaration" } +rorm-declaration = { version = "0.4.1", path = "../rorm-declaration" } [build-dependencies] rustc_version = "0.4.0" From 6585718526a93d4a48ae615a7da0081288b5b097 Mon Sep 17 00:00:00 2001 From: myOmikron Date: Thu, 22 May 2025 19:55:47 +0200 Subject: [PATCH 09/16] Fixed identifier in sqlite if identifier matches a builtin --- src/conditional.rs | 2 +- src/delete.rs | 2 +- src/drop_table.rs | 2 +- src/insert.rs | 8 ++++---- src/join_table.rs | 2 +- src/lib.rs | 1 + src/select.rs | 2 +- src/select_column.rs | 4 ++-- src/update.rs | 6 +++--- 9 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/conditional.rs b/src/conditional.rs index 1f6eb1d..3fb0298 100644 --- a/src/conditional.rs +++ b/src/conditional.rs @@ -235,7 +235,7 @@ impl<'a> BuildCondition<'a> for Condition<'a> { #[cfg(feature = "sqlite")] DBImpl::SQLite => { if let Some(table_name) = table_name { - write!(writer, "{table_name}.")?; + write!(writer, "\"{table_name}\".")?; } write!(writer, "{column_name}") } diff --git a/src/delete.rs b/src/delete.rs index caee2a5..8cae8f9 100644 --- a/src/delete.rs +++ b/src/delete.rs @@ -78,7 +78,7 @@ impl<'until_build, 'post_query> Delete<'until_build, 'post_query> match self { #[cfg(feature = "sqlite")] DeleteImpl::SQLite(mut d) => { - let mut s = format!("DELETE FROM {} ", d.model); + let mut s = format!("DELETE FROM \"{}\" ", d.model); if d.where_clause.is_some() { write!( diff --git a/src/drop_table.rs b/src/drop_table.rs index 06f1634..55077dc 100644 --- a/src/drop_table.rs +++ b/src/drop_table.rs @@ -63,7 +63,7 @@ impl DropTable for DropTableImpl<'_> { match self { #[cfg(feature = "sqlite")] DropTableImpl::SQLite(d) => format!( - "DROP TABLE {}{};", + "DROP TABLE \"{}\"{};", d.name, if d.if_exists { " IF EXISTS" } else { "" } ), diff --git a/src/insert.rs b/src/insert.rs index 78b94b8..87073b7 100644 --- a/src/insert.rs +++ b/src/insert.rs @@ -89,7 +89,7 @@ impl<'post_build> Insert<'post_build> for InsertImpl<'_, 'post_build> { // Handle case, if no columns should be inserted, aka an empty insert if d.columns.is_empty() { let mut s = format!( - "INSERT {}INTO {} DEFAULT VALUES", + "INSERT {}INTO \"{}\" DEFAULT VALUES", match d.on_conflict { OnConflict::ABORT => "OR ABORT ", OnConflict::ROLLBACK => "OR ROLLBACK ", @@ -114,7 +114,7 @@ impl<'post_build> Insert<'post_build> for InsertImpl<'_, 'post_build> { } let mut s = format!( - "INSERT {}INTO {} (", + "INSERT {}INTO \"{}\" (", match d.on_conflict { OnConflict::ABORT => "OR ABORT ", OnConflict::ROLLBACK => "OR ROLLBACK ", @@ -122,7 +122,7 @@ impl<'post_build> Insert<'post_build> for InsertImpl<'_, 'post_build> { d.into_clause, ); for (idx, x) in d.columns.iter().enumerate() { - write!(s, "{x}").unwrap(); + write!(s, "\"{x}\"").unwrap(); if idx != d.columns.len() - 1 { write!(s, ", ").unwrap(); } @@ -133,7 +133,7 @@ impl<'post_build> Insert<'post_build> for InsertImpl<'_, 'post_build> { write!(s, "(").unwrap(); for (idx_2, y) in x.iter().enumerate() { match y { - Value::Ident(st) => write!(s, "{}", *st).unwrap(), + Value::Ident(st) => write!(s, "\"{}\"", *st).unwrap(), Value::Choice(c) => write!(s, "{}", sqlite::fmt(c)).unwrap(), Value::Null(NullType::Choice) => write!(s, "NULL").unwrap(), _ => { diff --git a/src/join_table.rs b/src/join_table.rs index 434052d..95e5d49 100644 --- a/src/join_table.rs +++ b/src/join_table.rs @@ -112,7 +112,7 @@ impl<'post_query> JoinTable<'post_query> for JoinTableImpl<'_, 'post_query> { #[cfg(feature = "sqlite")] JoinTableImpl::SQLite(d) => write!( s, - "{} {} AS {} ON {}", + "{} \"{}\" AS {} ON {}", d.join_type, d.table_name, d.join_alias, diff --git a/src/lib.rs b/src/lib.rs index ff443a7..70fa921 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -412,6 +412,7 @@ impl DBImpl { */ pub fn update<'until_build, 'post_query>( &self, + table_name: &'until_build str, ) -> impl Update<'until_build, 'post_query> where diff --git a/src/select.rs b/src/select.rs index bd9eafe..282c442 100644 --- a/src/select.rs +++ b/src/select.rs @@ -135,7 +135,7 @@ impl<'until_build, 'post_build> Select<'until_build, 'post_build> } } - write!(s, " FROM {}", d.from_clause).unwrap(); + write!(s, " FROM \"{}\"", d.from_clause).unwrap(); for x in d.join_tables { write!(s, " ").unwrap(); diff --git a/src/select_column.rs b/src/select_column.rs index 8620d80..68ea659 100644 --- a/src/select_column.rs +++ b/src/select_column.rs @@ -64,10 +64,10 @@ impl SelectColumn for SelectColumnImpl<'_> { } if let Some(table_name) = d.table_name { - write!(s, "{table_name}.").unwrap(); + write!(s, "\"{table_name}\".").unwrap(); } - write!(s, "{}", d.column_name).unwrap(); + write!(s, "\"{}\"", d.column_name).unwrap(); if d.aggregation.is_some() { write!(s, ")").unwrap(); diff --git a/src/update.rs b/src/update.rs index 550ef98..b9e6890 100644 --- a/src/update.rs +++ b/src/update.rs @@ -150,11 +150,11 @@ impl<'until_build, 'post_build> Update<'until_build, 'post_build> let update_index = d.updates.len() - 1; for (idx, (name, value)) in d.updates.into_iter().enumerate() { if let Value::Choice(c) = value { - write!(s, "{name} = {}", sqlite::fmt(c)).unwrap(); + write!(s, "\"{name}\" = {}", sqlite::fmt(c)).unwrap(); } else if let Value::Null(NullType::Choice) = value { - write!(s, "{name} = NULL").unwrap(); + write!(s, "\"{name}\" = NULL").unwrap(); } else { - write!(s, "{name} = ?").unwrap(); + write!(s, "\"{name}\" = ?").unwrap(); d.lookup.push(value); } if idx != update_index { From bb95f1da8025ea2bd26283898642df0d0c27b0ac Mon Sep 17 00:00:00 2001 From: myOmikron Date: Thu, 22 May 2025 19:56:30 +0200 Subject: [PATCH 10/16] Update version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a5196af..62950d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rorm-sql" -version = "0.9.0" +version = "0.9.1" edition = "2021" keywords = ["database", "abstraction-layer", "sqlite", "postgres", "mysql"] categories = ["database"] From e6e44e4014d15a8e151e9aff6b6c6920d5679237 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Tue, 30 Sep 2025 19:49:10 +0200 Subject: [PATCH 11/16] Declare '\' as `ESCAPE` for `LIKE` on sqlite --- src/conditional.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/conditional.rs b/src/conditional.rs index 3fb0298..26ba287 100644 --- a/src/conditional.rs +++ b/src/conditional.rs @@ -125,6 +125,10 @@ impl<'a> BuildCondition<'a> for BinaryCondition<'a> { lhs.build_to_writer(writer, dialect, lookup)?; write!(writer, " {keyword} ")?; rhs.build_to_writer(writer, dialect, lookup)?; + if matches!(dialect, DBImpl::SQLite) && matches!(keyword, "LIKE" | "NOT LIKE") { + // Sqlite does not default it + write!(writer, " ESCAPE '\'")?; + } write!(writer, ")")?; Ok(()) } From 12c664a7f9518c908daa35afcc8f18524d742c5d Mon Sep 17 00:00:00 2001 From: gammelalf Date: Tue, 30 Sep 2025 20:46:55 +0200 Subject: [PATCH 12/16] Updated version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 62950d3..5b444f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rorm-sql" -version = "0.9.1" +version = "0.9.2" edition = "2021" keywords = ["database", "abstraction-layer", "sqlite", "postgres", "mysql"] categories = ["database"] From fe468cf46b7a92f1c58d63bd9c3ecd9b30a03ba8 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Wed, 1 Oct 2025 14:50:49 +0200 Subject: [PATCH 13/16] Fixed build without sqlite --- Cargo.toml | 2 +- src/conditional.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5b444f4..941b068 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rorm-sql" -version = "0.9.2" +version = "0.9.3" edition = "2021" keywords = ["database", "abstraction-layer", "sqlite", "postgres", "mysql"] categories = ["database"] diff --git a/src/conditional.rs b/src/conditional.rs index 26ba287..a1419ea 100644 --- a/src/conditional.rs +++ b/src/conditional.rs @@ -125,6 +125,7 @@ impl<'a> BuildCondition<'a> for BinaryCondition<'a> { lhs.build_to_writer(writer, dialect, lookup)?; write!(writer, " {keyword} ")?; rhs.build_to_writer(writer, dialect, lookup)?; + #[cfg(feature = "sqlite")] if matches!(dialect, DBImpl::SQLite) && matches!(keyword, "LIKE" | "NOT LIKE") { // Sqlite does not default it write!(writer, " ESCAPE '\'")?; From a965f2652c8156535bc8ab713d8688a7eb967013 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Thu, 2 Oct 2025 10:01:46 +0200 Subject: [PATCH 14/16] Added ILIKE and << operators for postgres-only --- Cargo.toml | 2 +- src/conditional.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 941b068..5571532 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rorm-sql" -version = "0.9.3" +version = "0.10.0" edition = "2021" keywords = ["database", "abstraction-layer", "sqlite", "postgres", "mysql"] categories = ["database"] diff --git a/src/conditional.rs b/src/conditional.rs index a1419ea..27266e9 100644 --- a/src/conditional.rs +++ b/src/conditional.rs @@ -98,6 +98,24 @@ pub enum BinaryCondition<'a> { In(Box<[Condition<'a>; 2]>), /// Representation of "{} NOT IN {}" in SQL NotIn(Box<[Condition<'a>; 2]>), + /// Representation of "{} ILIKE {}" in PostgreSQL + #[cfg(feature = "postgres-only")] + ILike(Box<[Condition<'a>; 2]>), + /// Representation of "{} NOT ILIKE {}" in PostgreSQL + #[cfg(feature = "postgres-only")] + NotILike(Box<[Condition<'a>; 2]>), + /// Representation of "{} << {}" for `inet` in PostgreSQL + #[cfg(feature = "postgres-only")] + Contained(Box<[Condition<'a>; 2]>), + /// Representation of "{} <<= {}" for `inet` in PostgreSQL + #[cfg(feature = "postgres-only")] + ContainedOrEquals(Box<[Condition<'a>; 2]>), + /// Representation of "{} >> {}" for `inet` in PostgreSQL + #[cfg(feature = "postgres-only")] + Contains(Box<[Condition<'a>; 2]>), + /// Representation of "{} >>= {}" for `inet` in PostgreSQL + #[cfg(feature = "postgres-only")] + ContainsOrEquals(Box<[Condition<'a>; 2]>), } impl<'a> BuildCondition<'a> for BinaryCondition<'a> { @@ -120,6 +138,18 @@ impl<'a> BuildCondition<'a> for BinaryCondition<'a> { BinaryCondition::NotRegexp(params) => ("NOT REGEXP", params.as_ref()), BinaryCondition::In(params) => ("IN", params.as_ref()), BinaryCondition::NotIn(params) => ("NOT IN", params.as_ref()), + #[cfg(feature = "postgres-only")] + BinaryCondition::ILike(params) => ("ILIKE", params.as_ref()), + #[cfg(feature = "postgres-only")] + BinaryCondition::NotILike(params) => ("NOT ILIKE", params.as_ref()), + #[cfg(feature = "postgres-only")] + BinaryCondition::Contained(params) => ("<<", params.as_ref()), + #[cfg(feature = "postgres-only")] + BinaryCondition::ContainedOrEquals(params) => ("<<=", params.as_ref()), + #[cfg(feature = "postgres-only")] + BinaryCondition::Contains(params) => (">>", params.as_ref()), + #[cfg(feature = "postgres-only")] + BinaryCondition::ContainsOrEquals(params) => (">>=", params.as_ref()), }; write!(writer, "(")?; lhs.build_to_writer(writer, dialect, lookup)?; From 227fe9fca37f335b4b1bdb4a888d1222e39fcf8e Mon Sep 17 00:00:00 2001 From: gammelalf Date: Thu, 2 Oct 2025 10:14:17 +0200 Subject: [PATCH 15/16] Fixed nightly builds and docsrs --- Cargo.toml | 2 +- build.rs | 8 -------- src/lib.rs | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 5571532..6be3f93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rorm-sql" -version = "0.10.0" +version = "0.10.1" edition = "2021" keywords = ["database", "abstraction-layer", "sqlite", "postgres", "mysql"] categories = ["database"] diff --git a/build.rs b/build.rs deleted file mode 100644 index 64b7aa5..0000000 --- a/build.rs +++ /dev/null @@ -1,8 +0,0 @@ -use rustc_version::{version_meta, Channel, VersionMeta}; - -fn main() { - println!("cargo::rustc-check-cfg=cfg(CHANNEL_NIGHTLY)"); - if matches!(version_meta(), Ok(VersionMeta { channel: Channel::Nightly, .. })) { - println!("cargo:rustc-cfg=CHANNEL_NIGHTLY"); - } -} diff --git a/src/lib.rs b/src/lib.rs index 70fa921..d9a9f32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ //! The module should be used to create sql queries for different SQL dialects. -#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![warn(missing_docs)] #[cfg(not(any(feature = "sqlite", feature = "postgres", feature = "mysql")))] From e2c4ab2e0b7e1eb71d5c84f91171dbedb1383f22 Mon Sep 17 00:00:00 2001 From: gammelalf Date: Thu, 2 Oct 2025 10:22:44 +0200 Subject: [PATCH 16/16] Removed unused dependencies --- Cargo.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6be3f93..914a45b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rorm-sql" -version = "0.10.1" +version = "0.10.2" edition = "2021" keywords = ["database", "abstraction-layer", "sqlite", "postgres", "mysql"] categories = ["database"] @@ -17,7 +17,6 @@ chrono = { version = ">=0.4.20", default-features = false } time = { version = "~0.3" } # Serialization library -serde = { version = "~1" } serde_json = { version = "~1" } # Uuid support @@ -35,9 +34,6 @@ mac_address = { version = "~1", optional = true } rorm-declaration = { version = "0.4.1", path = "../rorm-declaration" } -[build-dependencies] -rustc_version = "0.4.0" - [package.metadata.docs.rs] all-features = true