diff --git a/Cargo.toml b/Cargo.toml index d4cca84..2be0e56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition.workspace = true description = "Entity CRUD and change tracking for SQL databases with SQLx" [workspace.package] -version = "0.3.7" +version = "0.3.8" edition = "2021" [dependencies] diff --git a/sqlx-record-derive/src/lib.rs b/sqlx-record-derive/src/lib.rs index 30fd075..01a8b6f 100644 --- a/sqlx-record-derive/src/lib.rs +++ b/sqlx-record-derive/src/lib.rs @@ -841,8 +841,14 @@ fn generate_get_impl( let index_clause = ::sqlx_record::prelude::build_index_clause(index); - //Filter order_by fields to only those managed - let fields = Self::select_fields().into_iter().collect::<::std::collections::HashSet<_>>(); + //Filter order_by fields to only those managed. select_fields() + //may emit annotated forms like `id as "id: Uuid"` for fields that + //carry a custom type; strip the alias before matching so callers + //can pass bare column names. + let fields = Self::select_fields() + .into_iter() + .map(|s| s.split(" ").next().unwrap_or(s)) + .collect::<::std::collections::HashSet<_>>(); let order_by = order_by.iter() .filter(|(field, _)| fields.contains(field)) .collect::>(); @@ -977,8 +983,13 @@ fn generate_get_impl( { use ::sqlx_record::prelude::{Filter, bind_values}; - // Validate fields exist - let valid_fields: ::std::collections::HashSet<_> = Self::select_fields().into_iter().collect(); + // Validate fields exist. select_fields() may emit annotated + // forms like `id as "id: Uuid"`; strip the alias before + // matching so callers can pass bare column names. + let valid_fields: ::std::collections::HashSet<_> = Self::select_fields() + .into_iter() + .map(|s| s.split(" ").next().unwrap_or(s)) + .collect(); let selected: Vec<_> = select_fields.iter() .filter(|f| valid_fields.contains(*f)) .copied() diff --git a/src/lib.rs b/src/lib.rs index 6796245..fd78f81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -use chrono::Utc; -use rand::random; use uuid::Uuid; mod conn_provider; @@ -23,6 +21,7 @@ pub use sqlx_record_derive::{Entity, Update}; /// Last 8 bytes: random data #[inline] pub fn new_uuid() -> Uuid { + /* let timestamp = Utc::now().timestamp_millis() as u64; let random = random::(); let mut bytes = [0u8; 16]; @@ -30,6 +29,8 @@ pub fn new_uuid() -> Uuid { bytes[8..].copy_from_slice(&random.to_be_bytes()); Uuid::from_bytes(bytes) + */ + Uuid::now_v7() } /// Creates a lookup table entity struct with an associated code enum.