diff --git a/src/code.rs b/src/code.rs index 280bb35c..d6dc65f6 100644 --- a/src/code.rs +++ b/src/code.rs @@ -569,7 +569,7 @@ fn build_table_fns( // "Option::None" will never match anything, and "is_null" is required to be used, see https://docs.diesel.rs/master/diesel/expression_methods/trait.ExpressionMethods.html#method.eq format!( r##" - if let Some(filter_{column_name}) = filter.{column_name}.clone() {{ + if let Some(filter_{column_name}) = filter.{column_name} {{ query = if filter_{column_name}.is_some() {{ query.filter({schema_path}{table_name}::{column_name}.eq(filter_{column_name})) }} else {{ @@ -580,7 +580,7 @@ fn build_table_fns( } else { format!( r##" - if let Some(filter_{column_name}) = filter.{column_name}.clone() {{ + if let Some(filter_{column_name}) = filter.{column_name} {{ query = query.filter({schema_path}{table_name}::{column_name}.eq(filter_{column_name})); }}"## ) diff --git a/test/Cargo.lock b/test/Cargo.lock new file mode 100644 index 00000000..033ab97f --- /dev/null +++ b/test/Cargo.lock @@ -0,0 +1,705 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "advanced_queries" +version = "0.1.0" +dependencies = [ + "chrono", + "diesel", + "r2d2", + "serde", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-targets 0.48.5", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "custom_model_and_schema_path" +version = "0.1.0" +dependencies = [ + "chrono", + "diesel", + "serde", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "diesel" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62c6fcf842f17f8c78ecf7c81d75c5ce84436b41ee07e03f490fbb5f5a8731d8" +dependencies = [ + "bitflags 2.4.1", + "byteorder", + "chrono", + "diesel_derives", + "itoa", + "libsqlite3-sys", + "mysqlclient-sys", + "percent-encoding", + "pq-sys", + "r2d2", + "time", + "url", +] + +[[package]] +name = "diesel_derives" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8337737574f55a468005a83499da720f20c65586241ffea339db9ecdfd2b44" +dependencies = [ + "diesel_table_macro_syntax", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diesel_table_macro_syntax" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" +dependencies = [ + "syn", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "js-sys" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" + +[[package]] +name = "libsqlite3-sys" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +dependencies = [ + "pkg-config", + "vcpkg", +] + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "mysqlclient-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f61b381528ba293005c42a409dd73d034508e273bf90481f17ec2e964a6e969b" +dependencies = [ + "pkg-config", + "vcpkg", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pkg-config" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "pq-sys" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c0052426df997c0cbd30789eb44ca097e3541717a7b8fa36b1c464ee7edebd" +dependencies = [ + "vcpkg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r2d2" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93" +dependencies = [ + "log", + "parking_lot", + "scheduled-thread-pool", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "scheduled-thread-pool" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19" +dependencies = [ + "parking_lot", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.194" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.194" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "simple_table_mysql" +version = "0.1.0" +dependencies = [ + "chrono", + "diesel", + "r2d2", + "serde", +] + +[[package]] +name = "simple_table_pg" +version = "0.1.0" +dependencies = [ + "chrono", + "diesel", + "r2d2", + "serde", +] + +[[package]] +name = "simple_table_sqlite" +version = "0.1.0" +dependencies = [ + "chrono", + "diesel", + "r2d2", + "serde", +] + +[[package]] +name = "single_model_file" +version = "0.1.0" +dependencies = [ + "chrono", + "diesel", + "serde", +] + +[[package]] +name = "smallvec" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" + +[[package]] +name = "syn" +version = "2.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "time" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" +dependencies = [ + "deranged", + "itoa", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" +dependencies = [ + "time-core", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicode-bidi" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "wasm-bindgen" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/test/Cargo.toml b/test/Cargo.toml new file mode 100644 index 00000000..b0ddb7c2 --- /dev/null +++ b/test/Cargo.toml @@ -0,0 +1,16 @@ +[workspace] +# only some tests are currently compile-able +members = [ + "simple_table_pg", + "simple_table_mysql", + "simple_table_sqlite", + "custom_model_and_schema_path", + "single_model_file", + "advanced_queries", +] +resolver = "2" + +[workspace.dependencies] +chrono = { version = "*", features = ["serde"] } +serde = { version = "*", features = ["derive"] } +r2d2 = "*" diff --git a/test/advanced_queries/Cargo.toml b/test/advanced_queries/Cargo.toml new file mode 100644 index 00000000..7b61ac04 --- /dev/null +++ b/test/advanced_queries/Cargo.toml @@ -0,0 +1,17 @@ +[lib] +path = "lib.rs" + +[package] +name = "advanced_queries" +version = "0.1.0" +edition = "2021" + +[dependencies] +diesel = { version = "*", default-features = false, features = [ + "postgres", + "r2d2", + "chrono", +] } +r2d2.workspace = true +chrono.workspace = true +serde.workspace = true diff --git a/test/advanced_queries/lib.rs b/test/advanced_queries/lib.rs new file mode 100644 index 00000000..fdea3f51 --- /dev/null +++ b/test/advanced_queries/lib.rs @@ -0,0 +1,6 @@ +pub mod models; +pub mod schema; + +pub mod diesel { + pub use diesel::*; +} diff --git a/test/advanced_queries/models/todos/generated.rs b/test/advanced_queries/models/todos/generated.rs index 7341b7d3..cd2c9c80 100644 --- a/test/advanced_queries/models/todos/generated.rs +++ b/test/advanced_queries/models/todos/generated.rs @@ -11,56 +11,56 @@ pub type ConnectionType = diesel::r2d2::PooledConnection, /// Field representing column `text` pub text: String, /// Field representing column `completed` pub completed: bool, /// Field representing column `type` pub type_: String, + /// Field representing column `smallint` + pub smallint: i16, + /// Field representing column `bigint` + pub bigint: i64, /// Field representing column `created_at` pub created_at: chrono::DateTime, /// Field representing column `updated_at` - pub updated_at: chrono::DateTime, + pub updated_at: chrono::NaiveDateTime, } /// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { - /// Field representing column `unsigned` - pub unsigned: u32, - /// Field representing column `unsigned_nullable` - pub unsigned_nullable: Option, /// Field representing column `text` pub text: String, /// Field representing column `completed` pub completed: bool, /// Field representing column `type` pub type_: String, + /// Field representing column `smallint` + pub smallint: i16, + /// Field representing column `bigint` + pub bigint: i64, } /// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::AsChangeset, PartialEq, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { - /// Field representing column `unsigned` - pub unsigned: Option, - /// Field representing column `unsigned_nullable` - pub unsigned_nullable: Option>, /// Field representing column `text` pub text: Option, /// Field representing column `completed` pub completed: Option, /// Field representing column `type` pub type_: Option, + /// Field representing column `smallint` + pub smallint: Option, + /// Field representing column `bigint` + pub bigint: Option, /// Field representing column `created_at` pub created_at: Option>, /// Field representing column `updated_at` - pub updated_at: Option>, + pub updated_at: Option, } /// Result of a `.paginate` function @@ -131,32 +131,28 @@ impl Todos { ) -> crate::schema::todos::BoxedQuery<'a, diesel::pg::Pg> { let mut query = crate::schema::todos::table.into_boxed(); - if let Some(filter_id) = filter.id.clone() { + if let Some(filter_id) = filter.id { query = query.filter(crate::schema::todos::id.eq(filter_id)); } - if let Some(filter_unsigned) = filter.unsigned.clone() { - query = query.filter(crate::schema::todos::unsigned.eq(filter_unsigned)); - } - if let Some(filter_unsigned_nullable) = filter.unsigned_nullable.clone() { - query = if filter_unsigned_nullable.is_some() { - query.filter(crate::schema::todos::unsigned_nullable.eq(filter_unsigned_nullable)) - } else { - query.filter(crate::schema::todos::unsigned_nullable.is_null()) - }; - } - if let Some(filter_text) = filter.text.clone() { + if let Some(filter_text) = filter.text { query = query.filter(crate::schema::todos::text.eq(filter_text)); } - if let Some(filter_completed) = filter.completed.clone() { + if let Some(filter_completed) = filter.completed { query = query.filter(crate::schema::todos::completed.eq(filter_completed)); } - if let Some(filter_type_) = filter.type_.clone() { + if let Some(filter_type_) = filter.type_ { query = query.filter(crate::schema::todos::type_.eq(filter_type_)); } - if let Some(filter_created_at) = filter.created_at.clone() { + if let Some(filter_smallint) = filter.smallint { + query = query.filter(crate::schema::todos::smallint.eq(filter_smallint)); + } + if let Some(filter_bigint) = filter.bigint { + query = query.filter(crate::schema::todos::bigint.eq(filter_bigint)); + } + if let Some(filter_created_at) = filter.created_at { query = query.filter(crate::schema::todos::created_at.eq(filter_created_at)); } - if let Some(filter_updated_at) = filter.updated_at.clone() { + if let Some(filter_updated_at) = filter.updated_at { query = query.filter(crate::schema::todos::updated_at.eq(filter_updated_at)); } @@ -180,11 +176,11 @@ impl Todos { #[derive(Debug, Default, Clone)] pub struct TodosFilter { pub id: Option, - pub unsigned: Option, - pub unsigned_nullable: Option>, pub text: Option, pub completed: Option, pub type_: Option, + pub smallint: Option, + pub bigint: Option, pub created_at: Option>, - pub updated_at: Option>, + pub updated_at: Option, } diff --git a/test/advanced_queries/schema.rs b/test/advanced_queries/schema.rs index dc033baf..c66e8219 100644 --- a/test/advanced_queries/schema.rs +++ b/test/advanced_queries/schema.rs @@ -1,14 +1,14 @@ diesel::table! { todos (id) { id -> Int4, - unsigned -> Unsigned, - unsigned_nullable -> Nullable>, text -> Text, completed -> Bool, #[sql_name = "type"] #[max_length = 255] type_ -> Varchar, + smallint -> Int2, + bigint -> Int8, created_at -> Timestamptz, - updated_at -> Timestamptz, + updated_at -> Timestamp, } } diff --git a/test/advanced_queries/test.sh b/test/advanced_queries/test.sh index b843c869..4d7e0e41 100755 --- a/test/advanced_queries/test.sh +++ b/test/advanced_queries/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -F advanced-queries -- --diesel-backend diesel::pg::Pg -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file +cargo run -F advanced-queries --manifest-path ../../Cargo.toml -- \ +--diesel-backend diesel::pg::Pg -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" diff --git a/test/autogenerated_all/test.sh b/test/autogenerated_all/test.sh index 4602f622..959ccfec 100755 --- a/test/autogenerated_all/test.sh +++ b/test/autogenerated_all/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file diff --git a/test/autogenerated_attributes/test.sh b/test/autogenerated_attributes/test.sh index af773253..848165e7 100755 --- a/test/autogenerated_attributes/test.sh +++ b/test/autogenerated_attributes/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g created_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g created_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file diff --git a/test/autogenerated_primary_keys/test.sh b/test/autogenerated_primary_keys/test.sh index f9be906a..96babe61 100755 --- a/test/autogenerated_primary_keys/test.sh +++ b/test/autogenerated_primary_keys/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -c "diesel::r2d2::PooledConnection>" +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -c "diesel::r2d2::PooledConnection>" diff --git a/test/cleanup_generated_content/test.sh b/test/cleanup_generated_content/test.sh index a8099e7d..76367701 100755 --- a/test/cleanup_generated_content/test.sh +++ b/test/cleanup_generated_content/test.sh @@ -4,5 +4,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema1.rs -o models -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" -cargo run -- -i schema2.rs -o models -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema1.rs -o models -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema2.rs -o models -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file diff --git a/test/create_update_bytes_cow/test.sh b/test/create_update_bytes_cow/test.sh index ab894ead..7fca70ca 100755 --- a/test/create_update_bytes_cow/test.sh +++ b/test/create_update_bytes_cow/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --create-bytes=cow --update-bytes=cow +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --create-bytes=cow --update-bytes=cow diff --git a/test/create_update_bytes_slice/test.sh b/test/create_update_bytes_slice/test.sh index 97f5688d..88fe027f 100755 --- a/test/create_update_bytes_slice/test.sh +++ b/test/create_update_bytes_slice/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --create-bytes=slice --update-bytes=slice +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --create-bytes=slice --update-bytes=slice diff --git a/test/create_update_str_cow/test.sh b/test/create_update_str_cow/test.sh index 73ab95ec..f08db665 100755 --- a/test/create_update_str_cow/test.sh +++ b/test/create_update_str_cow/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --create-str=cow --update-str=cow +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --create-str=cow --update-str=cow diff --git a/test/create_update_str_str/test.sh b/test/create_update_str_str/test.sh index e10fe55e..a42444ff 100755 --- a/test/create_update_str_str/test.sh +++ b/test/create_update_str_str/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --create-str=str --update-str=str +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --create-str=str --update-str=str diff --git a/test/custom_model_and_schema_path/Cargo.toml b/test/custom_model_and_schema_path/Cargo.toml new file mode 100644 index 00000000..e15967cf --- /dev/null +++ b/test/custom_model_and_schema_path/Cargo.toml @@ -0,0 +1,15 @@ +[lib] +path = "lib.rs" + +[package] +name = "custom_model_and_schema_path" +version = "0.1.0" +edition = "2021" + +[dependencies] +diesel = { version = "*", default-features = false, features = [ + "postgres", + "chrono", +] } +chrono.workspace = true +serde.workspace = true diff --git a/test/custom_model_and_schema_path/data/mod.rs b/test/custom_model_and_schema_path/data/mod.rs new file mode 100644 index 00000000..d5cbad7e --- /dev/null +++ b/test/custom_model_and_schema_path/data/mod.rs @@ -0,0 +1,2 @@ +pub mod models; +pub mod schema; diff --git a/test/custom_model_and_schema_path/data/models/mod.rs b/test/custom_model_and_schema_path/data/models/mod.rs index 9379294b..99661ae2 100644 --- a/test/custom_model_and_schema_path/data/models/mod.rs +++ b/test/custom_model_and_schema_path/data/models/mod.rs @@ -1,2 +1,2 @@ pub mod table_a; -pub mod table_b; \ No newline at end of file +pub mod table_b; diff --git a/test/custom_model_and_schema_path/lib.rs b/test/custom_model_and_schema_path/lib.rs new file mode 100644 index 00000000..73157bb2 --- /dev/null +++ b/test/custom_model_and_schema_path/lib.rs @@ -0,0 +1,6 @@ +#![allow(non_snake_case)] +pub mod data; + +pub mod diesel { + pub use diesel::*; +} diff --git a/test/custom_model_and_schema_path/test.sh b/test/custom_model_and_schema_path/test.sh index 3dab2963..a3286282 100755 --- a/test/custom_model_and_schema_path/test.sh +++ b/test/custom_model_and_schema_path/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i data/schema.rs -o data/models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --schema-path "crate::data::schema::" --model-path "crate::data::models::" +cargo run --manifest-path ../../Cargo.toml -- \ +-i data/schema.rs -o data/models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --schema-path "crate::data::schema::" --model-path "crate::data::models::" diff --git a/test/custom_model_path/test.sh b/test/custom_model_path/test.sh index 762ee789..5625d17c 100755 --- a/test/custom_model_path/test.sh +++ b/test/custom_model_path/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --model-path "crate::data::models::" +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --model-path "crate::data::models::" diff --git a/test/manual_primary_keys/test.sh b/test/manual_primary_keys/test.sh index d49cdd23..87b5d7e8 100755 --- a/test/manual_primary_keys/test.sh +++ b/test/manual_primary_keys/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -c "diesel::r2d2::PooledConnection>" \ No newline at end of file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -c "diesel::r2d2::PooledConnection>" \ No newline at end of file diff --git a/test/multiple_primary_keys/test.sh b/test/multiple_primary_keys/test.sh index d49cdd23..87b5d7e8 100755 --- a/test/multiple_primary_keys/test.sh +++ b/test/multiple_primary_keys/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -c "diesel::r2d2::PooledConnection>" \ No newline at end of file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -c "diesel::r2d2::PooledConnection>" \ No newline at end of file diff --git a/test/no_default_features/test.sh b/test/no_default_features/test.sh index 2f9f0cde..5f5198e0 100755 --- a/test/no_default_features/test.sh +++ b/test/no_default_features/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run --no-default-features -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" +cargo run --no-default-features --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" diff --git a/test/once_common_structs/test.sh b/test/once_common_structs/test.sh index c98e9917..030a44eb 100755 --- a/test/once_common_structs/test.sh +++ b/test/once_common_structs/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --once-common-structs +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --once-common-structs diff --git a/test/once_common_structs_once_connection_type/test.sh b/test/once_common_structs_once_connection_type/test.sh index d18bbc68..01cdd7fd 100755 --- a/test/once_common_structs_once_connection_type/test.sh +++ b/test/once_common_structs_once_connection_type/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --once-common-structs --once-connection-type +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --once-common-structs --once-connection-type diff --git a/test/once_common_structs_once_connection_type_single_file/test.sh b/test/once_common_structs_once_connection_type_single_file/test.sh index 95a120b9..44d44510 100755 --- a/test/once_common_structs_once_connection_type_single_file/test.sh +++ b/test/once_common_structs_once_connection_type_single_file/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --once-common-structs --once-connection-type --single-model-file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --once-common-structs --once-connection-type --single-model-file diff --git a/test/once_connection_type/test.sh b/test/once_connection_type/test.sh index 44b42841..630b8384 100755 --- a/test/once_connection_type/test.sh +++ b/test/once_connection_type/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --once-connection-type +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --once-connection-type diff --git a/test/postgres_array_column/test.sh b/test/postgres_array_column/test.sh index 9f7f0d51..7af45024 100755 --- a/test/postgres_array_column/test.sh +++ b/test/postgres_array_column/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" diff --git a/test/readonly/test.sh b/test/readonly/test.sh index 895965f2..5fb29f43 100755 --- a/test/readonly/test.sh +++ b/test/readonly/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --readonly-prefix prefix --readonly-suffix Suffix +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --readonly-prefix prefix --readonly-suffix Suffix diff --git a/test/simple_table/test.sh b/test/simple_table/test.sh deleted file mode 100755 index 9f7f0d51..00000000 --- a/test/simple_table/test.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - -cd $SCRIPT_DIR - -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" \ No newline at end of file diff --git a/test/simple_table_async/test.sh b/test/simple_table_async/test.sh index 220d311e..73e15b56 100755 --- a/test/simple_table_async/test.sh +++ b/test/simple_table_async/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run --features async -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel_async::pooled_connection::deadpool::Object" --async \ No newline at end of file +cargo run --features async --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel_async::pooled_connection::deadpool::Object" --async diff --git a/test/simple_table_custom_schema_path/test.sh b/test/simple_table_custom_schema_path/test.sh index 2c1cd11e..63d57bb4 100755 --- a/test/simple_table_custom_schema_path/test.sh +++ b/test/simple_table_custom_schema_path/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i data/schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --schema-path "crate::data::schema::" +cargo run --manifest-path ../../Cargo.toml -- \ +-i data/schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --schema-path "crate::data::schema::" diff --git a/test/simple_table_mysql/Cargo.toml b/test/simple_table_mysql/Cargo.toml new file mode 100644 index 00000000..1eeccd9a --- /dev/null +++ b/test/simple_table_mysql/Cargo.toml @@ -0,0 +1,17 @@ +[lib] +path = "lib.rs" + +[package] +name = "simple_table_mysql" +version = "0.1.0" +edition = "2021" + +[dependencies] +diesel = { version = "*", default-features = false, features = [ + "mysql", + "r2d2", + "chrono", +] } +r2d2.workspace = true +chrono.workspace = true +serde.workspace = true diff --git a/test/simple_table_mysql/lib.rs b/test/simple_table_mysql/lib.rs new file mode 100644 index 00000000..fdea3f51 --- /dev/null +++ b/test/simple_table_mysql/lib.rs @@ -0,0 +1,6 @@ +pub mod models; +pub mod schema; + +pub mod diesel { + pub use diesel::*; +} diff --git a/test/simple_table/models/mod.rs b/test/simple_table_mysql/models/mod.rs similarity index 100% rename from test/simple_table/models/mod.rs rename to test/simple_table_mysql/models/mod.rs diff --git a/test/simple_table_mysql/models/todos/generated.rs b/test/simple_table_mysql/models/todos/generated.rs new file mode 100644 index 00000000..5a8672b7 --- /dev/null +++ b/test/simple_table_mysql/models/todos/generated.rs @@ -0,0 +1,74 @@ +/* @generated and managed by dsync */ + +use crate::diesel::*; +use crate::schema::*; + +/// Struct representing a row in table `todos` +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)] +#[diesel(table_name=todos, primary_key(id))] +pub struct Todos { + /// Field representing column `id` + pub id: i32, + /// Field representing column `unsigned` + pub unsigned: u32, + /// Field representing column `unsigned_nullable` + pub unsigned_nullable: Option, + /// Field representing column `text` + pub text: String, + /// Field representing column `completed` + pub completed: bool, + /// Field representing column `type` + pub type_: String, + /// Field representing column `smallint` + pub smallint: i16, + /// Field representing column `bigint` + pub bigint: i64, + /// Field representing column `created_at` + pub created_at: chrono::NaiveDateTime, + /// Field representing column `updated_at` + pub updated_at: chrono::NaiveDateTime, +} + +/// Create Struct for a row in table `todos` for [`Todos`] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Insertable)] +#[diesel(table_name=todos)] +pub struct CreateTodos { + /// Field representing column `unsigned` + pub unsigned: u32, + /// Field representing column `unsigned_nullable` + pub unsigned_nullable: Option, + /// Field representing column `text` + pub text: String, + /// Field representing column `completed` + pub completed: bool, + /// Field representing column `type` + pub type_: String, + /// Field representing column `smallint` + pub smallint: i16, + /// Field representing column `bigint` + pub bigint: i64, +} + +/// Update Struct for a row in table `todos` for [`Todos`] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::AsChangeset, PartialEq, Default)] +#[diesel(table_name=todos)] +pub struct UpdateTodos { + /// Field representing column `unsigned` + pub unsigned: Option, + /// Field representing column `unsigned_nullable` + pub unsigned_nullable: Option>, + /// Field representing column `text` + pub text: Option, + /// Field representing column `completed` + pub completed: Option, + /// Field representing column `type` + pub type_: Option, + /// Field representing column `smallint` + pub smallint: Option, + /// Field representing column `bigint` + pub bigint: Option, + /// Field representing column `created_at` + pub created_at: Option, + /// Field representing column `updated_at` + pub updated_at: Option, +} diff --git a/test/simple_table/models/todos/mod.rs b/test/simple_table_mysql/models/todos/mod.rs similarity index 100% rename from test/simple_table/models/todos/mod.rs rename to test/simple_table_mysql/models/todos/mod.rs diff --git a/test/simple_table/schema.rs b/test/simple_table_mysql/schema.rs similarity index 71% rename from test/simple_table/schema.rs rename to test/simple_table_mysql/schema.rs index dc033baf..7084caba 100644 --- a/test/simple_table/schema.rs +++ b/test/simple_table_mysql/schema.rs @@ -8,7 +8,9 @@ diesel::table! { #[sql_name = "type"] #[max_length = 255] type_ -> Varchar, - created_at -> Timestamptz, - updated_at -> Timestamptz, + smallint -> Int2, + bigint -> Int8, + created_at -> Timestamp, + updated_at -> Timestamp, } } diff --git a/test/simple_table_mysql/test.sh b/test/simple_table_mysql/test.sh new file mode 100755 index 00000000..2e056cea --- /dev/null +++ b/test/simple_table_mysql/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +cd $SCRIPT_DIR + +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --no-crud diff --git a/test/simple_table_no_crud/test.sh b/test/simple_table_no_crud/test.sh index a450db07..95f57870 100755 --- a/test/simple_table_no_crud/test.sh +++ b/test/simple_table_no_crud/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --no-crud +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --no-crud diff --git a/test/simple_table_no_serde/test.sh b/test/simple_table_no_serde/test.sh index b1b94b9f..29ea2824 100755 --- a/test/simple_table_no_serde/test.sh +++ b/test/simple_table_no_serde/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --no-serde +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --no-serde diff --git a/test/simple_table_pg/Cargo.toml b/test/simple_table_pg/Cargo.toml new file mode 100644 index 00000000..d3ed3cfb --- /dev/null +++ b/test/simple_table_pg/Cargo.toml @@ -0,0 +1,17 @@ +[lib] +path = "lib.rs" + +[package] +name = "simple_table_pg" +version = "0.1.0" +edition = "2021" + +[dependencies] +diesel = { version = "*", default-features = false, features = [ + "postgres", + "r2d2", + "chrono", +] } +r2d2.workspace = true +chrono.workspace = true +serde.workspace = true diff --git a/test/simple_table_pg/lib.rs b/test/simple_table_pg/lib.rs new file mode 100644 index 00000000..fdea3f51 --- /dev/null +++ b/test/simple_table_pg/lib.rs @@ -0,0 +1,6 @@ +pub mod models; +pub mod schema; + +pub mod diesel { + pub use diesel::*; +} diff --git a/test/simple_table_pg/models/mod.rs b/test/simple_table_pg/models/mod.rs new file mode 100644 index 00000000..015a6a2b --- /dev/null +++ b/test/simple_table_pg/models/mod.rs @@ -0,0 +1 @@ +pub mod todos; diff --git a/test/simple_table/models/todos/generated.rs b/test/simple_table_pg/models/todos/generated.rs similarity index 86% rename from test/simple_table/models/todos/generated.rs rename to test/simple_table_pg/models/todos/generated.rs index 64aa5752..2e777ec2 100644 --- a/test/simple_table/models/todos/generated.rs +++ b/test/simple_table_pg/models/todos/generated.rs @@ -11,56 +11,56 @@ pub type ConnectionType = diesel::r2d2::PooledConnection, /// Field representing column `text` pub text: String, /// Field representing column `completed` pub completed: bool, /// Field representing column `type` pub type_: String, + /// Field representing column `smallint` + pub smallint: i16, + /// Field representing column `bigint` + pub bigint: i64, /// Field representing column `created_at` pub created_at: chrono::DateTime, /// Field representing column `updated_at` - pub updated_at: chrono::DateTime, + pub updated_at: chrono::NaiveDateTime, } /// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { - /// Field representing column `unsigned` - pub unsigned: u32, - /// Field representing column `unsigned_nullable` - pub unsigned_nullable: Option, /// Field representing column `text` pub text: String, /// Field representing column `completed` pub completed: bool, /// Field representing column `type` pub type_: String, + /// Field representing column `smallint` + pub smallint: i16, + /// Field representing column `bigint` + pub bigint: i64, } /// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::AsChangeset, PartialEq, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { - /// Field representing column `unsigned` - pub unsigned: Option, - /// Field representing column `unsigned_nullable` - pub unsigned_nullable: Option>, /// Field representing column `text` pub text: Option, /// Field representing column `completed` pub completed: Option, /// Field representing column `type` pub type_: Option, + /// Field representing column `smallint` + pub smallint: Option, + /// Field representing column `bigint` + pub bigint: Option, /// Field representing column `created_at` pub created_at: Option>, /// Field representing column `updated_at` - pub updated_at: Option>, + pub updated_at: Option, } /// Result of a `.paginate` function diff --git a/test/simple_table_pg/models/todos/mod.rs b/test/simple_table_pg/models/todos/mod.rs new file mode 100644 index 00000000..a5bb9b90 --- /dev/null +++ b/test/simple_table_pg/models/todos/mod.rs @@ -0,0 +1,2 @@ +pub use generated::*; +pub mod generated; diff --git a/test/simple_table_pg/schema.rs b/test/simple_table_pg/schema.rs new file mode 100644 index 00000000..c66e8219 --- /dev/null +++ b/test/simple_table_pg/schema.rs @@ -0,0 +1,14 @@ +diesel::table! { + todos (id) { + id -> Int4, + text -> Text, + completed -> Bool, + #[sql_name = "type"] + #[max_length = 255] + type_ -> Varchar, + smallint -> Int2, + bigint -> Int8, + created_at -> Timestamptz, + updated_at -> Timestamp, + } +} diff --git a/test/simple_table_pg/test.sh b/test/simple_table_pg/test.sh new file mode 100755 index 00000000..7af45024 --- /dev/null +++ b/test/simple_table_pg/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +cd $SCRIPT_DIR + +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" diff --git a/test/simple_table_sqlite/Cargo.toml b/test/simple_table_sqlite/Cargo.toml new file mode 100644 index 00000000..6f29b3cb --- /dev/null +++ b/test/simple_table_sqlite/Cargo.toml @@ -0,0 +1,18 @@ +[lib] +path = "lib.rs" + +[package] +name = "simple_table_sqlite" +version = "0.1.0" +edition = "2021" + +[dependencies] +diesel = { version = "*", default-features = false, features = [ + "sqlite", + "r2d2", + "chrono", + "returning_clauses_for_sqlite_3_35", +] } +r2d2.workspace = true +chrono.workspace = true +serde.workspace = true diff --git a/test/simple_table_sqlite/lib.rs b/test/simple_table_sqlite/lib.rs new file mode 100644 index 00000000..fdea3f51 --- /dev/null +++ b/test/simple_table_sqlite/lib.rs @@ -0,0 +1,6 @@ +pub mod models; +pub mod schema; + +pub mod diesel { + pub use diesel::*; +} diff --git a/test/simple_table_sqlite/models/mod.rs b/test/simple_table_sqlite/models/mod.rs new file mode 100644 index 00000000..015a6a2b --- /dev/null +++ b/test/simple_table_sqlite/models/mod.rs @@ -0,0 +1 @@ +pub mod todos; diff --git a/test/simple_table_sqlite/models/todos/generated.rs b/test/simple_table_sqlite/models/todos/generated.rs new file mode 100644 index 00000000..7d596a5f --- /dev/null +++ b/test/simple_table_sqlite/models/todos/generated.rs @@ -0,0 +1,109 @@ +/* @generated and managed by dsync */ + +use crate::diesel::*; +use crate::schema::*; + +pub type ConnectionType = diesel::r2d2::PooledConnection>; + +/// Struct representing a row in table `todos` +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Queryable, diesel::Selectable, diesel::QueryableByName)] +#[diesel(table_name=todos, primary_key(id))] +pub struct Todos { + /// Field representing column `id` + pub id: i32, + /// Field representing column `text` + pub text: String, + /// Field representing column `completed` + pub completed: bool, + /// Field representing column `type` + pub type_: String, + /// Field representing column `smallint` + pub smallint: i16, + /// Field representing column `bigint` + pub bigint: i64, + /// Field representing column `created_at` + pub created_at: chrono::NaiveDateTime, + /// Field representing column `updated_at` + pub updated_at: chrono::NaiveDateTime, +} + +/// Create Struct for a row in table `todos` for [`Todos`] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Insertable)] +#[diesel(table_name=todos)] +pub struct CreateTodos { + /// Field representing column `text` + pub text: String, + /// Field representing column `completed` + pub completed: bool, + /// Field representing column `type` + pub type_: String, + /// Field representing column `smallint` + pub smallint: i16, + /// Field representing column `bigint` + pub bigint: i64, +} + +/// Update Struct for a row in table `todos` for [`Todos`] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::AsChangeset, PartialEq, Default)] +#[diesel(table_name=todos)] +pub struct UpdateTodos { + /// Field representing column `text` + pub text: Option, + /// Field representing column `completed` + pub completed: Option, + /// Field representing column `type` + pub type_: Option, + /// Field representing column `smallint` + pub smallint: Option, + /// Field representing column `bigint` + pub bigint: Option, + /// Field representing column `created_at` + pub created_at: Option, + /// Field representing column `updated_at` + pub updated_at: Option, +} + +/// Result of a `.paginate` function +#[derive(Debug, serde::Serialize)] +pub struct PaginationResult { + /// Resulting items that are from the current page + pub items: Vec, + /// The count of total items there are + pub total_items: i64, + /// Current page, 0-based index + pub page: i64, + /// Size of a page + pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` + pub num_pages: i64, +} + +impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] + pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> diesel::QueryResult { + use crate::schema::todos::dsl::*; + + diesel::insert_into(todos).values(item).get_result::(db) + } + + /// Get a row from `todos`, identified by the primary key + pub fn read(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult { + use crate::schema::todos::dsl::*; + + todos.filter(id.eq(param_id)).first::(db) + } + + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] + pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> diesel::QueryResult { + use crate::schema::todos::dsl::*; + + diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db) + } + + /// Delete a row in `todos`, identified by the primary key + pub fn delete(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult { + use crate::schema::todos::dsl::*; + + diesel::delete(todos.filter(id.eq(param_id))).execute(db) + } +} diff --git a/test/simple_table_sqlite/models/todos/mod.rs b/test/simple_table_sqlite/models/todos/mod.rs new file mode 100644 index 00000000..a5bb9b90 --- /dev/null +++ b/test/simple_table_sqlite/models/todos/mod.rs @@ -0,0 +1,2 @@ +pub use generated::*; +pub mod generated; diff --git a/test/simple_table_sqlite/schema.rs b/test/simple_table_sqlite/schema.rs new file mode 100644 index 00000000..c91a5c4f --- /dev/null +++ b/test/simple_table_sqlite/schema.rs @@ -0,0 +1,16 @@ +diesel::table! { + todos (id) { + id -> Int4, + // unsigned -> Unsigned, + // unsigned_nullable -> Nullable>, + text -> Text, + completed -> Bool, + #[sql_name = "type"] + #[max_length = 255] + type_ -> Varchar, + smallint -> Int2, + bigint -> Int8, + created_at -> Timestamp, + updated_at -> Timestamp, + } +} diff --git a/test/simple_table_sqlite/test.sh b/test/simple_table_sqlite/test.sh new file mode 100755 index 00000000..0953e7d7 --- /dev/null +++ b/test/simple_table_sqlite/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +cd $SCRIPT_DIR + +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" diff --git a/test/single_model_file/Cargo.toml b/test/single_model_file/Cargo.toml new file mode 100644 index 00000000..8d213c01 --- /dev/null +++ b/test/single_model_file/Cargo.toml @@ -0,0 +1,15 @@ +[lib] +path = "lib.rs" + +[package] +name = "single_model_file" +version = "0.1.0" +edition = "2021" + +[dependencies] +diesel = { version = "*", default-features = false, features = [ + "postgres", + "chrono", +] } +chrono.workspace = true +serde.workspace = true diff --git a/test/single_model_file/lib.rs b/test/single_model_file/lib.rs new file mode 100644 index 00000000..fdea3f51 --- /dev/null +++ b/test/single_model_file/lib.rs @@ -0,0 +1,6 @@ +pub mod models; +pub mod schema; + +pub mod diesel { + pub use diesel::*; +} diff --git a/test/single_model_file/test.sh b/test/single_model_file/test.sh index aaf327ad..3c53ff7d 100755 --- a/test/single_model_file/test.sh +++ b/test/single_model_file/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --single-model-file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -g id -g created_at -g updated_at -c "diesel::r2d2::PooledConnection>" --single-model-file diff --git a/test/test_all.sh b/test/test_all.sh index 21a8029b..ece659d3 100755 --- a/test/test_all.sh +++ b/test/test_all.sh @@ -1,5 +1,7 @@ #!/bin/bash +# This script is to run "dsync" generation on all test-cases + # fail on non-0 exit codes, which makes it more obvious if a test has failed set -e @@ -7,11 +9,11 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -for D in *; do - if [ -d "${D}" ]; then - echo "Testing $D" - ${D}/test.sh - # output separator - echo "" - fi -done +echo "Testing Generation" +./test_generate.sh + +# extra separator +echo "" + +echo "Testing Compiliation" +./test_compile.sh diff --git a/test/test_compile.sh b/test/test_compile.sh new file mode 100755 index 00000000..a61ddcd3 --- /dev/null +++ b/test/test_compile.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# This script is to compile all compile-able tests to see if they are correct + +# fail on non-0 exit codes, which makes it more obvious if a test has failed +set -e + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +cd $SCRIPT_DIR + +cargo build --all diff --git a/test/test_generate.sh b/test/test_generate.sh new file mode 100755 index 00000000..40780efd --- /dev/null +++ b/test/test_generate.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# fail on non-0 exit codes, which makes it more obvious if a test has failed +set -e + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +cd $SCRIPT_DIR + +for D in *; do + # ignore the test's "target" directory + if [ -d "${D}" ] && [ "${D}" != "target" ]; then + echo "Testing $D" + ${D}/test.sh + # output separator + echo "" + fi +done diff --git a/test/use_statements/test.sh b/test/use_statements/test.sh index d49cdd23..87b5d7e8 100755 --- a/test/use_statements/test.sh +++ b/test/use_statements/test.sh @@ -4,4 +4,5 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" cd $SCRIPT_DIR -cargo run -- -i schema.rs -o models -c "diesel::r2d2::PooledConnection>" \ No newline at end of file +cargo run --manifest-path ../../Cargo.toml -- \ +-i schema.rs -o models -c "diesel::r2d2::PooledConnection>" \ No newline at end of file