Skip to content

Commit dda3e88

Browse files
committed
#feature Implemented bool types for QueryParameter<'_>. Upgraded to v0.1.2
1 parent 65babf0 commit dda3e88

11 files changed

Lines changed: 53 additions & 47 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ Year format is defined as: `YYYY-m-d`
99

1010
## [Unreleased]
1111

12-
## [0.1.2] - 2023 - 03 - 23
13-
14-
### Update
15-
16-
- Removed from `postgresql` migrations the auto conversion to lowercase of the table and column names
17-
18-
### Fix
19-
2012
- Solved a bug in the canyon_entity proc macro that was wiring the incorrect user table name in the migrations
2113

2214
## [0.1.1] - 2023 - 03 - 20

canyon_connection/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "canyon_connection"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
documentation = "https://zerodaycode.github.io/canyon-book/"
66
homepage = "https://github.com/zerodaycode/Canyon-SQL"

canyon_crud/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "canyon_crud"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
documentation = "https://zerodaycode.github.io/canyon-book/"
66
homepage = "https://github.com/zerodaycode/Canyon-SQL"
@@ -12,4 +12,4 @@ description = "A Rust ORM and QueryBuilder"
1212
chrono = { version = "0.4", features = ["serde"] }
1313
async-trait = { version = "0.1.50" }
1414

15-
canyon_connection = { version = "0.1.1", path = "../canyon_connection" }
15+
canyon_connection = { version = "0.1.2", path = "../canyon_connection" }

canyon_crud/src/bounds.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ impl<'a> IntoSql<'a> for &'a dyn QueryParameter<'a> {
237237
}
238238
}
239239

