diff options
author | Teddy Wing | 2021-06-11 02:39:39 +0200 |
---|---|---|
committer | Teddy Wing | 2021-06-11 02:39:39 +0200 |
commit | 08c06d217cd2c63de4f032844d6d7856a0fb9657 (patch) | |
tree | 05c87375e5ad95f5f7cf687fa763695c0c2021c9 | |
parent | 5a115da66b98ce4604e98c47cbba0dcb617b5c10 (diff) | |
download | reflectub-08c06d217cd2c63de4f032844d6d7856a0fb9657.tar.bz2 |
Replace 'sqlx' with 'rusqlite'
Trying to get rid of async. This compiles, but fails with the following
runtime error:
Error code 21: Library used incorrectly
Need to investigate further.
-rw-r--r-- | Cargo.lock | 534 | ||||
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | src/database.rs | 173 | ||||
-rw-r--r-- | src/main.rs | 16 |
4 files changed, 127 insertions, 601 deletions
@@ -12,36 +12,12 @@ dependencies = [ ] [[package]] -name = "aho-corasick" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" -dependencies = [ - "memchr", -] - -[[package]] name = "anyhow" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" [[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "atoi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" -dependencies = [ - "num-traits", -] - -[[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -60,45 +36,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] -name = "bitvec" -version = "0.19.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - -[[package]] -name = "build_const" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" - -[[package]] name = "bumpalo" version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] name = "bytes" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -149,75 +92,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] -name = "cpufeatures" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed00c67cb5d0a7d64a44f6ad2668db7e7530311dd53ea79bcd4fb022c64911c8" -dependencies = [ - "libc", -] - -[[package]] -name = "crc" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" -dependencies = [ - "build_const", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-queue" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6cb3c7f5b8e51bc3ebb73a2327ad4abdbd119dc13223f14f961d2f38486756" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" -dependencies = [ - "cfg-if", - "lazy_static", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "dotenv" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] name = "encoding_rs" version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -233,6 +107,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193" [[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fallible-streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" + +[[package]] name = "filetime" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -276,12 +162,6 @@ dependencies = [ ] [[package]] -name = "funty" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" - -[[package]] name = "futures" version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -377,16 +257,6 @@ dependencies = [ ] [[package]] -name = "generic-array" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] name = "getopts" version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -465,15 +335,6 @@ dependencies = [ ] [[package]] -name = "heck" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" -dependencies = [ - "unicode-segmentation", -] - -[[package]] name = "hermit-abi" version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -483,12 +344,6 @@ dependencies = [ ] [[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] name = "http" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -581,15 +436,6 @@ dependencies = [ ] [[package]] -name = "instant" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" -dependencies = [ - "cfg-if", -] - -[[package]] name = "ipnet" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -626,19 +472,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] -name = "lexical-core" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" -dependencies = [ - "arrayvec", - "bitflags", - "cfg-if", - "ryu", - "static_assertions", -] - -[[package]] name = "libc" version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -664,7 +497,6 @@ version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d" dependencies = [ - "cc", "pkg-config", "vcpkg", ] @@ -696,15 +528,6 @@ dependencies = [ ] [[package]] -name = "lock_api" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" -dependencies = [ - "scopeguard", -] - -[[package]] name = "log" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -714,12 +537,6 @@ dependencies = [ ] [[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - -[[package]] name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -778,19 +595,6 @@ dependencies = [ ] [[package]] -name = "nom" -version = "6.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" -dependencies = [ - "bitvec", - "funty", - "lexical-core", - "memchr", - "version_check", -] - -[[package]] name = "ntapi" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -835,12 +639,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] name = "openssl" version = "0.10.34" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -874,31 +672,6 @@ dependencies = [ ] [[package]] -name = "parking_lot" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", -] - -[[package]] name = "parse-size" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -985,12 +758,6 @@ dependencies = [ ] [[package]] -name = "radium" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" - -[[package]] name = "rand" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1052,31 +819,14 @@ dependencies = [ "git2", "parse-size", "reqwest", + "rusqlite", "serde", - "sqlx", "thiserror", "tokio", "tokio-stream", ] [[package]] -name = "regex" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" - -[[package]] name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1121,31 +871,18 @@ dependencies = [ ] [[package]] -name = "ring" -version = "0.16.20" +name = "rusqlite" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +checksum = "57adcf67c8faaf96f3248c2a7b419a0dbc52ebe36ba83dd57fe83827c1ea4eb3" dependencies = [ - "cc", - "libc", - "once_cell", - "spin", - "untrusted", - "web-sys", - "winapi", -] - -[[package]] -name = "rustls" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" -dependencies = [ - "base64", - "log", - "ring", - "sct", - "webpki", + "bitflags", + "fallible-iterator", + "fallible-streaming-iterator", + "hashlink", + "libsqlite3-sys", + "memchr", + "smallvec", ] [[package]] @@ -1165,22 +902,6 @@ dependencies = [ ] [[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "sct" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] name = "security-framework" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1247,19 +968,6 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" -dependencies = [ - "block-buffer", - "cfg-if", - "cpufeatures", - "digest", - "opaque-debug", -] - -[[package]] name = "slab" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1282,126 +990,6 @@ dependencies = [ ] [[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "sqlformat" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d86e3c77ff882a828346ba401a7ef4b8e440df804491c6064fe8295765de71c" -dependencies = [ - "lazy_static", - "maplit", - "nom", - "regex", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba82f79b31f30acebf19905bcd8b978f46891b9d0723f578447361a8910b6584" -dependencies = [ - "sqlx-core", - "sqlx-macros", -] - -[[package]] -name = "sqlx-core" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f23af36748ec8ea8d49ef8499839907be41b0b1178a4e82b8cb45d29f531dc9" -dependencies = [ - "ahash", - "atoi", - "bitflags", - "byteorder", - "bytes", - "chrono", - "crc", - "crossbeam-channel", - "crossbeam-queue", - "crossbeam-utils", - "either", - "futures-channel", - "futures-core", - "futures-util", - "hashlink", - "hex", - "itoa", - "libc", - "libsqlite3-sys", - "log", - "memchr", - "once_cell", - "parking_lot", - "percent-encoding", - "rustls", - "sha2", - "smallvec", - "sqlformat", - "sqlx-rt", - "stringprep", - "thiserror", - "tokio-stream", - "url", - "webpki", - "webpki-roots", - "whoami", -] - -[[package]] -name = "sqlx-macros" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47e4a2349d1ffd60a03ca0de3f116ba55d7f406e55a0d84c64a5590866d94c06" -dependencies = [ - "dotenv", - "either", - "futures", - "heck", - "once_cell", - "proc-macro2", - "quote", - "sha2", - "sqlx-core", - "sqlx-rt", - "syn", - "url", -] - -[[package]] -name = "sqlx-rt" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8199b421ecf3493ee9ef3e7bc90c904844cfb2ea7ea2f57347a93f52bfd3e057" -dependencies = [ - "once_cell", - "tokio", - "tokio-rustls", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "stringprep" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] name = "syn" version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1413,12 +1001,6 @@ dependencies = [ ] [[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] name = "tempfile" version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1516,17 +1098,6 @@ dependencies = [ ] [[package]] -name = "tokio-rustls" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" -dependencies = [ - "rustls", - "tokio", - "webpki", -] - -[[package]] name = "tokio-stream" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1584,12 +1155,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] -name = "typenum" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" - -[[package]] name = "unicode-bidi" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1608,12 +1173,6 @@ dependencies = [ ] [[package]] -name = "unicode-segmentation" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" - -[[package]] name = "unicode-width" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1626,18 +1185,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[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 = "url" version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1756,35 +1303,6 @@ dependencies = [ ] [[package]] -name = "webpki" -version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" -dependencies = [ - "webpki", -] - -[[package]] -name = "whoami" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4abacf325c958dfeaf1046931d37f2a901b6dfe0968ee965a29e94c6766b2af6" -dependencies = [ - "wasm-bindgen", - "web-sys", -] - -[[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1814,9 +1332,3 @@ checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ "winapi", ] - -[[package]] -name = "wyz" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" @@ -13,11 +13,8 @@ getopts = "0.2.21" git2 = "0.13.20" parse-size = { version = "1.0.0", features = ["std"] } reqwest = { version = "0.11.3", features = ["json"] } +rusqlite = "0.25.3" serde = { version = "1.0.126", features = ["derive"] } thiserror = "1.0.25" tokio = { version = "1.6.1", features = ["macros", "rt-multi-thread"] } tokio-stream = "0.1.6" - -[dependencies.sqlx] -version = "0.5.5" -features = ["chrono", "runtime-tokio-rustls", "sqlite"] diff --git a/src/database.rs b/src/database.rs index 2c1c0c8..f23fcd4 100644 --- a/src/database.rs +++ b/src/database.rs @@ -16,7 +16,7 @@ // along with Reflectub. If not, see <https://www.gnu.org/licenses/>. -use sqlx::{self, ConnectOptions, Connection, Executor, Row}; +use rusqlite::{self, OptionalExtension}; use thiserror; use crate::github; @@ -54,59 +54,66 @@ impl From<&github::Repo> for Repo { #[derive(Debug, thiserror::Error)] pub enum Error { #[error("database error")] - Db(#[from] sqlx::Error), + Db(#[from] rusqlite::Error), } #[derive(Debug)] pub struct Db { - connection: sqlx::SqliteConnection, + connection: rusqlite::Connection, } impl Db { /// Open a connection to the database. - pub async fn connect(path: &str) -> Result<Self, Error> { + pub fn connect(path: &str) -> Result<Self, Error> { Ok( Db { - connection: sqlx::sqlite::SqliteConnectOptions::new() - .filename(path) - .create_if_missing(true) - .connect() - .await?, + connection: rusqlite::Connection::open_with_flags( + path, + rusqlite::OpenFlags::SQLITE_OPEN_CREATE, + )?, } ) } /// Initialise the database with tables and indexes. - pub async fn create(&mut self) -> Result<(), Error> { - let mut tx = self.connection.begin().await?; - - tx.execute(r#" - CREATE TABLE IF NOT EXISTS repositories ( - id INTEGER PRIMARY KEY, - name TEXT NOT NULL, - description TEXT, - updated_at TEXT NOT NULL - ); - "#).await?; - - tx.execute(r#" - CREATE UNIQUE INDEX IF NOT EXISTS idx_repositories_id - ON repositories (id); - "#).await?; - - tx.commit().await?; + pub fn create(&mut self) -> Result<(), Error> { + let tx = self.connection.transaction()?; + + tx.execute( + r#" + CREATE TABLE IF NOT EXISTS repositories ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + description TEXT, + updated_at TEXT NOT NULL + ); + "#, + [], + )?; + + tx.execute( + r#" + CREATE UNIQUE INDEX IF NOT EXISTS idx_repositories_id + ON repositories (id); + "#, + [], + )?; + + tx.commit()?; Ok(()) } /// Get a repository by its ID. /// - /// Returns a `sqlx::Error::RowNotFound` error if the row doesn't exist. - pub async fn repo_get(&mut self, id: i64) -> Result<Repo, Error> { - let mut tx = self.connection.begin().await?; + /// Returns a `rusqlite::Error::QueryReturnedNoRows` error if the row + /// doesn't exist. + pub fn repo_get(&mut self, id: i64) -> Result<Repo, Error> { + let tx = self.connection.transaction()?; - let row = sqlx::query(r#" + let repo = tx.query_row( + r#" SELECT id, name, @@ -114,41 +121,45 @@ impl Db { updated_at FROM repositories WHERE id = ? - "#) - .bind(id) - .fetch_one(&mut tx) - .await?; - - tx.commit().await?; - - Ok( - Repo { - id: row.get(0), - name: Some(row.get(1)), - description: row.get(2), - updated_at: Some(row.get(3)), - } - ) + "#, + [id], + |row| { + Ok( + Repo { + id: row.get(0)?, + name: Some(row.get(1)?), + description: row.get(2)?, + updated_at: Some(row.get(3)?), + } + ) + }, + )?; + + tx.commit()?; + + Ok(repo) } /// Insert a new repository. - pub async fn repo_insert(&mut self, repo: Repo) -> Result<(), Error> { - let mut tx = self.connection.begin().await?; + pub fn repo_insert(&mut self, repo: Repo) -> Result<(), Error> { + let tx = self.connection.transaction()?; - sqlx::query(r#" + tx.execute( + r#" INSERT INTO repositories (id, name, description, updated_at) VALUES (?, ?, ?, ?) - "#) - .bind(repo.id) - .bind(&repo.name) - .bind(&repo.description) - .bind(&repo.updated_at) - .execute(&mut tx) - .await?; + "#, + rusqlite::params![ + repo.id, + &repo.name, + &repo.description, + &repo.updated_at, + ], + )?; - tx.commit().await?; + tx.commit()?; Ok(()) } @@ -157,53 +168,59 @@ impl Db { /// /// Compares the `updated_at` field to find out whether the repository was /// updated. - pub async fn repo_is_updated( + pub fn repo_is_updated( &mut self, repo: &Repo, ) -> Result<bool, Error> { - let mut tx = self.connection.begin().await?; + let tx = self.connection.transaction()?; - let is_updated = match sqlx::query(r#" + let is_updated = match tx.query_row( + r#" SELECT 1 FROM repositories WHERE id = ? AND datetime(updated_at) < datetime(?) - "#) - .bind(repo.id) - .bind(&repo.updated_at) - .fetch_optional(&mut tx) - .await + "#, + rusqlite::params![ + repo.id, + &repo.updated_at, + ], + |row| row.get::<usize, u8>(0), + ) + .optional() { Ok(Some(_)) => Ok(true), Ok(None) => Ok(false), Err(e) => Err(e.into()), }; - tx.commit().await?; + tx.commit()?; is_updated } /// Update an existing repository. - pub async fn repo_update(&mut self, repo: &Repo) -> Result<(), Error> { - let mut tx = self.connection.begin().await?; + pub fn repo_update(&mut self, repo: &Repo) -> Result<(), Error> { + let tx = self.connection.transaction()?; - sqlx::query(r#" + tx.execute( + r#" UPDATE repositories SET name = ?, description = ?, updated_at = ? WHERE id = ? - "#) - .bind(&repo.name) - .bind(&repo.description) - .bind(&repo.updated_at) - .bind(repo.id) - .execute(&mut tx) - .await?; - - tx.commit().await?; + "#, + rusqlite::params![ + &repo.name, + &repo.description, + &repo.updated_at, + repo.id, + ], + )?; + + tx.commit()?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 6eb4492..3e17c06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ use filetime; // use futures::{self, executor, future}; use getopts::Options; use parse_size::parse_size; -use sqlx; +use rusqlite; use tokio; use tokio_stream::StreamExt; @@ -127,12 +127,12 @@ async fn run() -> anyhow::Result<()> { let db = Arc::new( tokio::sync::Mutex::new( - database::Db::connect(&database_file).await?, + database::Db::connect(&database_file)?, ) ); db.lock().await - .create().await?; + .create()?; // let mut joins = futures::stream::FuturesUnordered::new(); let mut joins = Vec::with_capacity(repos.len()); @@ -206,27 +206,27 @@ async fn process_repo( let path = clone_path(&mirror_root, &repo); let db_repo = database::Repo::from(repo); - match db.repo_get(id).await { + match db.repo_get(id) { // If we've already seen the repo and it's been updated, fetch the // latest. Ok(current_repo) => { - if db.repo_is_updated(&db_repo).await? { + if db.repo_is_updated(&db_repo)? { update(&path, ¤t_repo, &repo)?; - db.repo_update(&db_repo).await?; + db.repo_update(&db_repo)?; } }, // If the repo doesn't exist, mirror it and store it in the // database. - Err(database::Error::Db(sqlx::Error::RowNotFound)) => { + Err(database::Error::Db(rusqlite::Error::QueryReturnedNoRows)) => { mirror( &path, &repo, base_cgitrc.as_ref(), )?; - db.repo_insert(db_repo).await?; + db.repo_insert(db_repo)?; }, Err(e) => anyhow::bail!(e), |