From de297491a708e436efaaaf5a2e2b4cf8a75d41b7 Mon Sep 17 00:00:00 2001 From: MikeMoolenaar Date: Thu, 14 Mar 2024 21:27:52 +0100 Subject: [PATCH 1/5] Remove sqlx and use Libsql --- .env | 1 - .env.example | 2 + .env.temp | 2 + .gitignore | 3 +- Cargo.lock | 1500 +++++++++-------- Cargo.toml | 6 +- migrations/20231023175040_todos.sql | 4 +- migrations/20231119144105_users.sql | 2 +- prepush.sh | 2 +- src/main.rs | 46 +- src/models/todo_item.rs | 12 +- src/models/user.rs | 2 +- src/render_html.rs | 4 +- src/routes/auth/login.rs | 12 +- src/routes/auth/register/register.rs | 31 +- .../auth/register/register_email_validate.rs | 16 +- src/routes/index.rs | 13 +- src/routes/todos/create_todo.rs | 21 +- src/turso_helper.rs | 34 + 19 files changed, 973 insertions(+), 740 deletions(-) delete mode 100644 .env create mode 100644 .env.example create mode 100644 .env.temp create mode 100644 src/turso_helper.rs diff --git a/.env b/.env deleted file mode 100644 index be38441..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -DATABASE_URL="postgres://postgres:vewysecret@localhost:15432/rust-plus-htmx-test" diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..b47e713 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +DATABASE_URL="sqlite://..." +LIBSQL_AUTH_TOKEN="" diff --git a/.env.temp b/.env.temp new file mode 100644 index 0000000..33a6e43 --- /dev/null +++ b/.env.temp @@ -0,0 +1,2 @@ +DATABASE_URL="libsql://rust-api-plus-htmx-mikemoolenaar.turso.io" +LIBSQL_AUTH_TOKEN="eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJhIjoicnciLCJpYXQiOjE3MTA0NDI2NzIsImlkIjoiZjZjMWU3YjMtOGZmNy00MDdmLTk4ZTItYWJlMDI2ZWEwNjNiIn0.2KNEcgwlTkYhvXNVLGqrMQ3IqdEA1bHT0doZlMawsvxd5RjLvdqVgc9iJQSwcJw4zYwB31v3gGcUTh8B-XaeAQ" diff --git a/.gitignore b/.gitignore index b7301bf..4b3b773 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ /target -sqlite.db* +local.db* **/node_modules /static/output.css /static/dist .idea +.env .env.prod diff --git a/Cargo.lock b/Cargo.lock index 0b310a8..90a6342 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "ahash" version = "0.7.7" @@ -35,7 +46,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", - "getrandom", "once_cell", "version_check", "zerocopy", @@ -50,6 +60,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "allocator-api2" version = "0.2.16" @@ -71,6 +90,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + [[package]] name = "argon2" version = "0.5.3" @@ -84,33 +109,36 @@ dependencies = [ ] [[package]] -name = "async-trait" -version = "0.1.77" +name = "async-stream" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", + "async-stream-impl", + "futures-core", + "pin-project-lite", ] [[package]] -name = "atoi" -version = "2.0.0" +name = "async-stream-impl" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ - "num-traits", + "proc-macro2", + "quote", + "syn 2.0.48", ] [[package]] -name = "atomic-write-file" -version = "0.1.2" +name = "async-trait" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edcdbedc2236483ab103a53415653d6b4442ea6141baf1ffa85df29635e88436" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ - "nix", - "rand", + "proc-macro2", + "quote", + "syn 2.0.48", ] [[package]] @@ -119,6 +147,34 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "axum" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +dependencies = [ + "async-trait", + "axum-core 0.3.4", + "bitflags 1.3.2", + "bytes", + "futures-util", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower", + "tower-layer", + "tower-service", +] + [[package]] name = "axum" version = "0.7.4" @@ -126,14 +182,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.4.3", "axum-macros", "bytes", "futures-util", - "http", - "http-body", + "http 1.0.0", + "http-body 1.0.0", "http-body-util", - "hyper", + "hyper 1.1.0", "hyper-util", "itoa", "matchit", @@ -154,6 +210,23 @@ dependencies = [ "tracing", ] +[[package]] +name = "axum-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 0.2.12", + "http-body 0.4.6", + "mime", + "rustversion", + "tower-layer", + "tower-service", +] + [[package]] name = "axum-core" version = "0.4.3" @@ -163,8 +236,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 1.0.0", + "http-body 1.0.0", "http-body-util", "mime", "pin-project-lite", @@ -182,8 +255,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40f7051fdc094b6e5ea06cab9bca4b198c54dee4472a9419155f0ff19f19901e" dependencies = [ "async-trait", - "axum-core", - "http", + "axum-core 0.4.3", + "http 1.0.0", ] [[package]] @@ -234,6 +307,38 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bindgen" +version = "0.66.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" +dependencies = [ + "bitflags 2.4.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.48", + "which", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -245,9 +350,6 @@ name = "bitflags" version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" -dependencies = [ - "serde", -] [[package]] name = "bitvec" @@ -279,6 +381,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-padding" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.14.0" @@ -318,6 +429,18 @@ name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +dependencies = [ + "serde", +] + +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher", +] [[package]] name = "cc" @@ -328,6 +451,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -349,10 +481,25 @@ dependencies = [ ] [[package]] -name = "const-oid" -version = "0.9.6" +name = "cipher" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "clang-sys" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1" +dependencies = [ + "glob", + "libc", + "libloading", +] [[package]] name = "const-str" @@ -385,6 +532,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -400,21 +557,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" -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-deque" version = "0.8.5" @@ -434,15 +576,6 @@ dependencies = [ "crossbeam-utils", ] -[[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.19" @@ -519,17 +652,6 @@ dependencies = [ "matches", ] -[[package]] -name = "der" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" -dependencies = [ - "const-oid", - "pem-rfc7468", - "zeroize", -] - [[package]] name = "deranged" version = "0.3.11" @@ -547,7 +669,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", "subtle", ] @@ -558,12 +679,6 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - [[package]] name = "dtoa" version = "1.0.9" @@ -584,9 +699,6 @@ name = "either" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -dependencies = [ - "serde", -] [[package]] name = "equivalent" @@ -605,44 +717,22 @@ dependencies = [ ] [[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 = "2.0.1" +name = "fallible-iterator" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] -name = "finl_unicode" -version = "1.2.0" +name = "fallible-iterator" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" +checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" [[package]] -name = "flume" -version = "0.11.0" +name = "fallible-streaming-iterator" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" -dependencies = [ - "futures-core", - "futures-sink", - "spin 0.9.8", -] +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" [[package]] name = "fnv" @@ -717,17 +807,6 @@ 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" @@ -817,6 +896,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "governor" version = "0.6.0" @@ -835,6 +920,25 @@ dependencies = [ "smallvec", ] +[[package]] +name = "h2" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.12", + "indexmap 2.2.2", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "h2" version = "0.4.2" @@ -846,8 +950,8 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", - "indexmap", + "http 1.0.0", + "indexmap 2.2.2", "slab", "tokio", "tokio-util", @@ -897,9 +1001,6 @@ name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] [[package]] name = "hermit-abi" @@ -907,30 +1008,6 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" -[[package]] -name = "hex" -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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "home" version = "0.5.9" @@ -949,6 +1026,17 @@ dependencies = [ "utf8-width", ] +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http" version = "1.0.0" @@ -960,6 +1048,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http 0.2.12", + "pin-project-lite", +] + [[package]] name = "http-body" version = "1.0.0" @@ -967,7 +1066,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http", + "http 1.0.0", ] [[package]] @@ -978,11 +1077,17 @@ checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" dependencies = [ "bytes", "futures-util", - "http", - "http-body", + "http 1.0.0", + "http-body 1.0.0", "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" + [[package]] name = "http-range-header" version = "0.4.0" @@ -1003,22 +1108,75 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "1.1.0" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", + "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.24", + "http 0.2.12", + "http-body 0.4.6", "httparse", "httpdate", "itoa", "pin-project-lite", + "socket2", "tokio", -] + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.2", + "http 1.0.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "hyper-rustls" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +dependencies = [ + "futures-util", + "http 0.2.12", + "hyper 0.14.28", + "log", + "rustls", + "rustls-native-certs", + "tokio", + "tokio-rustls", + "webpki-roots", +] + +[[package]] +name = "hyper-timeout" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +dependencies = [ + "hyper 0.14.28", + "pin-project-lite", + "tokio", + "tokio-io-timeout", +] [[package]] name = "hyper-util" @@ -1028,9 +1186,9 @@ checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" dependencies = [ "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.1.0", "pin-project-lite", "socket2", "tokio", @@ -1060,13 +1218,13 @@ dependencies = [ ] [[package]] -name = "idna" -version = "0.5.0" +name = "indexmap" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "autocfg", + "hashbrown 0.12.3", ] [[package]] @@ -1079,6 +1237,16 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "block-padding", + "generic-array", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1117,9 +1285,12 @@ 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 = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" @@ -1128,20 +1299,136 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] -name = "libm" -version = "0.2.8" +name = "libloading" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if", + "windows-targets 0.52.0", +] + +[[package]] +name = "libsql" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27798e66397bc976ce3d90db2c94c6ab9c67c48e54fc329d9491e641d9982a82" +dependencies = [ + "anyhow", + "async-stream", + "async-trait", + "base64", + "bincode", + "bitflags 2.4.2", + "bytes", + "fallible-iterator 0.3.0", + "futures", + "http 0.2.12", + "hyper 0.14.28", + "hyper-rustls", + "libsql-sqlite3-parser", + "libsql-sys", + "libsql_replication", + "parking_lot", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", + "tokio-util", + "tonic", + "tonic-web", + "tower", + "tower-http 0.4.4", + "tracing", + "uuid", + "zerocopy", +] + +[[package]] +name = "libsql-ffi" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f67a0b0c6585ed06d48bfb2fd702a826065420e602fa34f8eb6e3a44e26520b9" +dependencies = [ + "bindgen", + "cc", +] + +[[package]] +name = "libsql-rusqlite" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "6227e9be9b8cb061692babbcdc7ab268a8df3517d5b377f1d603cfdc9cafe12a" +dependencies = [ + "bitflags 2.4.2", + "fallible-iterator 0.2.0", + "fallible-streaming-iterator", + "hashlink", + "libsql-ffi", + "smallvec", +] [[package]] -name = "libsqlite3-sys" -version = "0.27.0" +name = "libsql-sqlite3-parser" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +checksum = "095d2cf702a5c9c152e48b369f69da30cc44351fa9432621dd8976834abc1752" dependencies = [ + "bitflags 2.4.2", "cc", - "pkg-config", - "vcpkg", + "fallible-iterator 0.3.0", + "indexmap 2.2.2", + "log", + "memchr", + "phf 0.11.2", + "phf_codegen 0.11.2", + "phf_shared 0.11.2", + "smallvec", + "uncased", +] + +[[package]] +name = "libsql-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e260ef2a25e4d75bad7a45355a7f777429e59bf0867bbe43322cdc8d9eada774" +dependencies = [ + "base64", + "bytes", + "libsql-ffi", + "libsql-rusqlite", + "once_cell", + "prost", + "serde", + "tracing", + "zerocopy", +] + +[[package]] +name = "libsql_replication" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d064663c7ad1d2471c6a54decee33b4d6d2c5bc4daa2c73f7e48584998f653e" +dependencies = [ + "aes", + "async-stream", + "async-trait", + "bytes", + "cbc", + "libsql-rusqlite", + "libsql-sys", + "parking_lot", + "prost", + "serde", + "thiserror", + "tokio", + "tokio-stream", + "tokio-util", + "tonic", + "tracing", + "uuid", + "zerocopy", ] [[package]] @@ -1212,16 +1499,6 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" -[[package]] -name = "md-5" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" -dependencies = [ - "cfg-if", - "digest", -] - [[package]] name = "memchr" version = "2.7.1" @@ -1256,7 +1533,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cd4517942a8e7425c990b14977f86a63e4996eed7b15cfcca1540126ac5ff25" dependencies = [ - "aho-corasick", + "aho-corasick 0.7.20", "lazy_static", "lightningcss", "memchr", @@ -1272,7 +1549,7 @@ version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "697a6b40dffdc5de10c0cbd709dc2bc2039cea9dab8aaa636eb9a49d6b411780" dependencies = [ - "aho-corasick", + "aho-corasick 0.7.20", "itertools 0.12.1", "lazy_static", "memchr", @@ -1329,17 +1606,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "nix" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" -dependencies = [ - "bitflags 2.4.2", - "cfg-if", - "libc", -] - [[package]] name = "no-std-compat" version = "0.4.1" @@ -1368,50 +1634,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" -[[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-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.17" @@ -1419,7 +1647,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -1447,6 +1674,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + [[package]] name = "outref" version = "0.1.0" @@ -1464,7 +1697,7 @@ dependencies = [ "fxhash", "log", "phf 0.10.1", - "phf_codegen", + "phf_codegen 0.10.0", "precomputed-hash", "smallvec", ] @@ -1512,7 +1745,7 @@ version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ec3b11d443640ec35165ee8f6f0559f1c6f41878d70330fe9187012b5935f02" dependencies = [ - "aho-corasick", + "aho-corasick 0.7.20", "bumpalo", "hashbrown 0.13.2", "lazy_static", @@ -1543,13 +1776,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" [[package]] -name = "pem-rfc7468" -version = "0.7.0" +name = "peeking_take_while" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "percent-encoding" @@ -1586,6 +1816,16 @@ dependencies = [ "phf_shared 0.10.0", ] +[[package]] +name = "phf_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" +dependencies = [ + "phf_generator 0.11.2", + "phf_shared 0.11.2", +] + [[package]] name = "phf_generator" version = "0.10.0" @@ -1635,6 +1875,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ "siphasher", + "uncased", ] [[package]] @@ -1669,33 +1910,6 @@ 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.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" - [[package]] name = "powerfmt" version = "0.2.0" @@ -1714,6 +1928,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "prettyplease" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" +dependencies = [ + "proc-macro2", + "syn 2.0.48", +] + [[package]] name = "proc-macro2" version = "1.0.78" @@ -1723,6 +1947,29 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prost" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" +dependencies = [ + "bytes", + "prost-derive", +] + +[[package]] +name = "prost-derive" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" +dependencies = [ + "anyhow", + "itertools 0.10.5", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "ptr_meta" version = "0.1.4" @@ -1842,6 +2089,35 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick 1.1.2", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick 1.1.2", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "rend" version = "0.4.1" @@ -1851,6 +2127,21 @@ dependencies = [ "bytecheck", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rkyv" version = "0.7.43" @@ -1903,47 +2194,27 @@ dependencies = [ ] [[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-plus-htmx-playground" -version = "0.1.0" +name = "rust-plus-htmx-playground" +version = "0.1.0" dependencies = [ "argon2", - "axum", + "axum 0.7.4", "axum-htmx", "chrono", "dotenv", "html-escape", + "libsql", "minify-html", "minijinja", "rand", "serde", - "sqlx", "time", "tokio", "tower", - "tower-http", + "tower-http 0.5.1", "tower-livereload", "tower-sessions", - "tower-sessions-sqlx-store", + "tower-sessions-libsql-store", "tower_governor", ] @@ -1972,6 +2243,49 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.21.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -1984,18 +2298,60 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + [[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.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "self_cell" version = "1.0.3" @@ -2056,26 +2412,10 @@ dependencies = [ ] [[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sha2" -version = "0.10.8" +name = "shlex" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" @@ -2086,16 +2426,6 @@ 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 = "simd-abstraction" version = "0.7.1" @@ -2142,253 +2472,11 @@ dependencies = [ "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 0.12.1", - "nom", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dba03c279da73694ef99763320dea58b51095dfe87d001b1d4b5fe78ba8763cf" -dependencies = [ - "sqlx-core", - "sqlx-macros", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", -] - -[[package]] -name = "sqlx-core" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d84b0a3c3739e220d94b3239fd69fb1f74bc36e16643423bd99de3b43c21bfbd" -dependencies = [ - "ahash 0.8.7", - "atoi", - "byteorder", - "bytes", - "crc", - "crossbeam-queue", - "dotenvy", - "either", - "event-listener", - "futures-channel", - "futures-core", - "futures-intrusive", - "futures-io", - "futures-util", - "hashlink", - "hex", - "indexmap", - "log", - "memchr", - "once_cell", - "paste", - "percent-encoding", - "serde", - "serde_json", - "sha2", - "smallvec", - "sqlformat", - "thiserror", - "time", - "tokio", - "tokio-stream", - "tracing", - "url", -] - -[[package]] -name = "sqlx-macros" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89961c00dc4d7dffb7aee214964b065072bff69e36ddb9e2c107541f75e4f2a5" -dependencies = [ - "proc-macro2", - "quote", - "sqlx-core", - "sqlx-macros-core", - "syn 1.0.109", -] - -[[package]] -name = "sqlx-macros-core" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0bd4519486723648186a08785143599760f7cc81c52334a55d6a83ea1e20841" -dependencies = [ - "atomic-write-file", - "dotenvy", - "either", - "heck", - "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 = "sqlx-mysql" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e37195395df71fd068f6e2082247891bc11e3289624bbc776a0cdfa1ca7f1ea4" -dependencies = [ - "atoi", - "base64", - "bitflags 2.4.2", - "byteorder", - "bytes", - "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", - "serde", - "sha1", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "time", - "tracing", - "whoami", -] - -[[package]] -name = "sqlx-postgres" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ac0ac3b7ccd10cc96c7ab29791a7dd236bd94021f31eec7ba3d46a74aa1c24" -dependencies = [ - "atoi", - "base64", - "bitflags 2.4.2", - "byteorder", - "crc", - "dotenvy", - "etcetera", - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "hex", - "hkdf", - "hmac", - "home", - "itoa", - "log", - "md-5", - "memchr", - "once_cell", - "rand", - "serde", - "serde_json", - "sha1", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "time", - "tracing", - "whoami", -] - -[[package]] -name = "sqlx-sqlite" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "210976b7d948c7ba9fced8ca835b11cbb2d677c59c79de41ac0d397e14547490" -dependencies = [ - "atoi", - "flume", - "futures-channel", - "futures-core", - "futures-executor", - "futures-intrusive", - "futures-util", - "libsqlite3-sys", - "log", - "percent-encoding", - "serde", - "sqlx-core", - "time", - "tracing", - "url", - "urlencoding", -] - -[[package]] -name = "stringprep" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" -dependencies = [ - "finl_unicode", - "unicode-bidi", - "unicode-normalization", -] [[package]] name = "subtle" @@ -2430,33 +2518,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "tempfile" -version = "3.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" -dependencies = [ - "cfg-if", - "fastrand", - "redox_syscall", - "rustix", - "windows-sys 0.52.0", -] - [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", @@ -2465,9 +2540,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.33" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b24b79b7a07f10209f19e683ca1e289d80b1e76ffa8c2b779718566a083679" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ "deranged", "itoa", @@ -2528,6 +2603,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "tokio-io-timeout" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" +dependencies = [ + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-macros" version = "2.2.0" @@ -2539,6 +2624,16 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls", + "tokio", +] + [[package]] name = "tokio-stream" version = "0.1.14" @@ -2564,6 +2659,58 @@ dependencies = [ "tracing", ] +[[package]] +name = "tonic" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e" +dependencies = [ + "async-stream", + "async-trait", + "axum 0.6.20", + "base64", + "bytes", + "h2 0.3.24", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", + "hyper-timeout", + "percent-encoding", + "pin-project", + "prost", + "rustls", + "rustls-native-certs", + "rustls-pemfile", + "tokio", + "tokio-rustls", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", + "webpki-roots", +] + +[[package]] +name = "tonic-web" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fddb2a37b247e6adcb9f239f4e5cefdcc5ed526141a416b943929f13aea2cce" +dependencies = [ + "base64", + "bytes", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", + "pin-project", + "tokio-stream", + "tonic", + "tower-http 0.4.4", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower" version = "0.4.13" @@ -2572,9 +2719,13 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", + "indexmap 1.9.3", "pin-project", "pin-project-lite", + "rand", + "slab", "tokio", + "tokio-util", "tower-layer", "tower-service", "tracing", @@ -2587,16 +2738,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fd0118512cf0b3768f7fcccf0bef1ae41d68f2b45edc1e77432b36c97c56c6d" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.4.3", "cookie", "futures-util", - "http", + "http 1.0.0", "parking_lot", "pin-project-lite", "tower-layer", "tower-service", ] +[[package]] +name = "tower-http" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" +dependencies = [ + "bitflags 2.4.2", + "bytes", + "futures-core", + "futures-util", + "http 0.2.12", + "http-body 0.4.6", + "http-range-header 0.3.1", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower-http" version = "0.5.1" @@ -2606,10 +2777,10 @@ dependencies = [ "bitflags 2.4.2", "bytes", "futures-util", - "http", - "http-body", + "http 1.0.0", + "http-body 1.0.0", "http-body-util", - "http-range-header", + "http-range-header 0.4.0", "httpdate", "mime", "mime_guess", @@ -2635,8 +2806,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1e74a1dba7fccc96d1ea1fe8abe0ad8e9b84fb1d55ddefc7bc9da3b0681dc73" dependencies = [ "bytes", - "http", - "http-body", + "http 1.0.0", + "http-body 1.0.0", "pin-project-lite", "tokio", "tower", @@ -2650,12 +2821,12 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tower-sessions" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16c5f8194d71a7a61275e3c6dd0685b94b378df4c6be31678d697194719949eb" +checksum = "f3db9ccda3dabcbaad83dda82d9486eaa0a6983fe0cecfe113087a990cd240e1" dependencies = [ "async-trait", - "http", + "http 1.0.0", "time", "tokio", "tower-cookies", @@ -2668,15 +2839,15 @@ dependencies = [ [[package]] name = "tower-sessions-core" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1582edecb18d4bfadb598edc1c3c70d06a2206a50ae1860cf41bee81ae9c8cc9" +checksum = "bc792f6a4179356f9093447edebe14bb73dbc99be636886281313cb98b47201b" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.4.3", "base64", "futures", - "http", + "http 1.0.0", "parking_lot", "rand", "serde", @@ -2688,28 +2859,28 @@ dependencies = [ ] [[package]] -name = "tower-sessions-memory-store" -version = "0.10.1" +name = "tower-sessions-libsql-store" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "476cc714e59e6aeee9f11d7ffd3b1dad5fb749440ec80050f0198766909c9423" +checksum = "2925fe78b5985956756337b2c822b567a8fdc262f4d9152cb48cceb5541e663b" dependencies = [ "async-trait", + "libsql", + "rmp-serde", + "thiserror", "time", - "tokio", "tower-sessions-core", ] [[package]] -name = "tower-sessions-sqlx-store" -version = "0.10.0" +name = "tower-sessions-memory-store" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93bb337be75252391f9cff681fac300fa9df91bdccdc00c88c88b174637b00d" +checksum = "4d780288cc38a7f001b39a22392c29b1398bda163c846f07b1253713042bc549" dependencies = [ "async-trait", - "rmp-serde", - "sqlx", - "thiserror", "time", + "tokio", "tower-sessions-core", ] @@ -2719,10 +2890,10 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d31d2cd0776b0e10664d3db2e362b9a8b38a18cb09ba97d3f2f775c54f2c51b" dependencies = [ - "axum", + "axum 0.7.4", "forwarded-header-value", "governor", - "http", + "http 1.0.0", "pin-project", "thiserror", "tower", @@ -2761,6 +2932,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.17.0" @@ -2768,19 +2945,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] -name = "unicase" -version = "2.7.0" +name = "uncased" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +checksum = "e1b88fcfe09e89d3866a5c11019378088af2d24c3fbd4f0543f96b479ec90697" dependencies = [ "version_check", ] [[package]] -name = "unicode-bidi" -version = "0.3.15" +name = "unicase" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] [[package]] name = "unicode-ident" @@ -2789,42 +2969,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "unicode-normalization" -version = "0.1.22" +name = "untrusted" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-segmentation" -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 = "url" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "utf8-width" @@ -2837,6 +2985,10 @@ name = "uuid" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" +dependencies = [ + "getrandom", + "serde", +] [[package]] name = "v_htmlescape" @@ -2844,12 +2996,6 @@ version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e8257fbc510f0a46eb602c10215901938b5c2a7d5e70fc11483b1d3c9b5b18c" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -2862,6 +3008,15 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65dd7eed29412da847b0f78bcec0ac98588165988a8cfe41d4ea1d429f8ccfff" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2933,10 +3088,22 @@ dependencies = [ ] [[package]] -name = "whoami" -version = "1.4.1" +name = "webpki-roots" +version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] [[package]] name = "winapi" @@ -3116,6 +3283,7 @@ version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ + "byteorder", "zerocopy-derive", ] @@ -3129,9 +3297,3 @@ dependencies = [ "quote", "syn 2.0.48", ] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/Cargo.toml b/Cargo.toml index 98c0396..09216eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ tokio = { version = "1.36.0", features = ["full"] } tower-http = { version = "0.5", features = ["fs","set-header"] } serde = { version = "1.0.196", features = ["derive"] } rand = "0.8" -sqlx = { version = "0.7.3", features = [ "runtime-tokio", "postgres" ] } chrono = "0.4.33" html-escape = "0.2.13" dotenv = "0.15.0" @@ -21,7 +20,8 @@ minijinja = { version = "1.0.12", features = ["loader", "v_htmlescape", "multi_t axum-htmx = "0.5.0" tower-livereload = "0.9.1" argon2 = "0.5.3" -tower-sessions = { version = "0.10.1" } -tower-sessions-sqlx-store = { version = "0.10.0", features = ["postgres"] } +tower-sessions = "0.10.1" +tower-sessions-libsql-store = "0.1.0" time = "0.3.33" minify-html = "0.15.0" +libsql = "0.3.1" diff --git a/migrations/20231023175040_todos.sql b/migrations/20231023175040_todos.sql index 9e3064b..d0731e4 100644 --- a/migrations/20231023175040_todos.sql +++ b/migrations/20231023175040_todos.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS todos ( - id SERIAL PRIMARY KEY, + id INTEGER PRIMARY KEY, title VARCHAR(250) NOT NULL, - date bigint NOT NULL, + date BIGINT NOT NULL, user_id INTEGER NOT NULL ) diff --git a/migrations/20231119144105_users.sql b/migrations/20231119144105_users.sql index fcee822..6b10546 100644 --- a/migrations/20231119144105_users.sql +++ b/migrations/20231119144105_users.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS users ( - id SERIAL PRIMARY KEY, + id INTEGER PRIMARY KEY, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, created_at bigint NOT NULL diff --git a/prepush.sh b/prepush.sh index 72bb167..ed71593 100755 --- a/prepush.sh +++ b/prepush.sh @@ -1,2 +1,2 @@ cargo +nightly fmt -cargo clippy --fix --allow-dirty -- -A clippy::needless_return +cargo clippy --fix --allow-dirty --allow-staged -- -A clippy::needless_return diff --git a/src/main.rs b/src/main.rs index b016512..4458e30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,24 +5,25 @@ use axum::{ Router, }; use dotenv::dotenv; +use libsql::{Builder, Connection}; use minijinja::{path_loader, Environment}; -use sqlx::{migrate::MigrateDatabase, postgres::PgPoolOptions, Pool, Postgres}; use std::{env, net::SocketAddr, sync::Arc, time::Duration}; use tower::ServiceBuilder; use tower_governor::{governor::GovernorConfigBuilder, GovernorLayer}; use tower_http::{services::ServeDir, set_header::SetResponseHeaderLayer}; use tower_livereload::LiveReloadLayer; use tower_sessions::{cookie::SameSite, session_store::ExpiredDeletion, Expiry, SessionManagerLayer}; -use tower_sessions_sqlx_store::PostgresStore; +use tower_sessions_libsql_store::LibsqlStore; mod filters; mod models; mod render_html; mod routes; mod serde_converters; +mod turso_helper; pub struct AppState { - db: Pool, + db_conn: Connection, } fn not_htmx_predicate(req: &Request) -> bool { @@ -35,23 +36,32 @@ async fn main() { // Connect to DB let db_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); - Postgres::database_exists(&db_url) - .await - .expect("Database should exist, run `cargo sqlx database setup`"); - let db_pool = PgPoolOptions::new() - .max_connections(5) - .connect(&db_url) + let db_token = env::var("LIBSQL_AUTH_TOKEN").expect("TOKEN must be set"); + + // Setup database + let db = Builder::new_remote_replica("local.db", db_url, db_token) + .sync_interval(Duration::from_secs(60)) + .build() .await .expect("Could not connect to database"); - sqlx::migrate!("./migrations") - .run(&db_pool.clone()) - .await - .expect("Could not run migrations"); + let conn = db.connect().unwrap(); + db.sync().await.unwrap(); + + // Loop over all files in dir migrations and run them + let migrations = std::fs::read_dir("migrations").unwrap(); + for migration in migrations { + let path = migration.unwrap().path(); + if path.is_file() { + let content = std::fs::read_to_string(path.clone()).unwrap(); + conn.execute(&content, ()).await.unwrap(); + println!("Ran migration: {}", path.display()); + } + } // Setup session store - let session_store = PostgresStore::new(db_pool.clone()); + let session_store = LibsqlStore::new(conn.clone()); session_store.migrate().await.expect("Could not migrate session store"); - tokio::task::spawn( + let _deletion_task = tokio::task::spawn( session_store .clone() .continuously_delete_expired(Duration::from_secs(60)), @@ -110,13 +120,14 @@ async fn main() { .layer(governor_layer) .layer(session_layer) .fallback(handle_page_404) - .with_state(Arc::new(AppState { db: db_pool.clone() })); + .with_state(Arc::new(AppState { db_conn: conn.clone() })); + // Add live reload in debug mode if cfg!(debug_assertions) { app = app.layer( LiveReloadLayer::new() .request_predicate(not_htmx_predicate) - .reload_interval(Duration::from_millis(100)), + .reload_interval(Duration::from_millis(300)), ) } @@ -126,4 +137,5 @@ async fn main() { axum::serve(listener, app.into_make_service_with_connect_info::()) .await .unwrap(); + // TODO add graeful shutdown for deletion_task } diff --git a/src/models/todo_item.rs b/src/models/todo_item.rs index 62959b0..98a8380 100644 --- a/src/models/todo_item.rs +++ b/src/models/todo_item.rs @@ -1,8 +1,8 @@ use crate::serde_converters; use serde::{Deserialize, Serialize}; -#[derive(Deserialize, Serialize, sqlx::FromRow)] -pub struct TodoItem { +#[derive(Deserialize, Serialize)] +pub struct TodoItemRequest { #[serde(default)] pub id: i64, #[serde(deserialize_with = "serde_converters::html_encode")] @@ -12,3 +12,11 @@ pub struct TodoItem { #[serde(default)] pub user_id: i64, } + +#[derive(Deserialize, Serialize)] +pub struct TodoItem { + pub id: i64, + pub title: String, + pub date: i64, + pub user_id: i64, +} diff --git a/src/models/user.rs b/src/models/user.rs index 8ab0786..c6aa74c 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, sqlx::FromRow)] +#[derive(Serialize, Deserialize)] pub struct User { #[serde(default)] pub id: i32, diff --git a/src/render_html.rs b/src/render_html.rs index fa36b1b..3728b43 100644 --- a/src/render_html.rs +++ b/src/render_html.rs @@ -4,6 +4,8 @@ use minijinja::{context, Environment}; use serde::ser::Serialize; use std::{error::Error, sync::OnceLock}; +pub static SHARED_JINJA_ENV: OnceLock = OnceLock::new(); + pub fn render_html(template_name: &str, context: S, boosted: bool) -> Option> { match render(template_name, "body", context, boosted) { Ok(html) => Some(html), @@ -24,8 +26,6 @@ pub fn render_block(template_name: &str, block_name: &str, context } } -pub static SHARED_JINJA_ENV: OnceLock = OnceLock::new(); - fn render( template_name: &str, block_name: &str, diff --git a/src/routes/auth/login.rs b/src/routes/auth/login.rs index cd3f0a9..1e1fffd 100644 --- a/src/routes/auth/login.rs +++ b/src/routes/auth/login.rs @@ -1,7 +1,8 @@ -use crate::{models::user::User, render_html::*, AppState}; +use crate::{models::user::User, render_html::*, turso_helper::fetch_optional, AppState}; use argon2::{password_hash::PasswordHash, Argon2, PasswordVerifier}; use axum::{extract::State, http::StatusCode, response::Html, Form}; use axum_htmx::{HxBoosted, HxLocation}; +use libsql::params; use minijinja::context; use serde::Deserialize; use std::{collections::HashMap, sync::Arc}; @@ -24,12 +25,11 @@ pub async fn login_post( ) -> (StatusCode, Option, Html) { let mut errors = HashMap::new(); - let user = sqlx::query_as!( - User, - "SELECT id, email, password, created_at FROM users WHERE email = $1", - form.email + let user = fetch_optional::( + &state.db_conn, + "SELECT id, email, password, created_at FROM users WHERE email = ?", + params![form.email.clone()], ) - .fetch_optional(&state.db) .await .unwrap(); diff --git a/src/routes/auth/register/register.rs b/src/routes/auth/register/register.rs index b561e8f..c733536 100644 --- a/src/routes/auth/register/register.rs +++ b/src/routes/auth/register/register.rs @@ -1,10 +1,11 @@ -use crate::{models::user::User, render_html::*, AppState}; +use crate::{models::user::User, render_html::*, turso_helper::*, AppState}; use argon2::{ password_hash::{rand_core::OsRng, PasswordHasher, SaltString}, Argon2, }; use axum::{extract::State, http::StatusCode, response::Html, Form}; use axum_htmx::HxBoosted; +use libsql::params; use minijinja::context; use serde::Deserialize; use std::{collections::HashMap, sync::Arc}; @@ -36,10 +37,14 @@ pub async fn register_post( errors.insert("password2", "Passwords do not match"); } - let email_exists = sqlx::query!("SELECT email FROM users WHERE email = $1", form.email) - .fetch_optional(&state.db) - .await - .unwrap(); + // TODO fetch is a little overkill, just use a count or something + let email_exists = fetch_optional::( + &state.db_conn, + "SELECT email FROM users WHERE email = $1", + params![form.email.clone()], + ) + .await + .unwrap(); if email_exists.is_some() { errors.insert("email", "Email already exists"); @@ -66,15 +71,13 @@ pub async fn register_post( created_at: 0, }; - let query_result = sqlx::query!( - "INSERT INTO users (email,password,created_at) VALUES ($1,$2,$3)", - user.email, - user.password, - chrono::Utc::now().timestamp() - ) - .execute(&state.db) - .await - .map_err(|err: sqlx::Error| err.to_string()); + let query_result = state + .db_conn + .execute( + "INSERT INTO users (email,password,created_at) VALUES (?, ?, ?)", + params![user.email, user.password, chrono::Utc::now().timestamp()], + ) + .await; if let Err(err) = query_result { println!("Could not execute insert due to error: {}", err); diff --git a/src/routes/auth/register/register_email_validate.rs b/src/routes/auth/register/register_email_validate.rs index 5836bae..9a5ebd8 100644 --- a/src/routes/auth/register/register_email_validate.rs +++ b/src/routes/auth/register/register_email_validate.rs @@ -1,9 +1,10 @@ -use crate::AppState; +use crate::{models::user::User, turso_helper::fetch_optional, AppState}; use axum::{ extract::{Query, State}, http::StatusCode, response::Html, }; +use libsql::params; use serde::Deserialize; use std::sync::Arc; @@ -15,10 +16,15 @@ pub async fn register_email_validate( State(state): State>, query: Query, ) -> (StatusCode, Html) { - let email_exists = sqlx::query!("SELECT email FROM users WHERE email = $1", query.email) - .fetch_optional(&state.db) - .await - .unwrap(); + // TODO fetch is a little overkill, just use a count or something + let email_exists = fetch_optional::( + &state.db_conn, + "SELECT email FROM users WHERE email = $1", + params![query.email.clone()], + ) + .await + .unwrap(); + if email_exists.is_some() { return ( StatusCode::BAD_REQUEST, diff --git a/src/routes/index.rs b/src/routes/index.rs index b69e8b8..65db73a 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -1,6 +1,7 @@ use crate::{ models::{todo_item::TodoItem, user::User}, render_html::*, + turso_helper::fetch_all, AppState, }; use axum::{ @@ -8,6 +9,7 @@ use axum::{ response::{IntoResponse, Response}, }; use axum_htmx::HxBoosted; +use libsql::params; use minijinja::context; use std::{sync::Arc, time::Instant}; use tower_sessions::Session; @@ -19,10 +21,13 @@ pub async fn index(session: Session, State(state): State>, HxBoost } let user = session_user.unwrap(); let now = Instant::now(); - let todos: Vec = sqlx::query_as!(TodoItem, "SELECT * FROM todos WHERE user_id = $1", user.id) - .fetch_all(&state.db) - .await - .unwrap(); + let todos: Vec = fetch_all::( + &state.db_conn, + "SELECT * FROM todos WHERE user_id = ?", + params![user.id], + ) + .await + .unwrap(); let elapsed = format!("{:?}", now.elapsed()); let context = context!(todos, user, elapsed); diff --git a/src/routes/todos/create_todo.rs b/src/routes/todos/create_todo.rs index ebf9f44..78b0f17 100644 --- a/src/routes/todos/create_todo.rs +++ b/src/routes/todos/create_todo.rs @@ -1,28 +1,27 @@ use crate::{ - models::{todo_item::TodoItem, user::User}, + models::{todo_item::TodoItemRequest, user::User}, AppState, }; use axum::{extract::State, http::StatusCode, response::IntoResponse, Form}; +use libsql::params; use std::sync::Arc; use tower_sessions::Session; pub async fn create_todo( session: Session, State(state): State>, - Form(form): Form, + Form(form): Form, ) -> Result { let title_clone = form.title.clone(); let user = session.get::("user").await.unwrap().unwrap(); - let query_result = sqlx::query!( - "INSERT INTO todos (title,date,user_id) VALUES ($1,$2,$3)", - form.title, - form.date, - user.id - ) - .execute(&state.db) - .await - .map_err(|err: sqlx::Error| err.to_string()); + let query_result = state + .db_conn + .execute( + "INSERT INTO todos (title,date,user_id) VALUES (?, ?, ?)", + params![form.title, form.date, user.id], + ) + .await; if let Err(err) = query_result { println!("Could not execute insert due to error: {}", err); diff --git a/src/turso_helper.rs b/src/turso_helper.rs new file mode 100644 index 0000000..075cb2e --- /dev/null +++ b/src/turso_helper.rs @@ -0,0 +1,34 @@ +use libsql::{de, params::IntoParams}; + +/** + * Query all rows and convert to Vec + */ +pub async fn fetch_all( + conn: &libsql::Connection, + sql: &str, + params: impl IntoParams, +) -> Result, Box> { + let mut result = conn.query(sql, params).await?; + + let mut results = Vec::::new(); + while let Ok(Some(row)) = result.next().await { + results.push(de::from_row::(&row)?); + } + return Ok(results); +} + +/** + * Query one row or None and convert to T + */ +#[allow(dead_code)] +pub async fn fetch_optional( + conn: &libsql::Connection, + sql: &str, + params: impl IntoParams, +) -> Result, Box> { + let mut result = conn.query(sql, params).await?; + if let Ok(Some(row)) = result.next().await { + return Ok(Some(de::from_row::(&row)?)); + } + return Ok(None); +} From ef402530a85c00bdaeacee924f3141ac4cf6b51a Mon Sep 17 00:00:00 2001 From: MikeMoolenaar Date: Thu, 14 Mar 2024 21:29:04 +0100 Subject: [PATCH 2/5] Oopsie --- .env.temp | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .env.temp diff --git a/.env.temp b/.env.temp deleted file mode 100644 index 33a6e43..0000000 --- a/.env.temp +++ /dev/null @@ -1,2 +0,0 @@ -DATABASE_URL="libsql://rust-api-plus-htmx-mikemoolenaar.turso.io" -LIBSQL_AUTH_TOKEN="eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJhIjoicnciLCJpYXQiOjE3MTA0NDI2NzIsImlkIjoiZjZjMWU3YjMtOGZmNy00MDdmLTk4ZTItYWJlMDI2ZWEwNjNiIn0.2KNEcgwlTkYhvXNVLGqrMQ3IqdEA1bHT0doZlMawsvxd5RjLvdqVgc9iJQSwcJw4zYwB31v3gGcUTh8B-XaeAQ" From 878ef84e3e96094cbfba8edbdb457015bfcb02ce Mon Sep 17 00:00:00 2001 From: MikeMoolenaar Date: Thu, 14 Mar 2024 21:32:55 +0100 Subject: [PATCH 3/5] Update .env.example --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index b47e713..30d6624 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,2 @@ -DATABASE_URL="sqlite://..." +DATABASE_URL="libsql://..." LIBSQL_AUTH_TOKEN="" From 8294424cb22a4acb30e37d9ef49179cde988a5cb Mon Sep 17 00:00:00 2001 From: MikeMoolenaar Date: Thu, 14 Mar 2024 22:14:12 +0100 Subject: [PATCH 4/5] Update DockerFile --- .dockerignore | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6384392..68f6260 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,4 @@ target -**/sqlite.db* +**/local.db* static/node_modules fly.toml diff --git a/Dockerfile b/Dockerfile index 3758277..2823d8e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,6 @@ COPY --from=planner /app/recipe.json recipe.json RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json # Build application -ENV SQLX_OFFLINE=true COPY . . RUN cargo build --release --target x86_64-unknown-linux-musl @@ -24,6 +23,7 @@ WORKDIR /app COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/rust-plus-htmx-playground /usr/local/bin COPY --from=builder /app/templates /app/templates COPY --from=builder /app/static /app/static +COPY --from=builder /app/migrations /app/migrations # Optionally copy the .env file COPY --from=builder /app/.env.prod* /app/.env From 8e688f9b8759650e79e40e21fc67c957dfee3396 Mon Sep 17 00:00:00 2001 From: MikeMoolenaar Date: Thu, 14 Mar 2024 22:16:31 +0100 Subject: [PATCH 5/5] Update TODO's --- src/main.rs | 2 +- src/routes/auth/register/register.rs | 2 +- src/routes/auth/register/register_email_validate.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4458e30..b466cb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -137,5 +137,5 @@ async fn main() { axum::serve(listener, app.into_make_service_with_connect_info::()) .await .unwrap(); - // TODO add graeful shutdown for deletion_task + // TODO: add graeful shutdown for deletion_task } diff --git a/src/routes/auth/register/register.rs b/src/routes/auth/register/register.rs index c733536..5557f94 100644 --- a/src/routes/auth/register/register.rs +++ b/src/routes/auth/register/register.rs @@ -37,7 +37,7 @@ pub async fn register_post( errors.insert("password2", "Passwords do not match"); } - // TODO fetch is a little overkill, just use a count or something + // TODO: fetch is a little overkill, just use a count or something let email_exists = fetch_optional::( &state.db_conn, "SELECT email FROM users WHERE email = $1", diff --git a/src/routes/auth/register/register_email_validate.rs b/src/routes/auth/register/register_email_validate.rs index 9a5ebd8..9b5fe3d 100644 --- a/src/routes/auth/register/register_email_validate.rs +++ b/src/routes/auth/register/register_email_validate.rs @@ -16,7 +16,7 @@ pub async fn register_email_validate( State(state): State>, query: Query, ) -> (StatusCode, Html) { - // TODO fetch is a little overkill, just use a count or something + // TODO: fetch is a little overkill, just use a count or something let email_exists = fetch_optional::( &state.db_conn, "SELECT email FROM users WHERE email = $1",