240+
impl<'a> QueryParameter<'a> for bool {
241+
fn as_postgres_param(&self) -> &(dyn ToSql + Sync) {
242+
self
243+
}
244+
245+
fn as_sqlserver_param(&self) -> ColumnData<'_> {
246+
ColumnData::Bit(Some(*self))
247+
}
248+
}
240249
impl<'a> QueryParameter<'a> for i16 {
241250
fn as_postgres_param(&self) -> &(dyn ToSql + Sync) {
242251
self

canyon_macros/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "canyon_macros"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
documentation = "https://zerodaycode.github.io/canyon-book/"
66
homepage = "https://github.com/zerodaycode/Canyon-SQL"
@@ -18,6 +18,6 @@ proc-macro2 = "1.0.27"
1818
futures = "0.3.21"
1919
tokio = { version = "1.9.0", features = ["full"] }
2020

21-
canyon_observer = { version = "0.1.1", path = "../canyon_observer" }
22-
canyon_crud = { version = "0.1.1", path = "../canyon_crud" }
23-
canyon_connection = { version = "0.1.1", path = "../canyon_connection" }
21+
canyon_observer = { version = "0.1.2", path = "../canyon_observer" }
22+
canyon_crud = { version = "0.1.2", path = "../canyon_crud" }
23+
canyon_connection = { version = "0.1.2", path = "../canyon_connection" }

canyon_macros/src/canyon_macro.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use proc_macro2::{Ident, TokenStream};
55

66
use quote::quote;
77

8-
use canyon_observer::{QUERIES_TO_EXECUTE, CM_QUERIES_TO_EXECUTE};
8+
use canyon_observer::{CM_QUERIES_TO_EXECUTE, QUERIES_TO_EXECUTE};
99
use syn::{Lit, NestedMeta};
1010

1111
#[derive(Debug)]
@@ -109,7 +109,7 @@ fn report_literals_not_allowed(ident: &str, s: &Lit) -> TokenStream1 {
109109
pub fn wire_queries_to_execute(canyon_manager_tokens: &mut Vec<TokenStream>) {
110110
let cm_data = CM_QUERIES_TO_EXECUTE.lock().unwrap();
111111
let data = QUERIES_TO_EXECUTE.lock().unwrap();
112-
112+
113113
let cm_data_to_wire = cm_data.iter().map(|(key, value)| {
114114
quote! { cm_hm.insert(#key, vec![#(#value),*]); }
115115
});
@@ -123,10 +123,10 @@ pub fn wire_queries_to_execute(canyon_manager_tokens: &mut Vec<TokenStream>) {
123123

124124
let mut cm_hm: HashMap<&str, Vec<&str>> = HashMap::new();
125125
let mut hm: HashMap<&str, Vec<&str>> = HashMap::new();
126-
126+
127127
#(#cm_data_to_wire)*;
128128
#(#data_to_wire)*;
129-
129+
130130
MigrationsProcessor::from_query_register(&cm_hm).await;
131131
MigrationsProcessor::from_query_register(&hm).await;
132132
};

canyon_observer/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "canyon_observer"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
documentation = "https://zerodaycode.github.io/canyon-book/"
66
homepage = "https://github.com/zerodaycode/Canyon-SQL"
@@ -23,5 +23,5 @@ quote = "1.0.9"
2323
partialdebug = "0.2.0"
2424

2525
# Internal dependencies
26-
canyon_crud = { version = "0.1.1", path = "../canyon_crud" }
27-
canyon_connection = { version = "0.1.1", path = "../canyon_connection" }
26+
canyon_crud = { version = "0.1.2", path = "../canyon_crud" }
27+
canyon_connection = { version = "0.1.2", path = "../canyon_connection" }

canyon_observer/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub static CANYON_REGISTER_ENTITIES: Mutex<Vec<CanyonRegisterEntity<'static>>> =
2525
lazy_static! {
2626
pub static ref QUERIES_TO_EXECUTE: Mutex<HashMap<&'static str, Vec<String>>> =
2727
Mutex::new(HashMap::new());
28-
2928
pub static ref CM_QUERIES_TO_EXECUTE: Mutex<HashMap<&'static str, Vec<String>>> =
3029
Mutex::new(HashMap::new());
3130
}

canyon_observer/src/migrations/memory.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl CanyonMemory {
6161
#[allow(clippy::nonminimal_bool)]
6262
pub async fn remember(
6363
datasource: &DatasourceConfig<'static>,
64-
canyon_entities: &Vec<CanyonRegisterEntity<'_>>,
64+
canyon_entities: &[CanyonRegisterEntity<'_>],
6565
) -> Self {
6666
// Creates the memory table if not exists
6767
Self::create_memory(datasource.name, &datasource.properties.db_type).await;
@@ -90,18 +90,24 @@ impl CanyonMemory {
9090
renamed_entities: HashMap::new(),
9191
};
9292
Self::find_canyon_entity_annotated_structs(&mut mem, canyon_entities).await;
93-
93+
9494
let mut updates = Vec::new();
9595

96-
for _struct in &mem.memory { // For every program entity detected
97-
let already_in_db = db_rows.iter().find(|el|
98-
el.filepath == _struct.filepath || el.struct_name == _struct.struct_name || el.declared_table_name == _struct.declared_table_name
99-
);
96+
for _struct in &mem.memory {
97+
// For every program entity detected
98+
let already_in_db = db_rows.iter().find(|el| {
99+
el.filepath == _struct.filepath
100+
|| el.struct_name == _struct.struct_name
101+
|| el.declared_table_name == _struct.declared_table_name
102+
});
100103

101104
if let Some(old) = already_in_db {
102-
if !(old.filepath == _struct.filepath && old.struct_name == _struct.struct_name && old.declared_table_name == _struct.declared_table_name) {
105+
if !(old.filepath == _struct.filepath
106+
&& old.struct_name == _struct.struct_name
107+
&& old.declared_table_name == _struct.declared_table_name)
108+
{
103109
updates.push(old.struct_name);
104-
let stmt = format!(
110+
let stmt = format!(
105111
"UPDATE canyon_memory SET filepath = '{}', struct_name = '{}', declared_table_name = '{}' \
106112
WHERE id = {}",
107113
_struct.filepath, _struct.struct_name, _struct.declared_table_name, old.id
@@ -121,7 +127,6 @@ impl CanyonMemory {
121127
}
122128

123129
if already_in_db.is_none() {
124-
println!("\tInsert action for: {_struct:?}");
125130
let stmt = format!(
126131
"INSERT INTO canyon_memory (filepath, struct_name, declared_table_name) \
127132
VALUES ('{}', '{}', '{}')",
@@ -139,7 +144,13 @@ impl CanyonMemory {
139144
.any(|entity| entity.struct_name == db_row.struct_name)
140145
&& !updates.contains(&db_row.struct_name)
141146
{
142-
save_canyon_memory_query(format!("DELETE FROM canyon_memory WHERE struct_name = '{}'", db_row.struct_name), datasource.name);
147+
save_canyon_memory_query(
148+
format!(
149+
"DELETE FROM canyon_memory WHERE struct_name = '{}'",
150+
db_row.struct_name
151+
),
152+
datasource.name,
153+
);
143154
}
144155
}
145156
mem
@@ -219,15 +230,10 @@ impl CanyonMemory {
219230
}
220231
}
221232

222-
223-
fn save_canyon_memory_query<'a>(stmt: String, ds_name: &'static str) {
233+
fn save_canyon_memory_query(stmt: String, ds_name: &'static str) {
224234
use crate::CM_QUERIES_TO_EXECUTE;
225235

226-
if CM_QUERIES_TO_EXECUTE
227-
.lock()
228-
.unwrap()
229-
.contains_key(ds_name)
230-
{
236+
if CM_QUERIES_TO_EXECUTE.lock().unwrap().contains_key(ds_name) {
231237
CM_QUERIES_TO_EXECUTE
232238
.lock()
233239
.unwrap()
@@ -240,7 +246,7 @@ fn save_canyon_memory_query<'a>(stmt: String, ds_name: &'static str) {
240246
.unwrap()
241247
.insert(ds_name, vec![stmt]);
242248
}
243-
}
249+
}
244250

245251
/// Represents a single row from the `canyon_memory` table
246252
#[derive(Debug)]

canyon_sql/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "canyon_sql"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55
authors = ["Alex Vergara<pyzyryab@tutanota.com>, Gonzalo Busto<gbm25@gmail.com>"]
66
documentation = "https://zerodaycode.github.io/canyon-book/"
@@ -13,7 +13,7 @@ description = "A Rust ORM and QueryBuilder"
1313
async-trait = { version = "0.1.50" }
1414

1515
# Project crates
16-
canyon_macros = { version = "0.1.1", path = "../canyon_macros" }
17-
canyon_observer = { version = "0.1.1", path = "../canyon_observer" }
18-
canyon_crud = { version = "0.1.1", path = "../canyon_crud" }
19-
canyon_connection = { version = "0.1.1", path = "../canyon_connection" }
16+
canyon_macros = { version = "0.1.2", path = "../canyon_macros" }
17+
canyon_observer = { version = "0.1.2", path = "../canyon_observer" }
18+
canyon_crud = { version = "0.1.2", path = "../canyon_crud" }
19+
canyon_connection = { version = "0.1.2", path = "../canyon_connection" }

0 commit comments

Comments
 (0)