From 0bdd5479ff4cc7e63b3b8f732f7cb0586458fef8 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 7 Jul 2024 02:01:13 +0100 Subject: [PATCH] refactor: use confik instead of config --- .vscode/settings.json | 1 + Cargo.lock | 484 ++++++++++------------------ Cargo.toml | 4 +- databases/postgres/Cargo.toml | 4 +- databases/postgres/src/config.rs | 23 ++ databases/postgres/src/db.rs | 42 +++ databases/postgres/src/errors.rs | 25 ++ databases/postgres/src/main.rs | 167 ++-------- databases/postgres/src/models.rs | 11 + databases/redis/Cargo.toml | 5 +- databases/sea-orm/README.md | 8 +- databases/sqlite/Cargo.toml | 16 +- graphql/juniper-advanced/Cargo.toml | 5 +- graphql/juniper/Cargo.toml | 4 +- 14 files changed, 322 insertions(+), 477 deletions(-) create mode 100644 databases/postgres/src/config.rs create mode 100644 databases/postgres/src/db.rs create mode 100644 databases/postgres/src/errors.rs create mode 100644 databases/postgres/src/models.rs diff --git a/.vscode/settings.json b/.vscode/settings.json index 728be30..62fded6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "autoclean", "autoreload", "chrono", + "deadpool", "dotenv", "dotenvy", "graphiql", diff --git a/Cargo.lock b/Cargo.lock index 8b62c43..ed49ab8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ "parking_lot 0.12.3", "pem-rfc7468", "pkcs8 0.10.2", - "rand 0.8.5", + "rand", "reqwest 0.12.4", "serde", "serde_json", @@ -182,7 +182,7 @@ dependencies = [ "mime", "percent-encoding", "pin-project-lite 0.2.13", - "rand 0.8.5", + "rand", "sha1", "smallvec", "tokio 1.38.0", @@ -259,7 +259,7 @@ dependencies = [ "log", "memchr", "mime", - "rand 0.8.5", + "rand", "serde", "serde_json", "serde_plain", @@ -357,8 +357,8 @@ dependencies = [ "actix-web", "anyhow", "derive_more", - "rand 0.8.5", - "redis", + "rand", + "redis 0.24.0", "serde", "serde_json", "tracing", @@ -636,7 +636,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ - "getrandom 0.2.12", + "getrandom", "once_cell", "version_check", ] @@ -649,7 +649,7 @@ checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if 1.0.0", "const-random", - "getrandom 0.2.12", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -827,7 +827,7 @@ dependencies = [ "chrono", "futures", "log", - "redis", + "redis 0.24.0", "serde", "serde_json", "tokio 1.38.0", @@ -870,12 +870,6 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" -[[package]] -name = "ascii" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" - [[package]] name = "ascii_utils" version = "0.9.3" @@ -1086,21 +1080,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "async_pg" -version = "1.0.0" -dependencies = [ - "actix-web", - "config", - "deadpool-postgres", - "derive_more", - "dotenvy", - "serde", - "tokio-pg-mapper", - "tokio-pg-mapper-derive", - "tokio-postgres", -] - [[package]] name = "atoi" version = "2.0.0" @@ -1116,6 +1095,18 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba" +[[package]] +name = "auto_enums" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1899bfcfd9340ceea3533ea157360ba8fa864354eccbceab58e1006ecab35393" +dependencies = [ + "derive_utils 0.14.1", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -1149,7 +1140,7 @@ dependencies = [ "openssl", "percent-encoding", "pin-project-lite 0.2.13", - "rand 0.8.5", + "rand", "rustls 0.23.9", "serde", "serde_json", @@ -1275,7 +1266,7 @@ dependencies = [ "http 0.2.9", "percent-encoding", "tracing", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -1633,7 +1624,7 @@ dependencies = [ "dotenvy", "env_logger", "log", - "rand 0.8.5", + "rand", "serde", "tokio 1.38.0", "tokio-util 0.7.11", @@ -1874,23 +1865,6 @@ dependencies = [ "alloc-stdlib", ] -[[package]] -name = "bson" -version = "1.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0aa578035b938855a710ba58d43cfb4d435f3619f99236fb35922a574d6cb1" -dependencies = [ - "base64 0.13.1", - "chrono", - "hex", - "lazy_static", - "linked-hash-map", - "rand 0.7.3", - "serde", - "serde_json", - "uuid 0.8.2", -] - [[package]] name = "bson" version = "2.9.0" @@ -1904,12 +1878,12 @@ dependencies = [ "indexmap 2.1.0", "js-sys", "once_cell", - "rand 0.8.5", + "rand", "serde", "serde_bytes", "serde_json", "time", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -2208,19 +2182,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "combine" -version = "3.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" -dependencies = [ - "ascii", - "byteorder", - "either", - "memchr", - "unreachable", -] - [[package]] name = "combine" version = "4.6.6" @@ -2245,22 +2206,29 @@ dependencies = [ ] [[package]] -name = "config" -version = "0.13.4" +name = "confik" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23738e11972c7643e4ec947840fc463b6a571afcd3e735bdfce7d03c7a784aca" +checksum = "621e0282e2354dccefd421b94fed2be61dc5836836e0953ac0172bdfd9ce028a" dependencies = [ - "async-trait", - "json5", - "lazy_static", - "nom", - "pathdiff", - "ron", - "rust-ini", + "cfg-if 1.0.0", + "confik-macros", + "envious", "serde", - "serde_json", - "toml 0.5.11", - "yaml-rust", + "thiserror", + "toml 0.8.8", +] + +[[package]] +name = "confik-macros" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7705566cfbb6c788c882847b4b82f31ffc52413c87883544d629749a88ebd34" +dependencies = [ + "darling 0.20.3", + "proc-macro2", + "quote", + "syn 2.0.48", ] [[package]] @@ -2284,7 +2252,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" dependencies = [ - "getrandom 0.2.12", + "getrandom", "once_cell", "tiny-keccak", ] @@ -2312,7 +2280,7 @@ dependencies = [ "hkdf", "hmac", "percent-encoding", - "rand 0.8.5", + "rand", "sha2", "subtle", "time", @@ -2500,7 +2468,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" dependencies = [ "generic-array", - "rand_core 0.6.4", + "rand_core", "subtle", "zeroize", ] @@ -2512,7 +2480,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array", - "rand_core 0.6.4", + "rand_core", "subtle", "zeroize", ] @@ -2524,7 +2492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", - "rand_core 0.6.4", + "rand_core", "typenum", ] @@ -2647,6 +2615,21 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +[[package]] +name = "db-postgres" +version = "1.0.0" +dependencies = [ + "actix-web", + "confik", + "deadpool-postgres", + "derive_more", + "dotenvy", + "serde", + "tokio-pg-mapper", + "tokio-pg-mapper-derive", + "tokio-postgres", +] + [[package]] name = "db-redis" version = "1.0.0" @@ -2654,7 +2637,7 @@ dependencies = [ "actix-web", "env_logger", "log", - "redis", + "redis 0.25.4", "serde", ] @@ -2773,20 +2756,20 @@ dependencies = [ [[package]] name = "derive_utils" -version = "0.11.2" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532b4c15dccee12c7044f1fcad956e98410860b22231e44a3b827464797ca7bf" +checksum = "9abcad25e9720609ccb3dcdb795d845e37d8ce34183330a9f48b03a1a71c8e21" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] name = "derive_utils" -version = "0.13.2" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9abcad25e9720609ccb3dcdb795d845e37d8ce34183330a9f48b03a1a71c8e21" +checksum = "61bb5a1014ce6dfc2a378578509abe775a5aa06bff584a547555d9efdb81b926" dependencies = [ "proc-macro2", "quote", @@ -2814,7 +2797,7 @@ dependencies = [ "pq-sys", "r2d2", "time", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -2827,7 +2810,7 @@ dependencies = [ "env_logger", "log", "serde", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -2875,12 +2858,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "dlv-list" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" - [[package]] name = "docker_sample" version = "1.0.0" @@ -2971,7 +2948,7 @@ dependencies = [ "generic-array", "group 0.12.1", "pkcs8 0.9.0", - "rand_core 0.6.4", + "rand_core", "sec1 0.3.0", "subtle", "zeroize", @@ -2991,7 +2968,7 @@ dependencies = [ "group 0.13.0", "pem-rfc7468", "pkcs8 0.10.2", - "rand_core 0.6.4", + "rand_core", "sec1 0.7.3", "subtle", "zeroize", @@ -3041,6 +3018,16 @@ dependencies = [ "log", ] +[[package]] +name = "envious" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e52788a407588138195a40c991f500621fea2cffa87e7345d86dbab77287dc7" +dependencies = [ + "serde", + "thiserror", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -3065,7 +3052,7 @@ dependencies = [ "derive_more", "env_logger", "log", - "rand 0.8.5", + "rand", ] [[package]] @@ -3122,7 +3109,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" dependencies = [ - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -3132,7 +3119,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -3433,17 +3420,6 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" -[[package]] -name = "futures-enum" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3422d14de7903a52e9dbc10ae05a7e14445ec61890100e098754e120b2bd7b1e" -dependencies = [ - "derive_utils 0.11.2", - "quote", - "syn 1.0.109", -] - [[package]] name = "futures-executor" version = "0.3.29" @@ -3553,17 +3529,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.12" @@ -3572,7 +3537,7 @@ checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -3635,7 +3600,7 @@ dependencies = [ "nonzero_ext", "parking_lot 0.12.3", "quanta 0.11.1", - "rand 0.8.5", + "rand", "smallvec", ] @@ -3650,16 +3615,6 @@ dependencies = [ "tokio 1.38.0", ] -[[package]] -name = "graphql-parser" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1abd4ce5247dfc04a03ccde70f87a048458c9356c7e41d21ad8c407b3dde6f2" -dependencies = [ - "combine 3.8.1", - "thiserror", -] - [[package]] name = "group" version = "0.12.1" @@ -3667,7 +3622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" dependencies = [ "ff 0.12.1", - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -3678,7 +3633,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff 0.13.0", - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -4243,7 +4198,6 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", - "serde", ] [[package]] @@ -4430,17 +4384,6 @@ dependencies = [ "validator", ] -[[package]] -name = "json5" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1" -dependencies = [ - "pest", - "pest_derive", - "serde", -] - [[package]] name = "json_decode_error" version = "1.0.0" @@ -4477,24 +4420,19 @@ dependencies = [ [[package]] name = "juniper" -version = "0.15.12" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875dca5a0c08b1521e1bb0ed940e9955a9f38971008aaa2a9f64a2ac6b59e1b5" +checksum = "943306315b1a7a03d27af9dfb0c288d9f4da8830c17df4bceb7d50a47da0982c" dependencies = [ "async-trait", - "bson 1.2.4", - "chrono", + "auto_enums", "fnv", "futures", - "futures-enum", - "graphql-parser", - "indexmap 1.9.3", + "indexmap 2.1.0", "juniper_codegen", "serde", "smartstring", "static_assertions", - "url", - "uuid 0.8.2", ] [[package]] @@ -4511,7 +4449,7 @@ dependencies = [ "mysql 24.0.0", "r2d2", "r2d2_mysql", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -4528,14 +4466,14 @@ dependencies = [ [[package]] name = "juniper_codegen" -version = "0.15.9" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aee97671061ad50301ba077d054d295e01d31a1868fbd07902db651f987e71db" +checksum = "760dbe46660494d469023d661e8d268f413b2cb68c999975dcc237407096a693" dependencies = [ - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", + "url", ] [[package]] @@ -5041,7 +4979,7 @@ checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.48.0", ] @@ -5081,7 +5019,7 @@ dependencies = [ "async-trait", "base64 0.13.1", "bitflags 1.3.2", - "bson 2.9.0", + "bson", "chrono", "derivative", "derive_more", @@ -5095,7 +5033,7 @@ dependencies = [ "md-5", "pbkdf2", "percent-encoding", - "rand 0.8.5", + "rand", "rustc_version_runtime", "rustls 0.21.12", "rustls-pemfile 1.0.4", @@ -5115,7 +5053,7 @@ dependencies = [ "trust-dns-proto", "trust-dns-resolver", "typed-builder", - "uuid 1.8.0", + "uuid", "webpki-roots 0.25.4", ] @@ -5147,7 +5085,7 @@ dependencies = [ "futures-util", "log", "sanitize-filename", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -5255,7 +5193,7 @@ dependencies = [ "mysql-common-derive", "num-bigint", "num-traits", - "rand 0.8.5", + "rand", "regex", "rust_decimal", "saturating", @@ -5267,7 +5205,7 @@ dependencies = [ "subprocess", "thiserror", "time", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -5415,7 +5353,7 @@ dependencies = [ "num-integer", "num-iter", "num-traits", - "rand 0.8.5", + "rand", "smallvec", "zeroize", ] @@ -5592,7 +5530,7 @@ dependencies = [ "opentelemetry", "ordered-float", "percent-encoding", - "rand 0.8.5", + "rand", "thiserror", "tokio 1.38.0", "tokio-stream", @@ -5607,16 +5545,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "ordered-multimap" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" -dependencies = [ - "dlv-list", - "hashbrown 0.12.3", -] - [[package]] name = "outref" version = "0.5.1" @@ -5733,12 +5661,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "pathdiff" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" - [[package]] name = "pbkdf2" version = "0.11.0" @@ -5863,7 +5785,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" dependencies = [ "phf_shared 0.10.0", - "rand 0.8.5", + "rand", ] [[package]] @@ -5873,7 +5795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ "phf_shared 0.11.2", - "rand 0.8.5", + "rand", ] [[package]] @@ -6000,7 +5922,7 @@ dependencies = [ "hmac", "md-5", "memchr", - "rand 0.8.5", + "rand", "sha2", "stringprep", ] @@ -6195,7 +6117,7 @@ dependencies = [ "mach2", "once_cell", "raw-cpuid 10.7.0", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "web-sys", "winapi 0.3.9", ] @@ -6210,7 +6132,7 @@ dependencies = [ "libc", "once_cell", "raw-cpuid 11.0.2", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "web-sys", "winapi 0.3.9", ] @@ -6257,19 +6179,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", -] - [[package]] name = "rand" version = "0.8.5" @@ -6277,18 +6186,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", ] [[package]] @@ -6298,16 +6197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", + "rand_core", ] [[package]] @@ -6316,16 +6206,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.12", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "getrandom", ] [[package]] @@ -6355,7 +6236,7 @@ dependencies = [ "arc-swap", "async-trait", "bytes 1.6.0", - "combine 4.6.6", + "combine", "futures", "futures-util", "itoa 1.0.9", @@ -6369,6 +6250,30 @@ dependencies = [ "url", ] +[[package]] +name = "redis" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0d7a6955c7511f60f3ba9e86c6d02b3c3f144f8c24b288d1f4e18074ab8bbec" +dependencies = [ + "arc-swap", + "async-trait", + "bytes 1.6.0", + "combine", + "futures", + "futures-util", + "itoa 1.0.9", + "percent-encoding", + "pin-project-lite 0.2.13", + "ryu", + "sha1_smol", + "socket2 0.5.5", + "tokio 1.38.0", + "tokio-retry", + "tokio-util 0.7.11", + "url", +] + [[package]] name = "redis-session-example" version = "1.0.0" @@ -6654,7 +6559,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" dependencies = [ "cc", - "getrandom 0.2.12", + "getrandom", "libc", "spin 0.9.8", "untrusted", @@ -6685,7 +6590,7 @@ dependencies = [ "rkyv_derive", "seahash", "tinyvec", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -6699,17 +6604,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "ron" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" -dependencies = [ - "base64 0.13.1", - "bitflags 1.3.2", - "serde", -] - [[package]] name = "rsa" version = "0.9.3" @@ -6723,7 +6617,7 @@ dependencies = [ "num-traits", "pkcs1", "pkcs8 0.10.2", - "rand_core 0.6.4", + "rand_core", "signature 2.1.0", "spki 0.7.3", "subtle", @@ -6750,16 +6644,6 @@ dependencies = [ "constant_time_eq", ] -[[package]] -name = "rust-ini" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" -dependencies = [ - "cfg-if 1.0.0", - "ordered-multimap", -] - [[package]] name = "rust_decimal" version = "1.32.0" @@ -6770,7 +6654,7 @@ dependencies = [ "borsh", "bytes 1.6.0", "num-traits", - "rand 0.8.5", + "rand", "rkyv", "serde", "serde_json", @@ -7369,7 +7253,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" dependencies = [ "digest", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -7379,7 +7263,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" dependencies = [ "digest", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -7408,7 +7292,7 @@ dependencies = [ "serde_json", "sparkpost", "time", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -7678,7 +7562,7 @@ dependencies = [ "memchr", "once_cell", "percent-encoding", - "rand 0.8.5", + "rand", "rsa", "serde", "sha1", @@ -7718,7 +7602,7 @@ dependencies = [ "md-5", "memchr", "once_cell", - "rand 0.8.5", + "rand", "serde", "serde_json", "sha2", @@ -8058,7 +7942,7 @@ dependencies = [ "percent-encoding", "pest", "pest_derive", - "rand 0.8.5", + "rand", "regex", "serde", "serde_json", @@ -8360,7 +8244,7 @@ dependencies = [ "pin-project-lite 0.2.13", "postgres-protocol", "postgres-types", - "rand 0.8.5", + "rand", "socket2 0.5.5", "tokio 1.38.0", "tokio-util 0.7.11", @@ -8374,7 +8258,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" dependencies = [ "pin-project", - "rand 0.8.5", + "rand", "tokio 1.38.0", ] @@ -8556,7 +8440,7 @@ dependencies = [ "indexmap 1.9.3", "pin-project", "pin-project-lite 0.2.13", - "rand 0.8.5", + "rand", "slab", "tokio 1.38.0", "tokio-util 0.7.11", @@ -8601,7 +8485,7 @@ dependencies = [ "pin-project", "tracing", "tracing-opentelemetry", - "uuid 1.8.0", + "uuid", ] [[package]] @@ -8771,7 +8655,7 @@ dependencies = [ "ipnet", "lazy_static", "log", - "rand 0.8.5", + "rand", "smallvec", "thiserror", "tinyvec", @@ -8812,7 +8696,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if 1.0.0", - "rand 0.8.5", + "rand", "static_assertions", ] @@ -8854,7 +8738,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e37c4b6cbcc59a8dcd09a6429fbc7890286bcbb79215cea7b38a3c4c0921d93" dependencies = [ - "rand 0.8.5", + "rand", ] [[package]] @@ -9023,15 +8907,6 @@ dependencies = [ "log", ] -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -dependencies = [ - "void", -] - [[package]] name = "untrusted" version = "0.9.0" @@ -9067,12 +8942,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" - [[package]] name = "uuid" version = "1.8.0" @@ -9080,7 +8949,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" dependencies = [ "atomic", - "getrandom 0.2.12", + "getrandom", "serde", ] @@ -9151,12 +9020,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "vsimd" version = "0.8.0" @@ -9182,12 +9045,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -9353,7 +9210,7 @@ dependencies = [ "env_logger", "futures-util", "log", - "rand 0.8.5", + "rand", "tokio 1.38.0", ] @@ -9368,7 +9225,7 @@ dependencies = [ "actix-web-actors", "env_logger", "log", - "rand 0.8.5", + "rand", ] [[package]] @@ -9394,7 +9251,7 @@ dependencies = [ "actix-web-actors", "env_logger", "log", - "rand 0.8.5", + "rand", ] [[package]] @@ -9410,7 +9267,7 @@ dependencies = [ "env_logger", "futures-util", "log", - "rand 0.8.5", + "rand", "serde", "serde_json", "tokio 1.38.0", @@ -9765,15 +9622,6 @@ version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] - [[package]] name = "yansi-term" version = "0.1.2" diff --git a/Cargo.toml b/Cargo.toml index 0c0498e..8827111 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ members = [ "databases/mysql", "databases/postgres", "databases/redis", - # "databases/sqlite", "docker", "forms/form", "forms/multipart-s3", @@ -69,6 +68,9 @@ members = [ "websockets/echo-actorless", "websockets/echo", ] +exclude = [ + "databases/sqlite", +] [workspace.package] publish = false diff --git a/databases/postgres/Cargo.toml b/databases/postgres/Cargo.toml index 3fab108..6727cd6 100644 --- a/databases/postgres/Cargo.toml +++ b/databases/postgres/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "async_pg" +name = "db-postgres" version = "1.0.0" edition = "2021" [dependencies] actix-web.workspace = true -config = "0.13" +confik = "0.11" deadpool-postgres = { version = "0.12", features = ["serde"] } derive_more.workspace = true dotenvy.workspace = true diff --git a/databases/postgres/src/config.rs b/databases/postgres/src/config.rs new file mode 100644 index 0000000..87456be --- /dev/null +++ b/databases/postgres/src/config.rs @@ -0,0 +1,23 @@ +use confik::Configuration; +use serde::Deserialize; + +#[derive(Debug, Default, Configuration)] +pub struct ExampleConfig { + pub server_addr: String, + #[confik(from = DbConfig)] + pub pg: deadpool_postgres::Config, +} + +#[derive(Debug, Deserialize)] +#[serde(transparent)] +struct DbConfig(deadpool_postgres::Config); + +impl From for deadpool_postgres::Config { + fn from(value: DbConfig) -> Self { + value.0 + } +} + +impl confik::Configuration for DbConfig { + type Builder = Option; +} diff --git a/databases/postgres/src/db.rs b/databases/postgres/src/db.rs new file mode 100644 index 0000000..0b15b06 --- /dev/null +++ b/databases/postgres/src/db.rs @@ -0,0 +1,42 @@ +use deadpool_postgres::Client; +use tokio_pg_mapper::FromTokioPostgresRow; + +use crate::{errors::MyError, models::User}; + +pub async fn get_users(client: &Client) -> Result, MyError> { + let stmt = include_str!("../sql/get_users.sql"); + let stmt = stmt.replace("$table_fields", &User::sql_table_fields()); + let stmt = client.prepare(&stmt).await.unwrap(); + + let results = client + .query(&stmt, &[]) + .await? + .iter() + .map(|row| User::from_row_ref(row).unwrap()) + .collect::>(); + + Ok(results) +} + +pub async fn add_user(client: &Client, user_info: User) -> Result { + let _stmt = include_str!("../sql/add_user.sql"); + let _stmt = _stmt.replace("$table_fields", &User::sql_table_fields()); + let stmt = client.prepare(&_stmt).await.unwrap(); + + client + .query( + &stmt, + &[ + &user_info.email, + &user_info.first_name, + &user_info.last_name, + &user_info.username, + ], + ) + .await? + .iter() + .map(|row| User::from_row_ref(row).unwrap()) + .collect::>() + .pop() + .ok_or(MyError::NotFound) // more applicable for SELECTs +} diff --git a/databases/postgres/src/errors.rs b/databases/postgres/src/errors.rs new file mode 100644 index 0000000..0d1bef7 --- /dev/null +++ b/databases/postgres/src/errors.rs @@ -0,0 +1,25 @@ +use actix_web::{HttpResponse, ResponseError}; +use deadpool_postgres::PoolError; +use derive_more::{Display, Error, From}; +use tokio_pg_mapper::Error as PGMError; +use tokio_postgres::error::Error as PGError; + +#[derive(Debug, Display, Error, From)] +pub enum MyError { + NotFound, + PGError(PGError), + PGMError(PGMError), + PoolError(PoolError), +} + +impl ResponseError for MyError { + fn error_response(&self) -> HttpResponse { + match *self { + MyError::NotFound => HttpResponse::NotFound().finish(), + MyError::PoolError(ref err) => { + HttpResponse::InternalServerError().body(err.to_string()) + } + _ => HttpResponse::InternalServerError().finish(), + } + } +} diff --git a/databases/postgres/src/main.rs b/databases/postgres/src/main.rs index de0b334..43aa06b 100644 --- a/databases/postgres/src/main.rs +++ b/databases/postgres/src/main.rs @@ -1,147 +1,48 @@ -mod config { - use serde::Deserialize; - #[derive(Debug, Default, Deserialize)] - pub struct ExampleConfig { - pub server_addr: String, - pub pg: deadpool_postgres::Config, - } -} - -mod models { - use serde::{Deserialize, Serialize}; - use tokio_pg_mapper_derive::PostgresMapper; - - #[derive(Deserialize, PostgresMapper, Serialize)] - #[pg_mapper(table = "users")] // singular 'user' is a keyword.. - pub struct User { - pub email: String, - pub first_name: String, - pub last_name: String, - pub username: String, - } -} - -mod errors { - use actix_web::{HttpResponse, ResponseError}; - use deadpool_postgres::PoolError; - use derive_more::{Display, From}; - use tokio_pg_mapper::Error as PGMError; - use tokio_postgres::error::Error as PGError; - - #[derive(Display, From, Debug)] - pub enum MyError { - NotFound, - PGError(PGError), - PGMError(PGMError), - PoolError(PoolError), - } - impl std::error::Error for MyError {} - - impl ResponseError for MyError { - fn error_response(&self) -> HttpResponse { - match *self { - MyError::NotFound => HttpResponse::NotFound().finish(), - MyError::PoolError(ref err) => { - HttpResponse::InternalServerError().body(err.to_string()) - } - _ => HttpResponse::InternalServerError().finish(), - } - } - } -} - -mod db { - use deadpool_postgres::Client; - use tokio_pg_mapper::FromTokioPostgresRow; - - use crate::{errors::MyError, models::User}; - - pub async fn get_users(client: &Client) -> Result, MyError> { - let stmt = include_str!("../sql/get_users.sql"); - let stmt = stmt.replace("$table_fields", &User::sql_table_fields()); - let stmt = client.prepare(&stmt).await.unwrap(); - - let results = client - .query(&stmt, &[]) - .await? - .iter() - .map(|row| User::from_row_ref(row).unwrap()) - .collect::>(); - - Ok(results) - } - - pub async fn add_user(client: &Client, user_info: User) -> Result { - let _stmt = include_str!("../sql/add_user.sql"); - let _stmt = _stmt.replace("$table_fields", &User::sql_table_fields()); - let stmt = client.prepare(&_stmt).await.unwrap(); - - client - .query( - &stmt, - &[ - &user_info.email, - &user_info.first_name, - &user_info.last_name, - &user_info.username, - ], - ) - .await? - .iter() - .map(|row| User::from_row_ref(row).unwrap()) - .collect::>() - .pop() - .ok_or(MyError::NotFound) // more applicable for SELECTs - } -} - -mod handlers { - use actix_web::{web, Error, HttpResponse}; - use deadpool_postgres::{Client, Pool}; - - use crate::{db, errors::MyError, models::User}; - - pub async fn get_users(db_pool: web::Data) -> Result { - let client: Client = db_pool.get().await.map_err(MyError::PoolError)?; - - let users = db::get_users(&client).await?; - - Ok(HttpResponse::Ok().json(users)) - } - - pub async fn add_user( - user: web::Json, - db_pool: web::Data, - ) -> Result { - let user_info: User = user.into_inner(); - - let client: Client = db_pool.get().await.map_err(MyError::PoolError)?; - - let new_user = db::add_user(&client, user_info).await?; - - Ok(HttpResponse::Ok().json(new_user)) - } -} - -use ::config::Config; -use actix_web::{web, App, HttpServer}; +use actix_web::{web, App, Error, HttpResponse, HttpServer}; +use confik::{Configuration as _, EnvSource}; +use deadpool_postgres::{Client, Pool}; use dotenvy::dotenv; -use handlers::{add_user, get_users}; use tokio_postgres::NoTls; use crate::config::ExampleConfig; +mod config; +mod db; +mod errors; +mod models; + +use self::{errors::MyError, models::User}; + +pub async fn get_users(db_pool: web::Data) -> Result { + let client: Client = db_pool.get().await.map_err(MyError::PoolError)?; + + let users = db::get_users(&client).await?; + + Ok(HttpResponse::Ok().json(users)) +} + +pub async fn add_user( + user: web::Json, + db_pool: web::Data, +) -> Result { + let user_info: User = user.into_inner(); + + let client: Client = db_pool.get().await.map_err(MyError::PoolError)?; + + let new_user = db::add_user(&client, user_info).await?; + + Ok(HttpResponse::Ok().json(new_user)) +} + #[actix_web::main] async fn main() -> std::io::Result<()> { dotenv().ok(); - let config_ = Config::builder() - .add_source(::config::Environment::default()) - .build() + let config = ExampleConfig::builder() + .override_with(EnvSource::new()) + .try_build() .unwrap(); - let config: ExampleConfig = config_.try_deserialize().unwrap(); - let pool = config.pg.create_pool(None, NoTls).unwrap(); let server = HttpServer::new(move || { diff --git a/databases/postgres/src/models.rs b/databases/postgres/src/models.rs new file mode 100644 index 0000000..35f1e83 --- /dev/null +++ b/databases/postgres/src/models.rs @@ -0,0 +1,11 @@ +use serde::{Deserialize, Serialize}; +use tokio_pg_mapper_derive::PostgresMapper; + +#[derive(Deserialize, PostgresMapper, Serialize)] +#[pg_mapper(table = "users")] // singular 'user' is a keyword.. +pub struct User { + pub email: String, + pub first_name: String, + pub last_name: String, + pub username: String, +} diff --git a/databases/redis/Cargo.toml b/databases/redis/Cargo.toml index 3bf96d4..14c7ce1 100644 --- a/databases/redis/Cargo.toml +++ b/databases/redis/Cargo.toml @@ -8,8 +8,5 @@ actix-web.workspace = true env_logger.workspace = true log.workspace = true -redis = { version = "0.24", default-features = false, features = [ - "tokio-comp", - "connection-manager", -] } +redis = { version = "0.25", features = ["tokio-comp", "connection-manager"] } serde.workspace = true diff --git a/databases/sea-orm/README.md b/databases/sea-orm/README.md index 8482edf..f2c88c6 100644 --- a/databases/sea-orm/README.md +++ b/databases/sea-orm/README.md @@ -1,5 +1,5 @@ -# [SeaORM](https://github.com/SeaQL/sea-orm) +# [SeaORM](https://github.com/SeaQL/sea-orm) -You can find the SeaORM with Actix 4 example in the [sea-orm/examples/actix_example/](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example) - -And with the Actix 3 here: [sea-orm/examples/actix3_example/](https://github.com/SeaQL/sea-orm/tree/master/examples/actix3_example) \ No newline at end of file +You can find the SeaORM with Actix 4 example in the [sea-orm/examples/actix_example/](https://github.com/SeaQL/sea-orm/tree/master/examples/actix_example) + +And with the Actix 3 here: [sea-orm/examples/actix3_example/](https://github.com/SeaQL/sea-orm/tree/master/examples/actix3_example) diff --git a/databases/sqlite/Cargo.toml b/databases/sqlite/Cargo.toml index a3bf530..ceca265 100644 --- a/databases/sqlite/Cargo.toml +++ b/databases/sqlite/Cargo.toml @@ -3,13 +3,13 @@ name = "db-sqlite" version = "1.0.0" edition = "2021" +# Do not use workspace deps as they this package isn't part of the workspace. [dependencies] -actix-web.workspace = true - -env_logger.workspace = true -futures-util.workspace = true -log.workspace = true +actix-web = "4" +env_logger = "0.11" +futures-util = { version = "0.3.17", default-features = false, features = ["std"] } +log = "0.4" r2d2 = "0.8" -r2d2_sqlite = "0.22" -rusqlite = "0.29" -serde.workspace = true +r2d2_sqlite = "0.24" +rusqlite = "0.31" +serde = { version = "1", features = ["derive"] } diff --git a/graphql/juniper-advanced/Cargo.toml b/graphql/juniper-advanced/Cargo.toml index e24588b..e31efdc 100644 --- a/graphql/juniper-advanced/Cargo.toml +++ b/graphql/juniper-advanced/Cargo.toml @@ -7,13 +7,10 @@ edition = "2021" actix-web.workspace = true actix-web-lab.workspace = true actix-cors.workspace = true - -juniper = "0.15.10" - +juniper = "0.16" mysql = "24" r2d2 = "0.8" r2d2_mysql = "24" - dotenvy.workspace = true env_logger.workspace = true log.workspace = true diff --git a/graphql/juniper/Cargo.toml b/graphql/juniper/Cargo.toml index ad9d825..f98367f 100644 --- a/graphql/juniper/Cargo.toml +++ b/graphql/juniper/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" actix-web.workspace = true actix-web-lab.workspace = true actix-cors.workspace = true - -juniper = "0.15.10" - +juniper = "0.16" env_logger.workspace = true log.workspace = true