diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f508e6..86a1383 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## Unreleased + +## 0.1.1 - 2024-06-03 + +- small description change + ## 0.1.0 - 2024-06-03 - first public version diff --git a/Cargo.toml b/Cargo.toml index 70863d0..9a0fc9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.1" authors = ["Werner Braun "] edition = "2021" #rust-version = "1.78" -description = "Derive macros map struct/field to SQLite table/column. Generate const/fn for create-table,insert,select,update." +description = "Derive map of struct/field to SQLite table/column. Generate const/fn for create-table, insert, select, update." repository = "https://github.com/wbcat/wb_sqlite" license = "MIT OR Apache-2.0" keywords = ["derive", "sqlite", "database", "orm"] diff --git a/src/create_table.rs b/src/create_table.rs index 4a15379..f35c7fb 100644 --- a/src/create_table.rs +++ b/src/create_table.rs @@ -49,7 +49,7 @@ fn gen_struct( col_defs.push_str(&ident.to_string()); col_defs.push(' '); if col_attr.typ.is_empty() { - col_defs.push_str(crate::col_typ(&uf.type_string())); + col_defs.push_str(crate::util::col_typ(&uf.type_string())); } else { col_defs.push_str(&col_attr.typ); } diff --git a/src/create_table_log.rs b/src/create_table_log.rs index 920873f..2b753c4 100644 --- a/src/create_table_log.rs +++ b/src/create_table_log.rs @@ -46,7 +46,7 @@ fn gen_struct( log_values.push_str(&col_name); col_defs.push(' '); if col_attr.typ.is_empty() { - col_defs.push_str(crate::col_typ(&uf.type_string())); + col_defs.push_str(crate::util::col_typ(&uf.type_string())); } else { col_defs.push_str(&col_attr.typ); } diff --git a/src/lib.rs b/src/lib.rs index 485873f..1054f65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -169,22 +169,6 @@ pub fn create_table(input: TokenStream) -> TokenStream { create_table::inner(input).unwrap_or_else(|e| e.into_token_stream()) } -// Get SQLite column datatype from given rust type-string. -fn col_typ(rust_typ: &str) -> &'static str { - match rust_typ { - "bool" | "u8" | "u16" | "u32" | "i8" | "i16" | "i32" | "i64" => "INTEGER NOT NULL", - "f32" | "f64" => "REAL NOT NULL", - "&str" | "String" => "TEXT NOT NULL", - "&[u8]" | "Vec" => "BLOB NOT NULL", - "Option" | "Option" | "Option" | "Option" | "Option" - | "Option" | "Option" | "Option" => "INTEGER", - "Option" | "Option" => "REAL", - "Option" => "TEXT", - "Option>" => "BLOB", - _ => "ANY", - } -} - /// const CREATE_TABLE_LOG_SQL: &'static str = "CREATE ..." /// /// Create logging-table + trigger to log all table row modifications to the logging-table. diff --git a/src/util.rs b/src/util.rs index 99c4060..3c608fb 100644 --- a/src/util.rs +++ b/src/util.rs @@ -18,6 +18,22 @@ pub fn tab_name(ident: &str) -> String { .to_case(Case::Snake) } +/// Get SQLite column datatype from given rust type-string. +pub fn col_typ(rust_typ: &str) -> &'static str { + match rust_typ { + "bool" | "u8" | "u16" | "u32" | "i8" | "i16" | "i32" | "i64" => "INTEGER NOT NULL", + "f32" | "f64" => "REAL NOT NULL", + "&str" | "String" => "TEXT NOT NULL", + "&[u8]" | "Vec" => "BLOB NOT NULL", + "Option" | "Option" | "Option" | "Option" | "Option" + | "Option" | "Option" | "Option" => "INTEGER", + "Option" | "Option" => "REAL", + "Option" => "TEXT", + "Option>" => "BLOB", + _ => "ANY", + } +} + #[derive(Debug, Default)] pub struct TabAttr { pub constraint: String, // table-constraint(s)