From e1958abe535f601e7486ba8f510d23bddb1a5468 Mon Sep 17 00:00:00 2001 From: ZacJW Date: Mon, 27 Jan 2025 21:40:35 +0000 Subject: [PATCH] More datatype mapping --- Cargo.lock | 366 +++++++++++++++++++++++++++++++- rasql-core/Cargo.toml | 5 + rasql-core/src/rust/mod.rs | 2 +- rasql-core/src/rust/type_gen.rs | 87 ++++---- 4 files changed, 412 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a92ae9e..063deb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,23 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "async-trait" version = "0.1.85" @@ -25,7 +42,7 @@ checksum = "3f934833b4b7233644e5848f235df3f57ed8c80f1528a26c3dfa13d2147fa056" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.96", ] [[package]] @@ -61,6 +78,18 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -70,12 +99,57 @@ dependencies = [ "generic-array", ] +[[package]] +name = "borsh" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5430e3be710b68d984d1391c854eb431a9d548640711faa54eecb1df93db91cc" +dependencies = [ + "borsh-derive", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8b668d39970baad5356d7c83a86fee3a539e6f93bf6764c97368243e17a0487" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.96", +] + [[package]] name = "bumpalo" version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "bytecheck" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +dependencies = [ + "bytecheck_derive", + "ptr_meta", + "simdutf8", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "byteorder" version = "1.5.0" @@ -103,6 +177,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "convert_case" version = "0.7.1" @@ -142,12 +222,24 @@ dependencies = [ "subtle", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "fallible-iterator" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures-channel" version = "0.3.31" @@ -172,7 +264,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.96", ] [[package]] @@ -229,6 +321,21 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + [[package]] name = "hmac" version = "0.12.1" @@ -238,6 +345,22 @@ dependencies = [ "digest", ] +[[package]] +name = "indexmap" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" +dependencies = [ + "equivalent", + "hashbrown 0.15.2", +] + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + [[package]] name = "js-sys" version = "0.3.77" @@ -306,6 +429,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "object" version = "0.36.7" @@ -418,6 +550,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.93" @@ -436,6 +577,26 @@ dependencies = [ "cc", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "quote" version = "1.0.38" @@ -445,6 +606,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -487,9 +654,12 @@ dependencies = [ "proc-macro2", "quote", "rasql-traits", + "rust_decimal", "sqlparser", - "syn", + "syn 2.0.96", + "thiserror", "tokio-postgres", + "uuid", ] [[package]] @@ -520,7 +690,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76009fbe0614077fc1a2ce255e3a1881a2e3a3527097d5dc6d8212c585e7e38b" dependencies = [ "quote", - "syn", + "syn 2.0.96", ] [[package]] @@ -532,18 +702,116 @@ dependencies = [ "bitflags", ] +[[package]] +name = "rend" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck", +] + +[[package]] +name = "rkyv" +version = "0.7.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" +dependencies = [ + "bitvec", + "bytecheck", + "bytes", + "hashbrown 0.12.3", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", + "tinyvec", + "uuid", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "rust_decimal" +version = "1.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" +dependencies = [ + "arrayvec", + "borsh", + "bytes", + "num-traits", + "rand", + "rkyv", + "serde", + "serde_json", +] + [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + +[[package]] +name = "serde" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + +[[package]] +name = "serde_json" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "sha2" version = "0.10.8" @@ -561,6 +829,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + [[package]] name = "siphasher" version = "1.0.1" @@ -632,6 +906,17 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.96" @@ -643,6 +928,32 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "thiserror" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", +] + [[package]] name = "tinyvec" version = "1.8.1" @@ -712,6 +1023,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + [[package]] name = "typenum" version = "1.17.0" @@ -751,6 +1079,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +[[package]] +name = "uuid" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3758f5e68192bb96cc8f9b7e2c2cfdabb435499a28499a42f8f984092adad4b" + [[package]] name = "version_check" version = "0.9.5" @@ -790,7 +1124,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn", + "syn 2.0.96", "wasm-bindgen-shared", ] @@ -812,7 +1146,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.96", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -929,6 +1263,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a" +dependencies = [ + "memchr", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -947,5 +1299,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.96", ] diff --git a/rasql-core/Cargo.toml b/rasql-core/Cargo.toml index cbb90d6..9fa9708 100644 --- a/rasql-core/Cargo.toml +++ b/rasql-core/Cargo.toml @@ -9,6 +9,8 @@ description = "SQL analysis and Rust type generation for Rasql" [features] tokio-postgres = ["rasql-traits/tokio-postgres", "dep:tokio-postgres"] +uuid = ["dep:uuid"] +rust_decimal = ["dep:rust_decimal"] [dependencies] sqlparser = "0.54.0" @@ -18,3 +20,6 @@ proc-macro2 = "1.0.93" syn = { version = "2.0.96", features = ["full"] } tokio-postgres = { version = "0.7.12", optional = true } convert_case = "0.7.1" +thiserror = "2.0.11" +uuid = { version = "1.12.1", optional = true } +rust_decimal = { version = "1.36.0", optional = true } diff --git a/rasql-core/src/rust/mod.rs b/rasql-core/src/rust/mod.rs index 4153050..3cd0e47 100644 --- a/rasql-core/src/rust/mod.rs +++ b/rasql-core/src/rust/mod.rs @@ -95,7 +95,7 @@ fn generate_table_struct_and_impls< let r#type = match (&field_config.override_type, field_config.id_promote_mode) { (Some(r#type), _) => r#type.clone(), - (None, IdPromoteMode::None) => TypeGen::sql_datatype_to_rust_type(&column.data_type), + (None, IdPromoteMode::None) => TypeGen::sql_datatype_to_rust_type(&column.data_type).unwrap(), (None, IdPromoteMode::TrustedId) => todo!(), (None, IdPromoteMode::Id) => todo!(), }; diff --git a/rasql-core/src/rust/type_gen.rs b/rasql-core/src/rust/type_gen.rs index ad4fd4e..5c86ad3 100644 --- a/rasql-core/src/rust/type_gen.rs +++ b/rasql-core/src/rust/type_gen.rs @@ -1,14 +1,20 @@ +use thiserror::Error; + use crate::rust::TableStructField; use super::TableStruct; pub trait TypeGenerator { - fn sql_datatype_to_rust_type(datatype: &sqlparser::ast::DataType) -> syn::Type; + fn sql_datatype_to_rust_type( + datatype: &sqlparser::ast::DataType, + ) -> Result; fn generate_table_struct(table_struct: &TableStruct) -> proc_macro2::TokenStream; } - +#[derive(Debug, Error)] +#[error("Type generator does not support the following SQL datatype: {0}")] +pub struct UnsupportedDataType(pub sqlparser::ast::DataType); #[cfg(feature = "tokio-postgres")] pub struct TokioPostgresGenerator; @@ -26,8 +32,10 @@ impl TokioPostgresGenerator { #[cfg(feature = "tokio-postgres")] impl TypeGenerator for TokioPostgresGenerator { - fn sql_datatype_to_rust_type(datatype: &sqlparser::ast::DataType) -> syn::Type { - match datatype { + fn sql_datatype_to_rust_type( + datatype: &sqlparser::ast::DataType, + ) -> Result { + Ok(match datatype { sqlparser::ast::DataType::Character(..) | sqlparser::ast::DataType::Char(..) | sqlparser::ast::DataType::CharacterVarying(..) @@ -39,37 +47,32 @@ impl TypeGenerator for TokioPostgresGenerator | sqlparser::ast::DataType::MediumText | sqlparser::ast::DataType::LongText | sqlparser::ast::DataType::String(_) - | sqlparser::ast::DataType::FixedString(_) => syn::Type::Verbatim(quote::quote! {String}), - sqlparser::ast::DataType::Uuid => todo!(), - sqlparser::ast::DataType::CharacterLargeObject(_) => todo!(), - sqlparser::ast::DataType::CharLargeObject(_) => todo!(), - sqlparser::ast::DataType::Clob(_) => todo!(), - sqlparser::ast::DataType::Binary(_) => todo!(), - sqlparser::ast::DataType::Varbinary(_) => todo!(), - sqlparser::ast::DataType::Blob(_) => todo!(), - sqlparser::ast::DataType::TinyBlob => todo!(), - sqlparser::ast::DataType::MediumBlob => todo!(), - sqlparser::ast::DataType::LongBlob => todo!(), - sqlparser::ast::DataType::Bytes(_) => todo!(), - sqlparser::ast::DataType::Numeric(exact_number_info) => todo!(), - sqlparser::ast::DataType::Decimal(exact_number_info) => todo!(), - sqlparser::ast::DataType::BigNumeric(exact_number_info) => todo!(), - sqlparser::ast::DataType::BigDecimal(exact_number_info) => todo!(), - sqlparser::ast::DataType::Dec(exact_number_info) => todo!(), - sqlparser::ast::DataType::Float(_) => todo!(), - sqlparser::ast::DataType::TinyInt(_) => todo!(), - sqlparser::ast::DataType::UnsignedTinyInt(_) => todo!(), - sqlparser::ast::DataType::Int2(_) => todo!(), - sqlparser::ast::DataType::UnsignedInt2(_) => todo!(), - sqlparser::ast::DataType::SmallInt(_) => todo!(), - sqlparser::ast::DataType::UnsignedSmallInt(_) => todo!(), - sqlparser::ast::DataType::MediumInt(_) => todo!(), - sqlparser::ast::DataType::UnsignedMediumInt(_) => todo!(), - sqlparser::ast::DataType::Int(_) => todo!(), + | sqlparser::ast::DataType::FixedString(_) => { + syn::Type::Verbatim(quote::quote! {String}) + } + #[cfg(feature = "uuid")] + sqlparser::ast::DataType::Uuid => syn::Type::Verbatim(quote::quote! {uuid::Uuid}), + sqlparser::ast::DataType::Varbinary(_) + | sqlparser::ast::DataType::Blob(_) + | sqlparser::ast::DataType::TinyBlob + | sqlparser::ast::DataType::MediumBlob + | sqlparser::ast::DataType::LongBlob + | sqlparser::ast::DataType::Bytes(_) + | sqlparser::ast::DataType::Bytea + | sqlparser::ast::DataType::Binary(_) => syn::Type::Verbatim(quote::quote! {Vec}), + #[cfg(feature = "rust_decimal")] + sqlparser::ast::DataType::Numeric(..) + | sqlparser::ast::DataType::Decimal(..) + | sqlparser::ast::DataType::Dec(..) => { + syn::Type::Verbatim(quote::quote! {rust_decimal::Decimal}) + } + sqlparser::ast::DataType::Int2(_) => syn::Type::Verbatim(quote::quote! {i16}), + sqlparser::ast::DataType::UnsignedInt2(_) => syn::Type::Verbatim(quote::quote! {u16}), sqlparser::ast::DataType::Int16 => todo!(), sqlparser::ast::DataType::Int128 => todo!(), sqlparser::ast::DataType::Int256 => todo!(), - sqlparser::ast::DataType::Int32 + sqlparser::ast::DataType::Int(_) + | sqlparser::ast::DataType::Int32 | sqlparser::ast::DataType::Int4(_) | sqlparser::ast::DataType::Integer(_) => syn::Type::Verbatim(quote::quote! {i32}), sqlparser::ast::DataType::UnsignedInt(_) => todo!(), @@ -86,7 +89,8 @@ impl TypeGenerator for TokioPostgresGenerator | sqlparser::ast::DataType::BigInt(_) => syn::Type::Verbatim(quote::quote! {i64}), sqlparser::ast::DataType::UnsignedBigInt(_) => todo!(), sqlparser::ast::DataType::UnsignedInt8(_) => todo!(), - sqlparser::ast::DataType::Float4 + sqlparser::ast::DataType::Float(_) + | sqlparser::ast::DataType::Float4 | sqlparser::ast::DataType::Real | sqlparser::ast::DataType::Float32 => syn::Type::Verbatim(quote::quote! {f32}), sqlparser::ast::DataType::Float64 @@ -105,15 +109,19 @@ impl TypeGenerator for TokioPostgresGenerator sqlparser::ast::DataType::JSON => todo!(), sqlparser::ast::DataType::JSONB => todo!(), sqlparser::ast::DataType::Regclass => todo!(), - sqlparser::ast::DataType::Bytea => todo!(), sqlparser::ast::DataType::Bit(_) => todo!(), sqlparser::ast::DataType::BitVarying(_) => todo!(), sqlparser::ast::DataType::Custom(object_name, vec) => todo!(), sqlparser::ast::DataType::Array(array_elem_type_def) => match array_elem_type_def { - sqlparser::ast::ArrayElemTypeDef::None => unimplemented!(), + sqlparser::ast::ArrayElemTypeDef::None => { + return Err(UnsupportedDataType(datatype.clone())) + } sqlparser::ast::ArrayElemTypeDef::AngleBracket(data_type) | sqlparser::ast::ArrayElemTypeDef::SquareBracket(data_type, _) - | sqlparser::ast::ArrayElemTypeDef::Parenthesis(data_type) => todo!(), + | sqlparser::ast::ArrayElemTypeDef::Parenthesis(data_type) => { + let inner_type = Self::sql_datatype_to_rust_type(&datatype)?; + syn::Type::Verbatim(quote::quote! {Vec<#inner_type>}) + } }, sqlparser::ast::DataType::Map(data_type, data_type1) => todo!(), sqlparser::ast::DataType::Tuple(vec) => todo!(), @@ -124,12 +132,11 @@ impl TypeGenerator for TokioPostgresGenerator sqlparser::ast::DataType::Union(vec) => todo!(), sqlparser::ast::DataType::Nullable(data_type) => todo!(), sqlparser::ast::DataType::LowCardinality(data_type) => todo!(), - sqlparser::ast::DataType::Unspecified => todo!(), sqlparser::ast::DataType::Trigger => todo!(), - sqlparser::ast::DataType::AnyType => todo!(), - } + _ => return Err(UnsupportedDataType(datatype.clone())), + }) } - + fn generate_table_struct(table_struct: &TableStruct) -> proc_macro2::TokenStream { let TableStruct { name,