From be4898fe4d6a68b616a8bac9a74fe2a456c084bd Mon Sep 17 00:00:00 2001 From: Nicolas del Valle Date: Sun, 14 Jul 2024 13:10:37 +0800 Subject: [PATCH] Add migrations and entity models --- Cargo.lock | 1710 ++++++++++++----- Cargo.toml | 11 +- config/default.json | 6 +- config/production.json | 3 +- config/test.json | 5 +- entity/src/entities/cat.rs | 34 +- entity/src/entities/user.rs | 26 +- entity/src/lib.rs | 4 +- .../m20240527_080925_create_users_table.rs | 80 +- .../src/m20240530_082146_create_cats_table.rs | 82 +- src/database.rs | 30 +- src/errors.rs | 5 + src/main.rs | 17 +- src/models/cat.rs | 117 +- src/routes/cat.rs | 182 +- src/utils/entity.rs | 95 + src/utils/mod.rs | 1 + src/utils/models.rs | 202 -- 18 files changed, 1677 insertions(+), 933 deletions(-) create mode 100644 src/utils/entity.rs delete mode 100644 src/utils/models.rs diff --git a/Cargo.lock b/Cargo.lock index 4a33249..4724bbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,16 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "Inflector" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" -dependencies = [ - "lazy_static", - "regex", -] - [[package]] name = "addr2line" version = "0.20.0" @@ -29,14 +19,26 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.3" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "ahash" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -48,6 +50,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "aliasable" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" + [[package]] name = "alloc-no-stdlib" version = "2.0.4" @@ -63,6 +71,12 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -78,6 +92,61 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "assert-json-diff" version = "2.0.2" @@ -101,6 +170,28 @@ dependencies = [ "tokio", ] +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "async-trait" version = "0.1.80" @@ -112,6 +203,15 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -201,6 +301,12 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bcrypt" version = "0.15.1" @@ -214,6 +320,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "bigdecimal" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -260,6 +377,30 @@ dependencies = [ "cipher", ] +[[package]] +name = "borsh" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" +dependencies = [ + "borsh-derive", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.48", + "syn_derive", +] + [[package]] name = "brotli" version = "3.3.4" @@ -287,7 +428,7 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d43b38e074cc0de2957f10947e376a1d88b9c4dbab340b590800cc1b2e066b2" dependencies = [ - "ahash", + "ahash 0.8.11", "base64 0.13.1", "bitvec", "chrono", @@ -310,6 +451,28 @@ version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +[[package]] +name = "bytecheck" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +dependencies = [ + "bytecheck_derive", + "ptr_meta", + "simdutf8", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "byteorder" version = "1.4.3" @@ -324,9 +487,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -334,6 +497,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.38" @@ -344,6 +513,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-targets 0.52.0", ] @@ -358,6 +528,52 @@ dependencies = [ "inout", ] +[[package]] +name = "clap" +version = "4.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9689a29b593160de5bc4aacab7b5d54fb52231de70122626c178e6a368994c7" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e5387378c84f6faa26890ebf9f0a92989f8873d4d380467bcd0d8d8620424df" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.11.1", +] + +[[package]] +name = "clap_derive" +version = "4.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "clap_lex" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + [[package]] name = "config" version = "0.14.0" @@ -365,7 +581,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be" dependencies = [ "async-trait", - "convert_case 0.6.0", + "convert_case", "json5", "lazy_static", "nom", @@ -378,6 +594,12 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "const-random" version = "0.1.17" @@ -398,12 +620,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "convert_case" version = "0.6.0" @@ -438,6 +654,36 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "crunchy" version = "0.2.2" @@ -454,16 +700,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "darling" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" -dependencies = [ - "darling_core 0.10.2", - "darling_macro 0.10.2", -] - [[package]] name = "darling" version = "0.13.4" @@ -484,20 +720,6 @@ dependencies = [ "darling_macro 0.20.8", ] -[[package]] -name = "darling_core" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.9.3", - "syn 1.0.109", -] - [[package]] name = "darling_core" version = "0.13.4" @@ -526,17 +748,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "darling_macro" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" -dependencies = [ - "darling_core 0.10.2", - "quote", - "syn 1.0.109", -] - [[package]] name = "darling_macro" version = "0.13.4" @@ -560,10 +771,15 @@ dependencies = [ ] [[package]] -name = "data-encoding" -version = "2.4.0" +name = "der" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] [[package]] name = "derivative" @@ -576,19 +792,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case 0.4.0", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn 1.0.109", -] - [[package]] name = "diff" version = "0.1.13" @@ -602,6 +805,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", "subtle", ] @@ -615,6 +819,21 @@ dependencies = [ "const-random", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +dependencies = [ + "serde", +] + [[package]] name = "encoding_rs" version = "0.8.32" @@ -625,15 +844,10 @@ dependencies = [ ] [[package]] -name = "enum-as-inner" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73" +name = "entity" +version = "0.1.0" dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 1.0.109", + "sea-orm", ] [[package]] @@ -650,7 +864,7 @@ checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -663,6 +877,23 @@ dependencies = [ "libc", ] +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.48.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + [[package]] name = "fastrand" version = "1.9.0" @@ -672,6 +903,17 @@ dependencies = [ "instant", ] +[[package]] +name = "flume" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +dependencies = [ + "futures-core", + "futures-sink", + "spin 0.9.8", +] + [[package]] name = "fnv" version = "1.0.7" @@ -750,6 +992,17 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + [[package]] name = "futures-io" version = "0.3.30" @@ -825,7 +1078,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" [[package]] -name = "h2" +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "h2" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51ee2dd2e4f378392eeff5d51618cd9a63166a2513846bbc55f21cfacd9199d4" @@ -843,6 +1102,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.8", +] + [[package]] name = "hashbrown" version = "0.13.2" @@ -854,6 +1122,19 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash 0.8.11", + "allocator-api2", +] + +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown 0.14.3", +] [[package]] name = "headers" @@ -885,6 +1166,15 @@ name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" @@ -898,6 +1188,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + [[package]] name = "hmac" version = "0.12.1" @@ -908,14 +1207,12 @@ dependencies = [ ] [[package]] -name = "hostname" -version = "0.3.1" +name = "home" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "libc", - "match_cfg", - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -1100,17 +1397,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "idna" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "0.4.0" @@ -1141,6 +1427,17 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "inherent" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0122b7114117e64a63ac49f752a5ca4624d534c7b1c7de796ac196381cd2d947" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "inout" version = "0.1.3" @@ -1167,19 +1464,7 @@ checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi", "libc", - "windows-sys", -] - -[[package]] -name = "ipconfig" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" -dependencies = [ - "socket2 0.5.5", - "widestring", - "windows-sys", - "winreg 0.50.0", + "windows-sys 0.48.0", ] [[package]] @@ -1188,6 +1473,21 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -1222,7 +1522,7 @@ checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" dependencies = [ "base64 0.21.2", "pem", - "ring", + "ring 0.16.20", "serde", "serde_json", "simple_asn1", @@ -1233,6 +1533,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] [[package]] name = "libc" @@ -1240,6 +1543,23 @@ version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "libsqlite3-sys" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -1269,26 +1589,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] -name = "lru-cache" -version = "0.1.2" +name = "matchers" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "linked-hash-map", + "regex-automata 0.1.10", ] -[[package]] -name = "match_cfg" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" - -[[package]] -name = "matches" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" - [[package]] name = "matchit" version = "0.7.0" @@ -1310,6 +1618,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "migration" +version = "0.1.0" +dependencies = [ + "async-trait", + "sea-orm-migration", + "tokio", +] + [[package]] name = "mime" version = "0.3.17" @@ -1339,54 +1656,7 @@ checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "wasi", - "windows-sys", -] - -[[package]] -name = "mongodb" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcd85ec209a5b84fd9f54b9e381f6fa17462bc74160d018fc94fd8b9f61faa8" -dependencies = [ - "async-trait", - "base64 0.13.1", - "bitflags 1.3.2", - "bson", - "chrono", - "derivative", - "derive_more", - "futures-core", - "futures-executor", - "futures-io", - "futures-util", - "hex", - "hmac", - "lazy_static", - "md-5", - "pbkdf2", - "percent-encoding", - "rand", - "rustc_version_runtime", - "rustls", - "rustls-pemfile 1.0.3", - "serde", - "serde_bytes", - "serde_with", - "sha-1", - "sha2", - "socket2 0.4.9", - "stringprep", - "strsim 0.10.0", - "take_mut", - "thiserror", - "tokio", - "tokio-rustls", - "tokio-util", - "trust-dns-proto", - "trust-dns-resolver", - "typed-builder", - "uuid", - "webpki-roots", + "windows-sys 0.48.0", ] [[package]] @@ -1438,6 +1708,23 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1448,6 +1735,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -1455,6 +1753,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -1526,6 +1825,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ordered-float" +version = "3.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" +dependencies = [ + "num-traits", +] + [[package]] name = "ordered-multimap" version = "0.6.0" @@ -1536,6 +1844,30 @@ dependencies = [ "hashbrown 0.13.2", ] +[[package]] +name = "ouroboros" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2ba07320d39dfea882faa70554b4bd342a5f273ed59ba7c1c6b4c840492c954" +dependencies = [ + "aliasable", + "ouroboros_macro", + "static_assertions", +] + +[[package]] +name = "ouroboros_macro" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec4c6225c69b4ca778c0aea097321a64c421cf4577b331c61b229267edabb6f8" +dependencies = [ + "heck 0.4.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "overload" version = "0.1.1" @@ -1560,11 +1892,17 @@ checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.3.5", "smallvec", "windows-targets 0.48.1", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "pathdiff" version = "0.2.1" @@ -1572,21 +1910,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] -name = "pbkdf2" -version = "0.11.0" +name = "pem" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" dependencies = [ - "digest", + "base64 0.13.1", ] [[package]] -name = "pem" -version = "1.1.1" +name = "pem-rfc7468" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" dependencies = [ - "base64 0.13.1", + "base64ct", ] [[package]] @@ -1671,6 +2009,27 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.27" @@ -1693,6 +2052,15 @@ dependencies = [ "yansi", ] +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -1727,10 +2095,24 @@ dependencies = [ ] [[package]] -name = "quick-error" -version = "1.2.3" +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] [[package]] name = "quote" @@ -1786,6 +2168,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[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 = "regex" version = "1.9.1" @@ -1794,8 +2185,17 @@ checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.3.3", + "regex-syntax 0.7.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -1806,15 +2206,30 @@ checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.7.4", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +[[package]] +name = "rend" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck", +] + [[package]] name = "reqwest" version = "0.12.4" @@ -1854,17 +2269,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg 0.52.0", -] - -[[package]] -name = "resolv-conf" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" -dependencies = [ - "hostname", - "quick-error", + "winreg", ] [[package]] @@ -1876,17 +2281,61 @@ dependencies = [ "cc", "libc", "once_cell", - "spin", - "untrusted", + "spin 0.5.2", + "untrusted 0.7.1", "web-sys", "winapi", ] [[package]] -name = "ron" -version = "0.8.1" +name = "ring" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys 0.52.0", +] + +[[package]] +name = "rkyv" +version = "0.7.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cba464629b3394fc4dbc6f940ff8f5b4ff5c7aef40f29166fd4ad12acbc99c0" +dependencies = [ + "bitvec", + "bytecheck", + "bytes", + "hashbrown 0.12.3", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", + "tinyvec", + "uuid", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7dddfff8de25e6f62b9d64e6e432bf1c6736c57d20323e15ee10435fbda7c65" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ron" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ "base64 0.21.2", "bitflags 2.3.3", @@ -1894,6 +2343,26 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rust-ini" version = "0.19.0" @@ -1904,6 +2373,22 @@ dependencies = [ "ordered-multimap", ] +[[package]] +name = "rust_decimal" +version = "1.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +dependencies = [ + "arrayvec", + "borsh", + "bytes", + "num-traits", + "rand", + "rkyv", + "serde", + "serde_json", +] + [[package]] name = "rustapi" version = "0.1.0" @@ -1916,12 +2401,15 @@ dependencies = [ "bytes", "chrono", "config", + "entity", "futures", "jsonwebtoken", + "migration", "mime", "once_cell", "pretty_assertions", "reqwest", + "sea-orm", "serde", "serde_derive", "serde_json", @@ -1931,7 +2419,6 @@ dependencies = [ "tracing", "tracing-subscriber", "validator", - "wither", ] [[package]] @@ -1940,34 +2427,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.18", -] - -[[package]] -name = "rustc_version_runtime" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d31b7153270ebf48bf91c65ae5b0c00e749c4cfad505f66530ac74950249582f" -dependencies = [ - "rustc_version 0.2.3", - "semver 0.9.0", -] - [[package]] name = "rustix" version = "0.37.23" @@ -1979,26 +2438,25 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] name = "rustls" -version = "0.20.8" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ - "log", - "ring", + "ring 0.17.8", + "rustls-webpki", "sct", - "webpki", ] [[package]] name = "rustls-pemfile" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ "base64 0.21.2", ] @@ -2019,6 +2477,16 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -2037,7 +2505,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2048,14 +2516,179 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sct" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] +[[package]] +name = "sea-bae" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd3534a9978d0aa7edd2808dc1f8f31c4d0ecd31ddf71d997b3c98e9f3c9114" +dependencies = [ + "heck 0.4.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "sea-orm" +version = "0.12.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8814e37dc25de54398ee62228323657520b7f29713b8e238649385dbe473ee0" +dependencies = [ + "async-stream", + "async-trait", + "bigdecimal", + "chrono", + "futures", + "log", + "ouroboros", + "rust_decimal", + "sea-orm-macros", + "sea-query", + "sea-query-binder", + "serde", + "serde_json", + "sqlx", + "strum", + "thiserror", + "time", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "sea-orm-cli" +version = "0.12.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "620bc560062ae251b1366bde43b3f1508445cab5c2c8cbdb397034638ab1b357" +dependencies = [ + "chrono", + "clap", + "dotenvy", + "glob", + "regex", + "sea-schema", + "tracing", + "tracing-subscriber", + "url", +] + +[[package]] +name = "sea-orm-macros" +version = "0.12.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e115c6b078e013aa963cc2d38c196c2c40b05f03d0ac872fe06b6e0d5265603" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "sea-bae", + "syn 2.0.48", + "unicode-ident", +] + +[[package]] +name = "sea-orm-migration" +version = "0.12.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee8269bc6ff71afd6b78aa4333ac237a69eebd2cdb439036291e64fb4b8db23c" +dependencies = [ + "async-trait", + "clap", + "dotenvy", + "futures", + "sea-orm", + "sea-orm-cli", + "sea-schema", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "sea-query" +version = "0.30.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4166a1e072292d46dc91f31617c2a1cdaf55a8be4b5c9f4bf2ba248e3ac4999b" +dependencies = [ + "bigdecimal", + "chrono", + "derivative", + "inherent", + "ordered-float", + "rust_decimal", + "sea-query-derive", + "serde_json", + "time", + "uuid", +] + +[[package]] +name = "sea-query-binder" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36bbb68df92e820e4d5aeb17b4acd5cc8b5d18b2c36a4dd6f4626aabfa7ab1b9" +dependencies = [ + "bigdecimal", + "chrono", + "rust_decimal", + "sea-query", + "serde_json", + "sqlx", + "time", + "uuid", +] + +[[package]] +name = "sea-query-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a82fcb49253abcb45cdcb2adf92956060ec0928635eb21b4f7a6d8f25ab0bc" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.48", + "thiserror", +] + +[[package]] +name = "sea-schema" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d148608012d25222442d1ebbfafd1228dbc5221baf4ec35596494e27a2394e" +dependencies = [ + "futures", + "sea-query", + "sea-schema-derive", +] + +[[package]] +name = "sea-schema-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f686050f76bffc4f635cda8aea6df5548666b830b52387e8bc7de11056d11e" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + [[package]] name = "security-framework" version = "2.9.1" @@ -2079,27 +2712,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.202" @@ -2194,17 +2806,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "sha-1" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "sha1" version = "0.10.5" @@ -2245,6 +2846,22 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "simdutf8" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" + [[package]] name = "simple_asn1" version = "0.6.2" @@ -2258,45 +2875,297 @@ dependencies = [ ] [[package]] -name = "slab" -version = "0.4.8" +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlformat" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" +dependencies = [ + "itertools", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" +dependencies = [ + "ahash 0.8.11", + "atoi", + "bigdecimal", + "byteorder", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashlink", + "hex", + "indexmap", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "rust_decimal", + "rustls", + "rustls-pemfile 1.0.4", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror", + "time", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", + "webpki-roots", +] + +[[package]] +name = "sqlx-macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 1.0.109", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" dependencies = [ - "autocfg", + "dotenvy", + "either", + "heck 0.4.1", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn 1.0.109", + "tempfile", + "tokio", + "url", ] [[package]] -name = "smallvec" -version = "1.13.2" +name = "sqlx-mysql" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" +dependencies = [ + "atoi", + "base64 0.21.2", + "bigdecimal", + "bitflags 2.3.3", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "rust_decimal", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "time", + "tracing", + "uuid", + "whoami", +] [[package]] -name = "socket2" -version = "0.4.9" +name = "sqlx-postgres" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" dependencies = [ - "libc", - "winapi", + "atoi", + "base64 0.21.2", + "bigdecimal", + "bitflags 2.3.3", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "num-bigint", + "once_cell", + "rand", + "rust_decimal", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "time", + "tracing", + "uuid", + "whoami", ] [[package]] -name = "socket2" -version = "0.5.5" +name = "sqlx-sqlite" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" dependencies = [ - "libc", - "windows-sys", + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core", + "time", + "tracing", + "url", + "urlencoding", + "uuid", ] [[package]] -name = "spin" -version = "0.5.2" +name = "static_assertions" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stringprep" @@ -2310,15 +3179,21 @@ dependencies = [ [[package]] name = "strsim" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" [[package]] name = "subtle" @@ -2348,6 +3223,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "sync_wrapper" version = "0.1.2" @@ -2375,12 +3262,6 @@ dependencies = [ "libc", ] -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" - [[package]] name = "tap" version = "1.0.1" @@ -2396,9 +3277,9 @@ dependencies = [ "autocfg", "cfg-if", "fastrand", - "redox_syscall", + "redox_syscall 0.3.5", "rustix", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2498,7 +3379,7 @@ dependencies = [ "signal-hook-registry", "socket2 0.5.5", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] @@ -2523,14 +3404,14 @@ dependencies = [ ] [[package]] -name = "tokio-rustls" -version = "0.23.4" +name = "tokio-stream" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ - "rustls", + "futures-core", + "pin-project-lite", "tokio", - "webpki", ] [[package]] @@ -2541,7 +3422,6 @@ checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" dependencies = [ "bytes", "futures-core", - "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -2682,76 +3562,24 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] -[[package]] -name = "trust-dns-proto" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.2.3", - "ipnet", - "lazy_static", - "log", - "rand", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ba72c2ea84515690c9fcef4c6c660bb9df3036ed1051686de84605b74fd558" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lazy_static", - "log", - "lru-cache", - "parking_lot", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "trust-dns-proto", -] - [[package]] name = "try-lock" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" -[[package]] -name = "typed-builder" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89851716b67b937e393b3daa8423e67ddfc4bbbf1654bcf05488e95e0828db0c" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "typenum" version = "1.16.0" @@ -2791,12 +3619,24 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + [[package]] name = "untrusted" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.4.0" @@ -2808,6 +3648,18 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.4.0" @@ -2881,6 +3733,12 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" + [[package]] name = "wasm-bindgen" version = "0.2.87" @@ -2958,30 +3816,21 @@ dependencies = [ ] [[package]] -name = "webpki" -version = "0.22.0" +name = "webpki-roots" +version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" -dependencies = [ - "ring", - "untrusted", -] +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] -name = "webpki-roots" -version = "0.22.6" +name = "whoami" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" dependencies = [ - "webpki", + "redox_syscall 0.4.1", + "wasite", ] -[[package]] -name = "widestring" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" - [[package]] name = "winapi" version = "0.3.9" @@ -3022,6 +3871,15 @@ dependencies = [ "windows-targets 0.48.1", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-targets" version = "0.48.1" @@ -3145,16 +4003,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if", - "windows-sys", -] - [[package]] name = "winreg" version = "0.52.0" @@ -3162,37 +4010,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" dependencies = [ "cfg-if", - "windows-sys", -] - -[[package]] -name = "wither" -version = "0.9.0" -source = "git+https://github.com/thedodd/wither?rev=52fd503#52fd5037d5aa0dc358def3760cea8ef13a8766e8" -dependencies = [ - "async-trait", - "chrono", - "futures", - "log", - "mongodb", - "serde", - "thiserror", - "wither_derive", -] - -[[package]] -name = "wither_derive" -version = "0.9.0" -source = "git+https://github.com/thedodd/wither?rev=52fd503#52fd5037d5aa0dc358def3760cea8ef13a8766e8" -dependencies = [ - "Inflector", - "async-trait", - "darling 0.10.2", - "proc-macro-error", - "proc-macro2", - "quote", - "serde", - "syn 1.0.109", + "windows-sys 0.48.0", ] [[package]] @@ -3219,6 +4037,26 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "zerocopy" +version = "0.7.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "zeroize" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 8df1122..544b560 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,14 +4,18 @@ version = "0.1.0" authors = ["ndelvalle "] edition = "2021" +[workspace] +members = [".", "entity", "migration"] + + [dependencies] +entity = { path = "entity" } +migration = { path = "migration" } # depends on your needs + config = "0.14.0" serde = { version = "1.0.202", features = ["derive"] } serde_json = "1.0.116" serde_derive = "1.0.152" -# Wait for wither to relase a new version. -# https://github.com/thedodd/wither/pull/89#issuecomment-1023644443 -wither = { git = "https://github.com/thedodd/wither", rev = "52fd503" } futures = "0.3.30" thiserror = "1.0.61" axum = { version = "0.6.20", features = ["headers"] } @@ -35,6 +39,7 @@ bcrypt = "0.15.1" validator = { version = "0.18.1", features = ["derive"] } mime = "0.3.17" bytes = "1.6.0" +sea-orm = "0.12.15" [dev-dependencies] assert-json-diff = "2.0.2" diff --git a/config/default.json b/config/default.json index 12e57db..2d8b428 100644 --- a/config/default.json +++ b/config/default.json @@ -1,19 +1,15 @@ { "environment": "development", - "server": { "port": 8080 }, - "database": { - "uri": "mongodb://localhost:27017", + "uri": "postgresql://localhost:5432/rustdis", "name": "rustapi" }, - "auth": { "secret": "secret" }, - "logger": { "level": "debug" } diff --git a/config/production.json b/config/production.json index ee41684..0b731fa 100644 --- a/config/production.json +++ b/config/production.json @@ -1,7 +1,6 @@ { "environment": "production", - "logger": { "level": "info" } -} \ No newline at end of file +} diff --git a/config/test.json b/config/test.json index 9d50f82..86eeb79 100644 --- a/config/test.json +++ b/config/test.json @@ -1,15 +1,12 @@ { "environment": "test", - "server": { "port": 8088 }, - "database": { - "uri": "mongodb://localhost:27017", + "uri": "postgresql://localhost:5432/rustdis", "name": "rustapi-test" }, - "logger": { "level": "error" } diff --git a/entity/src/entities/cat.rs b/entity/src/entities/cat.rs index 7804055..06451e6 100644 --- a/entity/src/entities/cat.rs +++ b/entity/src/entities/cat.rs @@ -5,30 +5,30 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "cat")] pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub name: String, - pub created_at: DateTime, - pub updated_at: DateTime, - pub user: Uuid, + #[sea_orm(primary_key, auto_increment = false)] + pub id: Uuid, + pub name: String, + pub created_at: DateTime, + pub updated_at: DateTime, + pub user: Uuid, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm( - belongs_to = "super::user::Entity", - from = "Column::User", - to = "super::user::Column::Id", - on_update = "NoAction", - on_delete = "NoAction" - )] - User, + #[sea_orm( + belongs_to = "super::user::Entity", + from = "Column::User", + to = "super::user::Column::Id", + on_update = "NoAction", + on_delete = "NoAction" + )] + User, } impl Related for Entity { - fn to() -> RelationDef { - Relation::User.def() - } + fn to() -> RelationDef { + Relation::User.def() + } } impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/entities/user.rs b/entity/src/entities/user.rs index 661e8cc..e7019bc 100644 --- a/entity/src/entities/user.rs +++ b/entity/src/entities/user.rs @@ -5,26 +5,26 @@ use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "user")] pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub name: String, - pub email: String, - pub password: String, - pub created_at: DateTime, - pub updated_at: DateTime, - pub locked_at: Option, + #[sea_orm(primary_key, auto_increment = false)] + pub id: Uuid, + pub name: String, + pub email: String, + pub password: String, + pub created_at: DateTime, + pub updated_at: DateTime, + pub locked_at: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm(has_many = "super::cat::Entity")] - Cat, + #[sea_orm(has_many = "super::cat::Entity")] + Cat, } impl Related for Entity { - fn to() -> RelationDef { - Relation::Cat.def() - } + fn to() -> RelationDef { + Relation::Cat.def() + } } impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/lib.rs b/entity/src/lib.rs index 21c129f..4ee50c5 100644 --- a/entity/src/lib.rs +++ b/entity/src/lib.rs @@ -1,2 +1,4 @@ mod entities; -pub use entities::*; + +pub use entities::cat; +pub use entities::user; diff --git a/migration/src/m20240527_080925_create_users_table.rs b/migration/src/m20240527_080925_create_users_table.rs index 977589e..c139ac6 100644 --- a/migration/src/m20240527_080925_create_users_table.rs +++ b/migration/src/m20240527_080925_create_users_table.rs @@ -5,49 +5,49 @@ pub struct Migration; #[derive(DeriveIden)] pub enum User { - Table, - Id, - Name, - Email, - Password, - CreatedAt, - UpdatedAt, - LockedAt, + Table, + Id, + Name, + Email, + Password, + CreatedAt, + UpdatedAt, + LockedAt, } #[async_trait::async_trait] impl MigrationTrait for Migration { - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .create_table( - Table::create() - .table(User::Table) - .if_not_exists() - .col(ColumnDef::new(User::Id).uuid().not_null().primary_key()) - .col(ColumnDef::new(User::Name).string().not_null()) - .col(ColumnDef::new(User::Email).string().not_null()) - .col(ColumnDef::new(User::Password).string().not_null()) - .col( - ColumnDef::new(User::CreatedAt) - .timestamp() - .not_null() - .default(Expr::current_timestamp()), - ) - .col( - ColumnDef::new(User::UpdatedAt) - .timestamp() - .not_null() - .default(Expr::current_timestamp()), - ) - .col(ColumnDef::new(User::LockedAt).timestamp()) - .to_owned(), - ) - .await - } + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(User::Table) + .if_not_exists() + .col(ColumnDef::new(User::Id).uuid().not_null().primary_key()) + .col(ColumnDef::new(User::Name).string().not_null()) + .col(ColumnDef::new(User::Email).string().not_null()) + .col(ColumnDef::new(User::Password).string().not_null()) + .col( + ColumnDef::new(User::CreatedAt) + .timestamp() + .not_null() + .default(Expr::current_timestamp()), + ) + .col( + ColumnDef::new(User::UpdatedAt) + .timestamp() + .not_null() + .default(Expr::current_timestamp()), + ) + .col(ColumnDef::new(User::LockedAt).timestamp()) + .to_owned(), + ) + .await + } - async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .drop_table(Table::drop().table(User::Table).to_owned()) - .await - } + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(User::Table).to_owned()) + .await + } } diff --git a/migration/src/m20240530_082146_create_cats_table.rs b/migration/src/m20240530_082146_create_cats_table.rs index 0ae0604..a806c73 100644 --- a/migration/src/m20240530_082146_create_cats_table.rs +++ b/migration/src/m20240530_082146_create_cats_table.rs @@ -8,50 +8,50 @@ pub struct Migration; #[derive(DeriveIden)] enum Cat { - Table, - Id, - User, - Name, - CreatedAt, - UpdatedAt, + Table, + Id, + User, + Name, + CreatedAt, + UpdatedAt, } #[async_trait::async_trait] impl MigrationTrait for Migration { - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .create_table( - Table::create() - .table(Cat::Table) - .if_not_exists() - .col(ColumnDef::new(Cat::Id).uuid().not_null().primary_key()) - .col(ColumnDef::new(Cat::Name).string().not_null()) - .col( - ColumnDef::new(Cat::CreatedAt) - .timestamp() - .not_null() - .default(Expr::current_timestamp()), - ) - .col( - ColumnDef::new(Cat::UpdatedAt) - .timestamp() - .not_null() - .default(Expr::current_timestamp()), - ) - .col(ColumnDef::new(Cat::User).uuid().not_null()) - .foreign_key( - ForeignKey::create() - .from(Cat::Table, Cat::User) - .to(User::Table, User::Id), - ) - .to_owned(), - ) - .await - } + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(Cat::Table) + .if_not_exists() + .col(ColumnDef::new(Cat::Id).uuid().not_null().primary_key()) + .col(ColumnDef::new(Cat::Name).string().not_null()) + .col( + ColumnDef::new(Cat::CreatedAt) + .timestamp() + .not_null() + .default(Expr::current_timestamp()), + ) + .col( + ColumnDef::new(Cat::UpdatedAt) + .timestamp() + .not_null() + .default(Expr::current_timestamp()), + ) + .col(ColumnDef::new(Cat::User).uuid().not_null()) + .foreign_key( + ForeignKey::create() + .from(Cat::Table, Cat::User) + .to(User::Table, User::Id), + ) + .to_owned(), + ) + .await + } - async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .drop_table(Table::drop().table(Cat::Table).to_owned()) - .await - } + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(Cat::Table).to_owned()) + .await + } } diff --git a/src/database.rs b/src/database.rs index d6c1d0b..5f0aeff 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,21 +1,25 @@ -use mongodb::Database; +use sea_orm::{ConnectOptions, Database, DatabaseConnection}; use tokio::sync::OnceCell; -use wither::mongodb; + +use std::time::Duration; use crate::settings::SETTINGS; -static CONNECTION: OnceCell = OnceCell::const_new(); +static CONNECTION: OnceCell = OnceCell::const_new(); + +pub async fn connection() -> &'static DatabaseConnection { + CONNECTION + .get_or_init(|| async { + let uri = SETTINGS.database.uri.as_str(); + let mut opt = ConnectOptions::new(uri); -pub async fn connection() -> &'static Database { - CONNECTION - .get_or_init(|| async { - let db_uri = SETTINGS.database.uri.as_str(); - let db_name = SETTINGS.database.name.as_str(); + opt.min_connections(100) + .max_connections(1) + .connect_timeout(Duration::from_secs(10)); - mongodb::Client::with_uri_str(db_uri) + Database::connect(opt) + .await + .expect("Failed to connect to PostgreSQL") + }) .await - .expect("Failed to initialize MongoDB connection") - .database(db_name) - }) - .await } diff --git a/src/errors.rs b/src/errors.rs index 63c8e01..a63855a 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -2,6 +2,7 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use axum::Json; use bcrypt::BcryptError; +use sea_orm::error::DbErr as DatabaseError; use serde_json::json; use tokio::task::JoinError; use wither::bson; @@ -14,6 +15,9 @@ pub enum Error { #[error("{0}")] Wither(#[from] WitherError), + #[error("{0}")] + DatabaseError(#[from] DatabaseError), + #[error("{0}")] Mongo(#[from] MongoError), @@ -59,6 +63,7 @@ impl Error { Error::SerializeMongoResponse(_) => (StatusCode::INTERNAL_SERVER_ERROR, 5004), Error::RunSyncTask(_) => (StatusCode::INTERNAL_SERVER_ERROR, 5005), Error::HashPassword(_) => (StatusCode::INTERNAL_SERVER_ERROR, 5006), + Error::DatabaseError(_) => (StatusCode::INTERNAL_SERVER_ERROR, 5007), } } diff --git a/src/main.rs b/src/main.rs index 84b9ae6..a443c9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use entity; use std::net::SocketAddr; use tracing::info; @@ -23,14 +24,14 @@ use settings::SETTINGS; #[tokio::main] async fn main() { - let app = app::create_app().await; + let app = app::create_app().await; - let port = SETTINGS.server.port; - let address = SocketAddr::from(([127, 0, 0, 1], port)); + let port = SETTINGS.server.port; + let address = SocketAddr::from(([127, 0, 0, 1], port)); - info!("Server listening on {}", &address); - axum::Server::bind(&address) - .serve(app.into_make_service()) - .await - .expect("Failed to start server"); + info!("Server listening on {}", &address); + axum::Server::bind(&address) + .serve(app.into_make_service()) + .await + .expect("Failed to start server"); } diff --git a/src/models/cat.rs b/src/models/cat.rs index a654a0c..62f56ec 100644 --- a/src/models/cat.rs +++ b/src/models/cat.rs @@ -1,61 +1,68 @@ -use bson::serde_helpers::bson_datetime_as_rfc3339_string; -use bson::serde_helpers::serialize_object_id_as_hex_string; -use serde::{Deserialize, Serialize}; -use validator::Validate; -use wither::bson::{doc, oid::ObjectId}; -use wither::Model as WitherModel; +use sea_orm::entity::prelude::Uuid; +use sea_orm::ActiveValue::Set; -use crate::utils::date; -use crate::utils::date::Date; -use crate::utils::models::ModelExt; +use crate::entity::cat; +use crate::entity::cat::Entity as Cat; +use crate::utils::entity::EntityExt; +use crate::Error; -impl ModelExt for Cat {} +impl EntityExt for Cat {} -#[derive(Debug, Clone, Serialize, Deserialize, WitherModel, Validate)] -#[model(index(keys = r#"doc!{ "user": 1, "created_at": 1 }"#))] -pub struct Cat { - #[serde(rename = "_id", skip_serializing_if = "Option::is_none")] - pub id: Option, - pub user: ObjectId, - pub name: String, - pub updated_at: Date, - pub created_at: Date, -} - -impl Cat { - pub fn new(user: ObjectId, name: String) -> Self { - let now = date::now(); - Self { - id: None, - user, - name, - updated_at: now, - created_at: now, - } - } -} +pub async fn create_cat(user: Uuid, name: String) -> Result { + let cat = cat::ActiveModel { + id: Set(Uuid::new_v4()), + name: Set(name), + ..Default::default() + }; -#[derive(Debug, Serialize, Deserialize)] -pub struct PublicCat { - #[serde(alias = "_id", serialize_with = "serialize_object_id_as_hex_string")] - pub id: ObjectId, - #[serde(serialize_with = "serialize_object_id_as_hex_string")] - pub user: ObjectId, - pub name: String, - #[serde(with = "bson_datetime_as_rfc3339_string")] - pub updated_at: Date, - #[serde(with = "bson_datetime_as_rfc3339_string")] - pub created_at: Date, + Cat::create(cat).await } -impl From for PublicCat { - fn from(cat: Cat) -> Self { - Self { - id: cat.id.unwrap(), - user: cat.user, - name: cat.name.clone(), - updated_at: cat.updated_at, - created_at: cat.created_at, - } - } -} +// #[derive(Debug, Clone, Serialize, Deserialize, WitherModel, Validate)] +// #[model(index(keys = r#"doc!{ "user": 1, "created_at": 1 }"#))] +// pub struct Cat { +// #[serde(rename = "_id", skip_serializing_if = "Option::is_none")] +// pub id: Option, +// pub user: ObjectId, +// pub name: String, +// pub updated_at: Date, +// pub created_at: Date, +// } +// +// impl Cat { +// pub fn new(user: ObjectId, name: String) -> Self { +// let now = date::now(); +// Self { +// id: None, +// user, +// name, +// updated_at: now, +// created_at: now, +// } +// } +// } +// +// #[derive(Debug, Serialize, Deserialize)] +// pub struct PublicCat { +// #[serde(alias = "_id", serialize_with = "serialize_object_id_as_hex_string")] +// pub id: ObjectId, +// #[serde(serialize_with = "serialize_object_id_as_hex_string")] +// pub user: ObjectId, +// pub name: String, +// #[serde(with = "bson_datetime_as_rfc3339_string")] +// pub updated_at: Date, +// #[serde(with = "bson_datetime_as_rfc3339_string")] +// pub created_at: Date, +// } +// +// impl From for PublicCat { +// fn from(cat: Cat) -> Self { +// Self { +// id: cat.id.unwrap(), +// user: cat.user, +// name: cat.name.clone(), +// updated_at: cat.updated_at, +// created_at: cat.created_at, +// } +// } +// } diff --git a/src/routes/cat.rs b/src/routes/cat.rs index 3f65fe9..019980d 100644 --- a/src/routes/cat.rs +++ b/src/routes/cat.rs @@ -1,138 +1,134 @@ use axum::http::StatusCode; use axum::{ - extract::Path, - routing::{delete, get, post, put}, - Json, Router, + extract::Path, + routing::{delete, get, post, put}, + Json, Router, }; use bson::doc; use serde::{Deserialize, Serialize}; use tracing::debug; -use wither::mongodb::options::FindOptions; use crate::errors::Error; -use crate::models::cat::{Cat, PublicCat}; +use crate::models::cat; use crate::utils::custom_response::CustomResponseResult as Response; use crate::utils::custom_response::{CustomResponse, CustomResponseBuilder, ResponsePagination}; -use crate::utils::models::ModelExt; -use crate::utils::pagination::Pagination; -use crate::utils::to_object_id::to_object_id; use crate::utils::token::TokenUser; pub fn create_route() -> Router { - Router::new() - .route("/cats", post(create_cat)) - .route("/cats", get(query_cats)) - .route("/cats/:id", get(get_cat_by_id)) - .route("/cats/:id", delete(remove_cat_by_id)) - .route("/cats/:id", put(update_cat_by_id)) + Router::new() + .route("/cats", post(create_cat)) + .route("/cats", get(query_cats)) + .route("/cats/:id", get(get_cat_by_id)) + .route("/cats/:id", delete(remove_cat_by_id)) + .route("/cats/:id", put(update_cat_by_id)) } async fn create_cat(user: TokenUser, Json(payload): Json) -> Response { - let cat = Cat::new(user.id, payload.name); - let cat = Cat::create(cat).await?; - let res = PublicCat::from(cat); + let cat = Cat::new(user.id, payload.name); + let cat = Cat::create(cat).await?; + let res = PublicCat::from(cat); - let res = CustomResponseBuilder::new() - .body(res) - .status_code(StatusCode::CREATED) - .build(); + let res = CustomResponseBuilder::new() + .body(res) + .status_code(StatusCode::CREATED) + .build(); - Ok(res) + Ok(res) } async fn query_cats(user: TokenUser, pagination: Pagination) -> Response> { - let options = FindOptions::builder() - .sort(doc! { "created_at": -1_i32 }) - .skip(pagination.offset) - .limit(pagination.limit as i64) - .build(); - - let (cats, count) = Cat::find_and_count(doc! { "user": &user.id }, options).await?; - let cats = cats.into_iter().map(Into::into).collect::>(); - - let res = CustomResponseBuilder::new() - .body(cats) - .pagination(ResponsePagination { - count, - offset: pagination.offset, - limit: pagination.limit, - }) - .build(); - - debug!("Returning cats"); - Ok(res) + let options = FindOptions::builder() + .sort(doc! { "created_at": -1_i32 }) + .skip(pagination.offset) + .limit(pagination.limit as i64) + .build(); + + let (cats, count) = Cat::find_and_count(doc! { "user": &user.id }, options).await?; + let cats = cats.into_iter().map(Into::into).collect::>(); + + let res = CustomResponseBuilder::new() + .body(cats) + .pagination(ResponsePagination { + count, + offset: pagination.offset, + limit: pagination.limit, + }) + .build(); + + debug!("Returning cats"); + Ok(res) } async fn get_cat_by_id(user: TokenUser, Path(id): Path) -> Result, Error> { - let cat_id = to_object_id(id)?; - let cat = Cat::find_one(doc! { "_id": cat_id, "user": &user.id }, None) - .await? - .map(PublicCat::from); - - let cat = match cat { - Some(cat) => cat, - None => { - debug!("Cat not found, returning 404 status code"); - return Err(Error::not_found()); - } - }; - - debug!("Returning cat"); - Ok(Json(cat)) + let cat_id = to_object_id(id)?; + let cat = Cat::find_one(doc! { "_id": cat_id, "user": &user.id }, None) + .await? + .map(PublicCat::from); + + let cat = match cat { + Some(cat) => cat, + None => { + debug!("Cat not found, returning 404 status code"); + return Err(Error::not_found()); + } + }; + + debug!("Returning cat"); + Ok(Json(cat)) } async fn remove_cat_by_id( - user: TokenUser, - Path(id): Path, + user: TokenUser, + Path(id): Path, ) -> Result, Error> { - let cat_id = to_object_id(id)?; - let delete_result = Cat::delete_one(doc! { "_id": cat_id, "user": &user.id }).await?; + let cat_id = to_object_id(id)?; + let delete_result = Cat::delete_one(doc! { "_id": cat_id, "user": &user.id }).await?; - if delete_result.deleted_count == 0 { - debug!("Cat not found, returning 404 status code"); - return Err(Error::not_found()); - } + if delete_result.deleted_count == 0 { + debug!("Cat not found, returning 404 status code"); + return Err(Error::not_found()); + } - let res = CustomResponseBuilder::new() - .status_code(StatusCode::NO_CONTENT) - .build(); + let res = CustomResponseBuilder::new() + .status_code(StatusCode::NO_CONTENT) + .build(); - Ok(res) + Ok(res) } async fn update_cat_by_id( - user: TokenUser, - Path(id): Path, - Json(payload): Json, + user: TokenUser, + Path(id): Path, + Json(payload): Json, ) -> Result, Error> { - let cat_id = to_object_id(id)?; - let update = bson::to_document(&payload).unwrap(); - - let cat = Cat::find_one_and_update( - doc! { "_id": &cat_id, "user": &user.id }, - doc! { "$set": update }, - ) - .await? - .map(PublicCat::from); - - let cat = match cat { - Some(cat) => cat, - None => { - debug!("Cat not found, returning 404 status code"); - return Err(Error::not_found()); - } - }; + let cat_id = to_object_id(id)?; + let update = bson::to_document(&payload).unwrap(); + + let cat = Cat::find_one_and_update( + doc! { "_id": &cat_id, "user": &user.id }, + doc! { "$set": update }, + ) + .await? + .map(PublicCat::from); + + let cat = match cat { + Some(cat) => cat, + None => { + debug!("Cat not found, returning 404 status code"); + return Err(Error::not_found()); + } + }; - debug!("Returning cat"); - Ok(Json(cat)) + debug!("Returning cat"); + Ok(Json(cat)) } #[derive(Deserialize)] struct CreateCat { - name: String, + name: String, } #[derive(Serialize, Deserialize)] struct UpdateCat { - name: String, + name: String, } diff --git a/src/utils/entity.rs b/src/utils/entity.rs new file mode 100644 index 0000000..df4213d --- /dev/null +++ b/src/utils/entity.rs @@ -0,0 +1,95 @@ +use crate::database; +use crate::errors::Error; +use async_trait::async_trait; + +use sea_orm::query::QueryFilter; +use sea_orm::{ActiveModelTrait, DeleteResult, EntityTrait, PrimaryKeyTrait}; + +#[async_trait] +pub trait EntityExt: EntityTrait { + // async fn create(model: T) -> Result<(), Error> + // where + // T: ActiveModelTrait + Send, + // { + // let conn = database::connection().await; + // // let result = ::insert(model) + // // .exec(conn) + // // .await + // // .map_err(Error::DatabaseError)?; + // + // Self::ActiveModel { + // title: Set(form_data.title.to_owned()), + // text: Set(form_data.text.to_owned()), + // ..Default::default() + // } + // .save(db) + // .await + // } + + async fn create(model: T) -> Result + where + T: ActiveModelTrait + Send, + { + let conn = database::connection().await; + model.save(conn).await + } + + async fn find_by_id(id: T) -> Result, Error> + where + T: Into<::ValueType> + Send, + { + let conn = database::connection().await; + ::find_by_id(id) + .one(conn) + .await + .map_err(Error::DatabaseError) + } + + async fn find_one(query: Q) -> Result, Error> + where + Q: QueryFilter, + { + let conn = database::connection().await; + ::find() + .filter(query) + .one(conn) + .await + .map_err(Error::DatabaseError) + } + + async fn find(query: Q) -> Result, Error> + where + Q: QueryFilter, + { + let conn = database::connection().await; + ::find() + .filter(query) + .all(conn) + .await + .map_err(Error::DatabaseError) + } + + async fn delete_by_id(id: T) -> Result + where + T: Into<::ValueType> + Send, + { + let conn = database::connection().await; + ::delete_by_id(id) + .exec(conn) + .await + .map_err(Error::DatabaseError) + } + + async fn update_one(query: Q, update: U) -> Result + where + Q: QueryFilter, + U: ActiveModelTrait, + { + let conn = database::connection().await; + ::update(update.clone()) + .filter(query) + .exec(conn) + .await + .map_err(Error::DatabaseError) + } +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 320e075..8163463 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,6 +1,7 @@ pub mod authenticate_request; pub mod custom_response; pub mod date; +pub mod entity; pub mod models; pub mod pagination; pub mod to_object_id; diff --git a/src/utils/models.rs b/src/utils/models.rs deleted file mode 100644 index 2ae2fad..0000000 --- a/src/utils/models.rs +++ /dev/null @@ -1,202 +0,0 @@ -#![allow(dead_code)] - -use async_trait::async_trait; -use futures::stream::TryStreamExt; -use serde::{de::DeserializeOwned, ser::Serialize}; -use validator::Validate; -use wither::bson::doc; -use wither::bson::from_bson; -use wither::bson::Bson; -use wither::bson::Document; -use wither::bson::{self, oid::ObjectId}; -use wither::mongodb::options::FindOneAndUpdateOptions; -use wither::mongodb::options::FindOneOptions; -use wither::mongodb::options::FindOptions; -use wither::mongodb::options::ReturnDocument; -use wither::mongodb::options::UpdateOptions; -use wither::mongodb::results::DeleteResult; -use wither::mongodb::results::UpdateResult; -use wither::Model as WitherModel; -use wither::ModelCursor; - -use crate::database; -use crate::errors::Error; - -// This is the Model trait. All models that have a MongoDB collection should -// implement this and therefore inherit theses methods. -#[async_trait] -pub trait ModelExt -where - Self: WitherModel + Validate, -{ - async fn create(mut model: Self) -> Result { - let connection = database::connection().await; - model.validate().map_err(|_error| Error::bad_request())?; - model.save(connection, None).await.map_err(Error::Wither)?; - - Ok(model) - } - - async fn find_by_id(id: &ObjectId) -> Result, Error> { - let connection = database::connection().await; - ::find_one(connection, doc! { "_id": id }, None) - .await - .map_err(Error::Wither) - } - - async fn find_one(query: Document, options: O) -> Result, Error> - where - O: Into> + Send, - { - let connection = database::connection().await; - ::find_one(connection, query, options) - .await - .map_err(Error::Wither) - } - - async fn find(query: Document, options: O) -> Result, Error> - where - O: Into> + Send, - { - let connection = database::connection().await; - ::find(connection, query, options) - .await - .map_err(Error::Wither)? - .try_collect::>() - .await - .map_err(Error::Wither) - } - - async fn find_and_count(query: Document, options: O) -> Result<(Vec, u64), Error> - where - O: Into> + Send, - { - let connection = database::connection().await; - - let count = Self::collection(connection) - .count_documents(query.clone(), None) - .await - .map_err(Error::Mongo)?; - - let items = ::find(connection, query, options.into()) - .await - .map_err(Error::Wither)? - .try_collect::>() - .await - .map_err(Error::Wither)?; - - Ok((items, count)) - } - - async fn cursor(query: Document, options: O) -> Result, Error> - where - O: Into> + Send, - { - let connection = database::connection().await; - ::find(connection, query, options) - .await - .map_err(Error::Wither) - } - - async fn find_one_and_update(query: Document, update: Document) -> Result, Error> { - let connection = database::connection().await; - let options = FindOneAndUpdateOptions::builder() - .return_document(ReturnDocument::After) - .build(); - - ::find_one_and_update(connection, query, update, options) - .await - .map_err(Error::Wither) - } - - async fn update_one( - query: Document, - update: Document, - options: O, - ) -> Result - where - O: Into> + Send, - { - let connection = database::connection().await; - Self::collection(connection) - .update_one(query, update, options) - .await - .map_err(Error::Mongo) - } - - async fn update_many( - query: Document, - update: Document, - options: O, - ) -> Result - where - O: Into> + Send, - { - let connection = database::connection().await; - Self::collection(connection) - .update_many(query, update, options) - .await - .map_err(Error::Mongo) - } - - async fn delete_many(query: Document) -> Result { - let connection = database::connection().await; - ::delete_many(connection, query, None) - .await - .map_err(Error::Wither) - } - - async fn delete_one(query: Document) -> Result { - let connection = database::connection().await; - Self::collection(connection) - .delete_one(query, None) - .await - .map_err(Error::Mongo) - } - - async fn count(query: Document) -> Result { - let connection = database::connection().await; - Self::collection(connection) - .count_documents(query, None) - .await - .map_err(Error::Mongo) - } - - async fn exists(query: Document) -> Result { - let connection = database::connection().await; - let count = Self::collection(connection) - .count_documents(query, None) - .await - .map_err(Error::Mongo)?; - - Ok(count > 0) - } - - async fn aggregate(pipeline: Vec) -> Result, Error> - where - A: Serialize + DeserializeOwned, - { - let connection = database::connection().await; - - let documents = Self::collection(connection) - .aggregate(pipeline, None) - .await - .map_err(Error::Mongo)? - .try_collect::>() - .await - .map_err(Error::Mongo)?; - - let documents = documents - .into_iter() - .map(|document| from_bson::(Bson::Document(document))) - .collect::, bson::de::Error>>() - .map_err(Error::SerializeMongoResponse)?; - - Ok(documents) - } - - async fn sync_indexes() -> Result<(), Error> { - let connection = database::connection().await; - Self::sync(connection).await.map_err(Error::Wither) - } -}