diff --git a/.envrc b/.envrc index 5bf7d25..720b586 100644 --- a/.envrc +++ b/.envrc @@ -3,3 +3,5 @@ # SPDX-License-Identifier: AGPL-3.0-or-later use flake + +export SQLX_OFFLINE=true diff --git a/.reuse/dep5 b/.reuse/dep5 index 9d3d83f..526ed36 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -3,8 +3,6 @@ Upstream-Name: i7y Upstream-Contact: Simon Bruder Source: -# Sample paragraph, commented out: -# -# Files: src/* -# Copyright: $YEAR $NAME <$CONTACT> -# License: ... +Files: .sqlx/query-*.json +Copyright: 2024 Simon Bruder +License: AGPL-3.0-or-later diff --git a/.sqlx/query-05452db872d5ae8574a979b07d19c2b0791f3f2c4c0ae4777b2a2c309410d0ec.json b/.sqlx/query-05452db872d5ae8574a979b07d19c2b0791f3f2c4c0ae4777b2a2c309410d0ec.json new file mode 100644 index 0000000..d114826 --- /dev/null +++ b/.sqlx/query-05452db872d5ae8574a979b07d19c2b0791f3f2c4c0ae4777b2a2c309410d0ec.json @@ -0,0 +1,42 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO items (name, parent, class) VALUES ($1, $2, $3) RETURNING *", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + }, + { + "ordinal": 3, + "name": "class", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Varchar", + "Uuid", + "Uuid" + ] + }, + "nullable": [ + false, + true, + true, + false + ] + }, + "hash": "05452db872d5ae8574a979b07d19c2b0791f3f2c4c0ae4777b2a2c309410d0ec" +} diff --git a/.sqlx/query-08cce122c8eb9b390e5411cc08d2e735de7230a596fa2f2ba472bed6a9b4a75c.json b/.sqlx/query-08cce122c8eb9b390e5411cc08d2e735de7230a596fa2f2ba472bed6a9b4a75c.json new file mode 100644 index 0000000..7132e02 --- /dev/null +++ b/.sqlx/query-08cce122c8eb9b390e5411cc08d2e735de7230a596fa2f2ba472bed6a9b4a75c.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM items WHERE id = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [] + }, + "hash": "08cce122c8eb9b390e5411cc08d2e735de7230a596fa2f2ba472bed6a9b4a75c" +} diff --git a/.sqlx/query-1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204.json b/.sqlx/query-1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204.json new file mode 100644 index 0000000..c5e700a --- /dev/null +++ b/.sqlx/query-1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM items WHERE id = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + }, + { + "ordinal": 3, + "name": "class", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + true, + true, + false + ] + }, + "hash": "1e9045f52c002a19b815351fee1c7ee7520478ff4f5886b4523fb0dc4df0e204" +} diff --git a/.sqlx/query-2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b.json b/.sqlx/query-2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b.json new file mode 100644 index 0000000..6e1a26f --- /dev/null +++ b/.sqlx/query-2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM items WHERE parent = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + }, + { + "ordinal": 3, + "name": "class", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + true, + true, + false + ] + }, + "hash": "2e9619ce6db1047e2f5447c4925f28fd05f18706f70220b6ebb7354d2a0a9e3b" +} diff --git a/.sqlx/query-308962c26250f9312287a3f2f21e5da76e4cf488eedd4704019b4f14b6fbafb2.json b/.sqlx/query-308962c26250f9312287a3f2f21e5da76e4cf488eedd4704019b4f14b6fbafb2.json new file mode 100644 index 0000000..66eaa87 --- /dev/null +++ b/.sqlx/query-308962c26250f9312287a3f2f21e5da76e4cf488eedd4704019b4f14b6fbafb2.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM item_classes WHERE id = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + false, + true + ] + }, + "hash": "308962c26250f9312287a3f2f21e5da76e4cf488eedd4704019b4f14b6fbafb2" +} diff --git a/.sqlx/query-408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10.json b/.sqlx/query-408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10.json new file mode 100644 index 0000000..ab0620b --- /dev/null +++ b/.sqlx/query-408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10.json @@ -0,0 +1,36 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE item_classes SET name = $2, parent = $3 WHERE id = $1 RETURNING *", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid", + "Varchar", + "Uuid" + ] + }, + "nullable": [ + false, + false, + true + ] + }, + "hash": "408a171b46d5c615ff846547f463dc0b18360644234fb01b24c4c047bebb3a10" +} diff --git a/.sqlx/query-467dcd7fd379750cbf30a190d06dc1b3e61b1bd7ef288fbf6fbedec52c276434.json b/.sqlx/query-467dcd7fd379750cbf30a190d06dc1b3e61b1bd7ef288fbf6fbedec52c276434.json new file mode 100644 index 0000000..53d333c --- /dev/null +++ b/.sqlx/query-467dcd7fd379750cbf30a190d06dc1b3e61b1bd7ef288fbf6fbedec52c276434.json @@ -0,0 +1,38 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM items", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + }, + { + "ordinal": 3, + "name": "class", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + true, + true, + false + ] + }, + "hash": "467dcd7fd379750cbf30a190d06dc1b3e61b1bd7ef288fbf6fbedec52c276434" +} diff --git a/.sqlx/query-7a811ef54e617ed88ef9c7be88b48ca0da2204c64200ffa77a51f0c580f9ab87.json b/.sqlx/query-7a811ef54e617ed88ef9c7be88b48ca0da2204c64200ffa77a51f0c580f9ab87.json new file mode 100644 index 0000000..f1d4f96 --- /dev/null +++ b/.sqlx/query-7a811ef54e617ed88ef9c7be88b48ca0da2204c64200ffa77a51f0c580f9ab87.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM item_classes WHERE id = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [] + }, + "hash": "7a811ef54e617ed88ef9c7be88b48ca0da2204c64200ffa77a51f0c580f9ab87" +} diff --git a/.sqlx/query-7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78.json b/.sqlx/query-7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78.json new file mode 100644 index 0000000..c7661e1 --- /dev/null +++ b/.sqlx/query-7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78.json @@ -0,0 +1,35 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO item_classes (name, parent) VALUES ($1, $2) RETURNING *", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Varchar", + "Uuid" + ] + }, + "nullable": [ + false, + false, + true + ] + }, + "hash": "7e2e1460a2c946ba909c50d4cf1beacf50ebf5fbfead379340f9f72614958e78" +} diff --git a/.sqlx/query-85528d16361a6e736773e8f8aba4c85cfc7db545724d94c1a467b2c0c74b6b6e.json b/.sqlx/query-85528d16361a6e736773e8f8aba4c85cfc7db545724d94c1a467b2c0c74b6b6e.json new file mode 100644 index 0000000..4553886 --- /dev/null +++ b/.sqlx/query-85528d16361a6e736773e8f8aba4c85cfc7db545724d94c1a467b2c0c74b6b6e.json @@ -0,0 +1,43 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE items SET name = $2, parent = $3, class = $4 WHERE id = $1 RETURNING *", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + }, + { + "ordinal": 3, + "name": "class", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid", + "Varchar", + "Uuid", + "Uuid" + ] + }, + "nullable": [ + false, + true, + true, + false + ] + }, + "hash": "85528d16361a6e736773e8f8aba4c85cfc7db545724d94c1a467b2c0c74b6b6e" +} diff --git a/.sqlx/query-94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2.json b/.sqlx/query-94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2.json new file mode 100644 index 0000000..4266aae --- /dev/null +++ b/.sqlx/query-94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM items WHERE class = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + }, + { + "ordinal": 3, + "name": "class", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + true, + true, + false + ] + }, + "hash": "94958a3a57c3178e6b0de5723b1fbc5433e972b5522b367098afe6cb90a30bf2" +} diff --git a/.sqlx/query-97d6a7ee24e75dc5a9dc41a581e1013767fe36575c28574733c5ab5cbf557fb5.json b/.sqlx/query-97d6a7ee24e75dc5a9dc41a581e1013767fe36575c28574733c5ab5cbf557fb5.json new file mode 100644 index 0000000..cfbdff0 --- /dev/null +++ b/.sqlx/query-97d6a7ee24e75dc5a9dc41a581e1013767fe36575c28574733c5ab5cbf557fb5.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT unnest(parents) as \"parents!\" FROM item_tree WHERE id = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "parents!", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + null + ] + }, + "hash": "97d6a7ee24e75dc5a9dc41a581e1013767fe36575c28574733c5ab5cbf557fb5" +} diff --git a/.sqlx/query-a6f646089b4424deffc0b1a454bcfa2f2a497180e2517a937471f81a1f9c5538.json b/.sqlx/query-a6f646089b4424deffc0b1a454bcfa2f2a497180e2517a937471f81a1f9c5538.json new file mode 100644 index 0000000..666377d --- /dev/null +++ b/.sqlx/query-a6f646089b4424deffc0b1a454bcfa2f2a497180e2517a937471f81a1f9c5538.json @@ -0,0 +1,26 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id as \"id!\", parents as \"parents!\" FROM item_tree", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id!", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "parents!", + "type_info": "UuidArray" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + true, + true + ] + }, + "hash": "a6f646089b4424deffc0b1a454bcfa2f2a497180e2517a937471f81a1f9c5538" +} diff --git a/.sqlx/query-c552c0a40bc8995cb95726a85f1d0c0b86eb2322035e6a720e2e6d425072a8c1.json b/.sqlx/query-c552c0a40bc8995cb95726a85f1d0c0b86eb2322035e6a720e2e6d425072a8c1.json new file mode 100644 index 0000000..1d1eaa6 --- /dev/null +++ b/.sqlx/query-c552c0a40bc8995cb95726a85f1d0c0b86eb2322035e6a720e2e6d425072a8c1.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM item_classes WHERE parent = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + false, + true + ] + }, + "hash": "c552c0a40bc8995cb95726a85f1d0c0b86eb2322035e6a720e2e6d425072a8c1" +} diff --git a/.sqlx/query-dc197bce5f03ab1ab08391f54f960e63e935172b25e5a6835d51e786fb2f854e.json b/.sqlx/query-dc197bce5f03ab1ab08391f54f960e63e935172b25e5a6835d51e786fb2f854e.json new file mode 100644 index 0000000..f354f52 --- /dev/null +++ b/.sqlx/query-dc197bce5f03ab1ab08391f54f960e63e935172b25e5a6835d51e786fb2f854e.json @@ -0,0 +1,32 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM item_classes", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false, + true + ] + }, + "hash": "dc197bce5f03ab1ab08391f54f960e63e935172b25e5a6835d51e786fb2f854e" +} diff --git a/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json b/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json new file mode 100644 index 0000000..1de7df6 --- /dev/null +++ b/.sqlx/query-e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d.json @@ -0,0 +1,40 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM items WHERE id = ANY (SELECT unnest(parents) FROM item_tree WHERE id = $1)", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "parent", + "type_info": "Uuid" + }, + { + "ordinal": 3, + "name": "class", + "type_info": "Uuid" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + true, + true, + false + ] + }, + "hash": "e45160a73a18d870f592989349057d6852d2d3f63dc055442125a6a92950729d" +} diff --git a/Cargo.lock b/Cargo.lock index a331d21..4dea82f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,6 +265,12 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + [[package]] name = "allsorts" version = "0.14.2" @@ -348,14 +354,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] -name = "async-trait" -version = "0.1.80" +name = "atoi" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.68", + "num-traits", ] [[package]] @@ -397,6 +401,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bitflags" version = "1.3.2" @@ -408,6 +418,9 @@ name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +dependencies = [ + "serde", +] [[package]] name = "bitreader" @@ -519,6 +532,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "convert_case" version = "0.4.0" @@ -545,6 +564,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + [[package]] name = "crc32fast" version = "1.4.2" @@ -573,6 +607,15 @@ 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.20" @@ -589,41 +632,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "darling" -version = "0.20.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.20.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 2.0.68", -] - -[[package]] -name = "darling_macro" -version = "0.20.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" -dependencies = [ - "darling_core", - "quote", - "syn 2.0.68", -] - [[package]] name = "datamatrix" version = "0.3.1" @@ -635,22 +643,16 @@ dependencies = [ ] [[package]] -name = "deadpool" -version = "0.12.1" +name = "der" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6541a3916932fe57768d4be0b1ffb5ec7cbf74ca8c903fdfd5c0fe8aa958f0ed" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ - "deadpool-runtime", - "num_cpus", - "tokio", + "const-oid", + "pem-rfc7468", + "zeroize", ] -[[package]] -name = "deadpool-runtime" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" - [[package]] name = "deranged" version = "0.3.11" @@ -673,78 +675,6 @@ dependencies = [ "syn 2.0.68", ] -[[package]] -name = "diesel" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62d6dcd069e7b5fe49a302411f759d4cf1cf2c27fe798ef46fb8baefc053dd2b" -dependencies = [ - "bitflags 2.5.0", - "byteorder", - "diesel_derives", - "itoa", - "uuid", -] - -[[package]] -name = "diesel-async" -version = "0.4.1" -source = "git+https://github.com/weiznich/diesel_async.git#d2fc97dfd4c1a2b54ae07ee115a219be9993103b" -dependencies = [ - "async-trait", - "deadpool", - "diesel", - "futures-util", - "scoped-futures", - "tokio", - "tokio-postgres", -] - -[[package]] -name = "diesel-derive-enum" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81c5131a2895ef64741dad1d483f358c2a229a3a2d1b256778cdc5e146db64d4" -dependencies = [ - "heck 0.4.1", - "proc-macro2", - "quote", - "syn 2.0.68", -] - -[[package]] -name = "diesel_derives" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59de76a222c2b8059f789cbe07afbfd8deb8c31dd0bc2a21f85e256c1def8259" -dependencies = [ - "diesel_table_macro_syntax", - "dsl_auto_type", - "proc-macro2", - "quote", - "syn 2.0.68", -] - -[[package]] -name = "diesel_migrations" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a73ce704bad4231f001bff3314d91dce4aba0770cee8b233991859abc15c1f6" -dependencies = [ - "diesel", - "migrations_internals", - "migrations_macros", -] - -[[package]] -name = "diesel_table_macro_syntax" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" -dependencies = [ - "syn 2.0.68", -] - [[package]] name = "digest" version = "0.10.7" @@ -752,29 +682,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", "subtle", ] [[package]] -name = "dsl_auto_type" -version = "0.1.1" +name = "dotenvy" +version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0892a17df262a24294c382f0d5997571006e7a4348b4327557c4ff1cd4a8bccc" -dependencies = [ - "darling", - "either", - "heck 0.5.0", - "proc-macro2", - "quote", - "syn 2.0.68", -] +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" [[package]] name = "either" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +dependencies = [ + "serde", +] [[package]] name = "encoding_rs" @@ -815,10 +741,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] -name = "fallible-iterator" -version = "0.2.0" +name = "errno" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[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.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "flagset" @@ -836,6 +789,17 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flume" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" @@ -868,16 +832,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] -name = "futures-macro" +name = "futures-executor" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.68", + "futures-core", + "futures-task", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + [[package]] name = "futures-sink" version = "0.3.30" @@ -897,9 +878,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", - "futures-macro", + "futures-io", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", @@ -962,24 +944,43 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown", +] [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] [[package]] -name = "heck" -version = "0.5.0" +name = "hex" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "hkdf" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] [[package]] name = "hmac" @@ -990,6 +991,15 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.12" @@ -1025,12 +1035,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "idna" version = "0.5.0" @@ -1101,6 +1105,9 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] [[package]] name = "li7y" @@ -1110,10 +1117,6 @@ dependencies = [ "actix-web", "barcoders", "datamatrix", - "diesel", - "diesel-async", - "diesel-derive-enum", - "diesel_migrations", "env_logger", "log", "maud", @@ -1121,6 +1124,7 @@ dependencies = [ "printpdf", "rust-fontconfig", "serde", + "sqlx", "thiserror", "uuid", ] @@ -1131,12 +1135,35 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "libsqlite3-sys" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "local-channel" version = "0.1.5" @@ -1233,27 +1260,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "migrations_internals" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd01039851e82f8799046eabbb354056283fb265c8ec0996af940f4e85a380ff" -dependencies = [ - "serde", - "toml", -] - -[[package]] -name = "migrations_macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb161cc72176cb37aa47f1fc520d3ef02263d67d661f44f05d05a079e1237fd" -dependencies = [ - "migrations_internals", - "proc-macro2", - "quote", -] - [[package]] name = "mime" version = "0.3.17" @@ -1270,6 +1276,12 @@ dependencies = [ "unicase", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -1301,12 +1313,59 @@ dependencies = [ "winapi", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[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.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1314,16 +1373,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", + "libm", ] [[package]] @@ -1358,7 +1408,7 @@ version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec4c6225c69b4ca778c0aea097321a64c421cf4577b331c61b229267edabb6f8" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro-error", "proc-macro2", "quote", @@ -1403,30 +1453,21 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "phf" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_shared" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" -dependencies = [ - "siphasher", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -1439,6 +1480,27 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + [[package]] name = "pkg-config" version = "0.3.30" @@ -1454,35 +1516,6 @@ dependencies = [ "bstr", ] -[[package]] -name = "postgres-protocol" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b6c5ef183cd3ab4ba005f1ca64c21e8bd97ce4699cfea9e8d9a2c4958ca520" -dependencies = [ - "base64 0.21.7", - "byteorder", - "bytes", - "fallible-iterator", - "hmac", - "md-5", - "memchr", - "rand", - "sha2", - "stringprep", -] - -[[package]] -name = "postgres-types" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d2234cdee9408b523530a9b6d2d6b373d1db34f6a8e51dc03ded1828d7fb67c" -dependencies = [ - "bytes", - "fallible-iterator", - "postgres-protocol", -] - [[package]] name = "powerfmt" version = "0.2.0" @@ -1652,6 +1685,26 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[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-fontconfig" version = "0.1.7" @@ -1685,22 +1738,25 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "scoped-futures" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1473e24c637950c9bd38763220bea91ec3e095a89f672bbd7a10d03e77ba467" -dependencies = [ - "cfg-if", - "pin-utils", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1744,15 +1800,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_spanned" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" -dependencies = [ - "serde", -] - [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1797,10 +1844,14 @@ dependencies = [ ] [[package]] -name = "siphasher" -version = "0.3.11" +name = "signature" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] [[package]] name = "slab" @@ -1827,6 +1878,233 @@ dependencies = [ "windows-sys 0.52.0", ] +[[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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f895e3734318cc55f1fe66258926c9b910c124d47520339efecbb6c59cec7c1f" +dependencies = [ + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" +dependencies = [ + "ahash", + "atoi", + "byteorder", + "bytes", + "crc", + "crossbeam-queue", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashlink", + "hex", + "indexmap", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "sqlx-macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 1.0.109", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" +dependencies = [ + "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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.5.0", + "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", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" +dependencies = [ + "atoi", + "base64 0.21.7", + "bitflags 2.5.0", + "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", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" +dependencies = [ + "atoi", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core", + "tracing", + "url", + "urlencoding", + "uuid", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -1844,12 +2122,6 @@ dependencies = [ "unicode-properties", ] -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - [[package]] name = "subtle" version = "2.6.1" @@ -1863,6 +2135,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", + "quote", "unicode-ident", ] @@ -1877,6 +2150,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "thiserror" version = "1.0.61" @@ -1961,29 +2246,14 @@ dependencies = [ ] [[package]] -name = "tokio-postgres" -version = "0.7.10" +name = "tokio-stream" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d340244b32d920260ae7448cb72b6e238bddc3d4f7603394e7dd46ed8e48f5b8" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ - "async-trait", - "byteorder", - "bytes", - "fallible-iterator", - "futures-channel", - "futures-util", - "log", - "parking_lot", - "percent-encoding", - "phf", + "futures-core", "pin-project-lite", - "postgres-protocol", - "postgres-types", - "rand", - "socket2", "tokio", - "tokio-util", - "whoami", ] [[package]] @@ -1999,40 +2269,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml" -version = "0.8.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.22.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", -] - [[package]] name = "tracing" version = "0.1.40" @@ -2041,9 +2277,21 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -2125,6 +2373,18 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4259d9d4425d9f0661581b804cb85fe66a4c631cadd8f490d1c13a35d5d9291" +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[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.2" @@ -2136,6 +2396,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf8parse" version = "0.2.2" @@ -2158,6 +2424,12 @@ 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" @@ -2230,16 +2502,6 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" -[[package]] -name = "web-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "weezl" version = "0.1.8" @@ -2254,7 +2516,6 @@ checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" dependencies = [ "redox_syscall 0.4.1", "wasite", - "web-sys", ] [[package]] @@ -2418,15 +2679,6 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" -[[package]] -name = "winnow" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" -dependencies = [ - "memchr", -] - [[package]] name = "xmlparser" version = "0.13.6" @@ -2453,6 +2705,12 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + [[package]] name = "zstd" version = "0.13.1" diff --git a/Cargo.toml b/Cargo.toml index 6ba2869..fc0e3ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,6 @@ actix-files = "0.6.6" actix-web = "4.8.0" barcoders = { version = "2.0.0", default-features = false, features = ["std"] } datamatrix = "0.3.1" -diesel = { version = "2.2.1", features = ["uuid"] } -diesel-async = { git = "https://github.com/weiznich/diesel_async.git", version = "0.4.1", features = ["postgres", "deadpool", "async-connection-wrapper"] } -diesel-derive-enum = { version = "2.1.0", features = ["postgres"] } -diesel_migrations = { version = "2.2.0", features = ["postgres"] } env_logger = "0.11.3" log = "0.4.21" maud = { version = "0.26.0", features = ["actix-web"] } @@ -25,5 +21,9 @@ mime = "0.3.17" printpdf = "0.7.0" rust-fontconfig = "0.1.7" serde = { version = "1.0.203", features = ["serde_derive"] } +sqlx = { version = "0.7.4", features = ["runtime-tokio", "postgres", "uuid"] } thiserror = "1.0.61" uuid = { version = "1.9.0", features = ["serde", "v4"] } + +[profile.dev.package.sqlx-macros] +opt-level = 3 diff --git a/LICENSES/Apache-2.0.txt b/LICENSES/Apache-2.0.txt deleted file mode 100644 index 137069b..0000000 --- a/LICENSES/Apache-2.0.txt +++ /dev/null @@ -1,73 +0,0 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - - (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. - - You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - -To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/diesel.toml b/diesel.toml deleted file mode 100644 index 9e2faa8..0000000 --- a/diesel.toml +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-FileCopyrightText: 2024 Simon Bruder -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -# For documentation on how to configure this file, -# see https://diesel.rs/guides/configuring-diesel-cli - -[print_schema] -custom_type_derives = ["diesel::query_builder::QueryId"] - -[migrations_directory] -dir = "migrations" diff --git a/flake.nix b/flake.nix index 0496915..fb651e0 100644 --- a/flake.nix +++ b/flake.nix @@ -91,10 +91,10 @@ cargo-deny cargo-watch clippy - diesel-cli postgresql.lib postgresql reuse + sqlx-cli ]); shellHook = '' diff --git a/migrations/.keep b/migrations/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/migrations/00000000000000_diesel_initial_setup/down.sql b/migrations/00000000000000_diesel_initial_setup/down.sql deleted file mode 100644 index a776289..0000000 --- a/migrations/00000000000000_diesel_initial_setup/down.sql +++ /dev/null @@ -1,10 +0,0 @@ --- SPDX-FileCopyrightText: 2017 Sage Griffin --- --- SPDX-License-Identifier: Apache-2.0 OR MIT - --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - -DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); -DROP FUNCTION IF EXISTS diesel_set_updated_at(); diff --git a/migrations/00000000000000_diesel_initial_setup/up.sql b/migrations/00000000000000_diesel_initial_setup/up.sql deleted file mode 100644 index 0cadb18..0000000 --- a/migrations/00000000000000_diesel_initial_setup/up.sql +++ /dev/null @@ -1,41 +0,0 @@ --- SPDX-FileCopyrightText: 2017 Sage Griffin --- SPDX-FileCopyrightText: 2016 Robert Maloney --- --- SPDX-License-Identifier: Apache-2.0 OR MIT - --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - - - - --- Sets up a trigger for the given table to automatically set a column called --- `updated_at` whenever the row is modified (unless `updated_at` was included --- in the modified columns) --- --- # Example --- --- ```sql --- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); --- --- SELECT diesel_manage_updated_at('users'); --- ``` -CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ -BEGIN - EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s - FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ -BEGIN - IF ( - NEW IS DISTINCT FROM OLD AND - NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at - ) THEN - NEW.updated_at := current_timestamp; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; diff --git a/migrations/2024-06-24-153851_create_item/down.sql b/migrations/20240624153851_create_item.down.sql similarity index 100% rename from migrations/2024-06-24-153851_create_item/down.sql rename to migrations/20240624153851_create_item.down.sql diff --git a/migrations/2024-06-24-153851_create_item/up.sql b/migrations/20240624153851_create_item.up.sql similarity index 100% rename from migrations/2024-06-24-153851_create_item/up.sql rename to migrations/20240624153851_create_item.up.sql diff --git a/migrations/2024-07-03-122248_item_add_parent/down.sql b/migrations/20240703122248_item_add_parent.down.sql similarity index 100% rename from migrations/2024-07-03-122248_item_add_parent/down.sql rename to migrations/20240703122248_item_add_parent.down.sql diff --git a/migrations/2024-07-03-122248_item_add_parent/up.sql b/migrations/20240703122248_item_add_parent.up.sql similarity index 100% rename from migrations/2024-07-03-122248_item_add_parent/up.sql rename to migrations/20240703122248_item_add_parent.up.sql diff --git a/migrations/2024-07-05-104056_create_item_class/down.sql b/migrations/20240705104056_create_item_class.down.sql similarity index 100% rename from migrations/2024-07-05-104056_create_item_class/down.sql rename to migrations/20240705104056_create_item_class.down.sql diff --git a/migrations/2024-07-05-104056_create_item_class/up.sql b/migrations/20240705104056_create_item_class.up.sql similarity index 100% rename from migrations/2024-07-05-104056_create_item_class/up.sql rename to migrations/20240705104056_create_item_class.up.sql diff --git a/migrations/2024-07-09-133113_item_make_name_optional/down.sql b/migrations/20240709133113_item_make_name_optional.down.sql similarity index 100% rename from migrations/2024-07-09-133113_item_make_name_optional/down.sql rename to migrations/20240709133113_item_make_name_optional.down.sql diff --git a/migrations/2024-07-09-133113_item_make_name_optional/up.sql b/migrations/20240709133113_item_make_name_optional.up.sql similarity index 100% rename from migrations/2024-07-09-133113_item_make_name_optional/up.sql rename to migrations/20240709133113_item_make_name_optional.up.sql diff --git a/migrations/2024-07-11-110525_item_class_simplify/down.sql b/migrations/20240711110525_item_class_simplify.down.sql similarity index 100% rename from migrations/2024-07-11-110525_item_class_simplify/down.sql rename to migrations/20240711110525_item_class_simplify.down.sql diff --git a/migrations/2024-07-11-110525_item_class_simplify/up.sql b/migrations/20240711110525_item_class_simplify.up.sql similarity index 100% rename from migrations/2024-07-11-110525_item_class_simplify/up.sql rename to migrations/20240711110525_item_class_simplify.up.sql diff --git a/src/api/v1/item.rs b/src/api/v1/item.rs index 6eb74b8..f68ce34 100644 --- a/src/api/v1/item.rs +++ b/src/api/v1/item.rs @@ -3,11 +3,11 @@ // SPDX-License-Identifier: AGPL-3.0-or-later use actix_web::{delete, error, get, post, put, web, HttpResponse, Responder}; +use sqlx::PgPool; use uuid::Uuid; use crate::manage; use crate::models::*; -use crate::DbPool; pub fn config(cfg: &mut web::ServiceConfig) { cfg.service(add) @@ -20,15 +20,10 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[put("/item")] async fn add( - pool: web::Data, + pool: web::Data, new_item: web::Json, ) -> actix_web::Result { - // TODO: Failure to get a connection from the pool should not panic. - // Instead, a Result::Err variant should be returned, which then gets turned into an ISE. - // This is not easily possible as getting a connection from a pool returns an r2d2 error - // type, while the databse action returns a diesel error type, which are incompatible. - // This also affects other functions below. - let item = manage::item::add(&mut pool.get().await.unwrap(), new_item.into_inner()) + let item = manage::item::add(&pool, new_item.into_inner()) .await .map_err(error::ErrorInternalServerError)?; @@ -36,8 +31,8 @@ async fn add( } #[get("/item")] -async fn list(pool: web::Data) -> actix_web::Result { - let items = manage::item::get_all(&mut pool.get().await.unwrap()) +async fn list(pool: web::Data) -> actix_web::Result { + let items = manage::item::get_all(&pool) .await .map_err(error::ErrorInternalServerError)?; @@ -45,10 +40,10 @@ async fn list(pool: web::Data) -> actix_web::Result { } #[get("/item/{id}")] -async fn show(pool: web::Data, path: web::Path) -> actix_web::Result { +async fn show(pool: web::Data, path: web::Path) -> actix_web::Result { let id = path.into_inner(); - let item = manage::item::get(&mut pool.get().await.unwrap(), id) + let item = manage::item::get(&pool, id) .await .map_err(error::ErrorInternalServerError)?; @@ -57,13 +52,13 @@ async fn show(pool: web::Data, path: web::Path) -> actix_web::Resu #[post("/item/{id}")] async fn update( - pool: web::Data, + pool: web::Data, path: web::Path, new_item: web::Json, ) -> actix_web::Result { let id = path.into_inner(); - let item = manage::item::update(&mut pool.get().await.unwrap(), id, new_item.into_inner()) + let item = manage::item::update(&pool, id, new_item.into_inner()) .await .map_err(error::ErrorInternalServerError)?; @@ -72,12 +67,12 @@ async fn update( #[delete("/item/{id}")] async fn delete( - pool: web::Data, + pool: web::Data, path: web::Path, ) -> actix_web::Result { let id = path.into_inner(); - manage::item::delete(&mut pool.get().await.unwrap(), id) + manage::item::delete(&pool, id) .await .map_err(error::ErrorInternalServerError)?; @@ -86,12 +81,12 @@ async fn delete( #[get("/item/{id}/parents")] async fn parents( - pool: web::Data, + pool: web::Data, path: web::Path, ) -> actix_web::Result { let id = path.into_inner(); - let parents = manage::item::get_parents(&mut pool.get().await.unwrap(), id) + let parents = manage::item::get_parents(&pool, id) .await .map_err(error::ErrorInternalServerError)?; diff --git a/src/api/v1/item_class.rs b/src/api/v1/item_class.rs index 22c9314..fff2764 100644 --- a/src/api/v1/item_class.rs +++ b/src/api/v1/item_class.rs @@ -3,11 +3,11 @@ // SPDX-License-Identifier: AGPL-3.0-or-later use actix_web::{delete, error, get, post, put, web, HttpResponse, Responder}; +use sqlx::PgPool; use uuid::Uuid; use crate::manage; use crate::models::*; -use crate::DbPool; pub fn config(cfg: &mut web::ServiceConfig) { cfg.service(add) @@ -20,20 +20,19 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[put("/item-class")] async fn add( - pool: web::Data, + pool: web::Data, new_item_class: web::Json, ) -> actix_web::Result { - let item_class = - manage::item_class::add(&mut pool.get().await.unwrap(), new_item_class.into_inner()) - .await - .map_err(error::ErrorInternalServerError)?; + let item_class = manage::item_class::add(&pool, new_item_class.into_inner()) + .await + .map_err(error::ErrorInternalServerError)?; Ok(HttpResponse::Ok().json(item_class)) } #[get("/item-class")] -async fn list(pool: web::Data) -> actix_web::Result { - let item_classes = manage::item_class::get_all(&mut pool.get().await.unwrap()) +async fn list(pool: web::Data) -> actix_web::Result { + let item_classes = manage::item_class::get_all(&pool) .await .map_err(error::ErrorInternalServerError)?; @@ -41,10 +40,10 @@ async fn list(pool: web::Data) -> actix_web::Result { } #[get("/item-class/{id}")] -async fn show(pool: web::Data, path: web::Path) -> actix_web::Result { +async fn show(pool: web::Data, path: web::Path) -> actix_web::Result { let id = path.into_inner(); - let item_class = manage::item_class::get(&mut pool.get().await.unwrap(), id) + let item_class = manage::item_class::get(&pool, id) .await .map_err(error::ErrorInternalServerError)?; @@ -53,12 +52,12 @@ async fn show(pool: web::Data, path: web::Path) -> actix_web::Resu #[get("/item-class/{id}/items")] async fn items( - pool: web::Data, + pool: web::Data, path: web::Path, ) -> actix_web::Result { let id = path.into_inner(); - let items = manage::item_class::items(&mut pool.get().await.unwrap(), id) + let items = manage::item_class::items(&pool, id) .await .map_err(error::ErrorInternalServerError)?; @@ -67,31 +66,27 @@ async fn items( #[post("/item-class/{id}")] async fn update( - pool: web::Data, + pool: web::Data, path: web::Path, new_item_class: web::Json, ) -> actix_web::Result { let id = path.into_inner(); - let item_class = manage::item_class::update( - &mut pool.get().await.unwrap(), - id, - new_item_class.into_inner(), - ) - .await - .map_err(error::ErrorInternalServerError)?; + let item_class = manage::item_class::update(&pool, id, new_item_class.into_inner()) + .await + .map_err(error::ErrorInternalServerError)?; Ok(HttpResponse::Ok().json(item_class)) } #[delete("/item-class/{id}")] async fn delete( - pool: web::Data, + pool: web::Data, path: web::Path, ) -> actix_web::Result { let id = path.into_inner(); - manage::item_class::delete(&mut pool.get().await.unwrap(), id) + manage::item_class::delete(&pool, id) .await .map_err(error::ErrorInternalServerError)?; diff --git a/src/frontend/item.rs b/src/frontend/item.rs index 80dc380..f0d3a9c 100644 --- a/src/frontend/item.rs +++ b/src/frontend/item.rs @@ -6,12 +6,12 @@ use std::collections::HashMap; use actix_web::{error, get, post, web, Responder}; use maud::html; +use sqlx::PgPool; use uuid::Uuid; use super::templates::{self, forms, TemplateConfig}; use crate::manage; use crate::models::*; -use crate::DbPool; pub fn config(cfg: &mut web::ServiceConfig) { cfg.service(show_item) @@ -24,24 +24,24 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("/item/{id}")] async fn show_item( - pool: web::Data, + pool: web::Data, path: web::Path, ) -> actix_web::Result { let id = path.into_inner(); - let item = manage::item::get(&mut pool.get().await.unwrap(), id) + let item = manage::item::get(&pool, id) .await .map_err(error::ErrorInternalServerError)?; - let item_classes = manage::item_class::get_all_as_map(&mut pool.get().await.unwrap()) + let item_classes = manage::item_class::get_all_as_map(&pool) .await .map_err(error::ErrorInternalServerError)?; - let parents = manage::item::get_parents_details(&mut pool.get().await.unwrap(), item.id) + let parents = manage::item::get_parents_details(&pool, item.id) .await .map_err(error::ErrorInternalServerError)?; - let children = manage::item::get_children(&mut pool.get().await.unwrap(), item.id) + let children = manage::item::get_children(&pool, item.id) .await .map_err(error::ErrorInternalServerError)?; @@ -100,20 +100,20 @@ async fn show_item( } #[get("/items")] -async fn list_items(pool: web::Data) -> actix_web::Result { - let item_list = manage::item::get_all(&mut pool.get().await.unwrap()) +async fn list_items(pool: web::Data) -> actix_web::Result { + let item_list = manage::item::get_all(&pool) .await .map_err(error::ErrorInternalServerError)?; - let items = manage::item::get_all_as_map(&mut pool.get().await.unwrap()) + let items = manage::item::get_all_as_map(&pool) .await .map_err(error::ErrorInternalServerError)?; - let item_classes = manage::item_class::get_all_as_map(&mut pool.get().await.unwrap()) + let item_classes = manage::item_class::get_all_as_map(&pool) .await .map_err(error::ErrorInternalServerError)?; - let item_tree = manage::item::get_all_parents(&mut pool.get().await.unwrap()) + let item_tree = manage::item::get_all_parents(&pool) .await .map_err(error::ErrorInternalServerError)?; @@ -212,9 +212,9 @@ async fn add_item() -> actix_web::Result { #[post("/items/add")] async fn add_item_post( data: web::Form, - pool: web::Data, + pool: web::Data, ) -> actix_web::Result { - let item = manage::item::add(&mut pool.get().await.unwrap(), data.into_inner()) + let item = manage::item::add(&pool, data.into_inner()) .await .map_err(error::ErrorInternalServerError)?; Ok(web::Redirect::to("/item/".to_owned() + &item.id.to_string()).see_other()) @@ -222,16 +222,16 @@ async fn add_item_post( #[get("/item/{id}/edit")] async fn edit_item( - pool: web::Data, + pool: web::Data, path: web::Path, ) -> actix_web::Result { let id = path.into_inner(); - let item = manage::item::get(&mut pool.get().await.unwrap(), id) + let item = manage::item::get(&pool, id) .await .map_err(error::ErrorInternalServerError)?; - let item_class = manage::item_class::get(&mut pool.get().await.unwrap(), item.class) + let item_class = manage::item_class::get(&pool, item.class) .await .map_err(error::ErrorInternalServerError)?; @@ -289,13 +289,13 @@ async fn edit_item( #[post("/item/{id}/edit")] async fn edit_item_post( - pool: web::Data, + pool: web::Data, path: web::Path, data: web::Form, ) -> actix_web::Result { let id = path.into_inner(); - let item = manage::item::update(&mut pool.get().await.unwrap(), id, data.into_inner()) + let item = manage::item::update(&pool, id, data.into_inner()) .await .map_err(error::ErrorInternalServerError)?; diff --git a/src/frontend/item_class.rs b/src/frontend/item_class.rs index 7760428..13ea207 100644 --- a/src/frontend/item_class.rs +++ b/src/frontend/item_class.rs @@ -4,12 +4,12 @@ use actix_web::{error, get, post, web, Responder}; use maud::html; +use sqlx::PgPool; use uuid::Uuid; use super::templates::{self, forms, TemplateConfig}; use crate::manage; use crate::models::*; -use crate::DbPool; pub fn config(cfg: &mut web::ServiceConfig) { cfg.service(show_item_class) @@ -22,27 +22,25 @@ pub fn config(cfg: &mut web::ServiceConfig) { #[get("/item-class/{id}")] async fn show_item_class( - pool: web::Data, + pool: web::Data, path: web::Path, ) -> actix_web::Result { let id = path.into_inner(); - let mut conn = pool.clone().get().await.unwrap(); - - let item_class = manage::item_class::get(&mut conn, id) + let item_class = manage::item_class::get(&pool, id) .await .map_err(error::ErrorInternalServerError)?; // TODO: Once async closures are stable, use map_or on item_class.parent instead let parent = match item_class.parent { - Some(id) => manage::item_class::get(&mut conn, id) + Some(id) => manage::item_class::get(&pool, id) .await .map(Some) .map_err(error::ErrorInternalServerError)?, None => None, }; - let children = manage::item_class::children(&mut conn, id) + let children = manage::item_class::children(&pool, id) .await .map_err(error::ErrorInternalServerError)?; @@ -96,8 +94,8 @@ async fn show_item_class( } #[get("/item-classes")] -async fn list_item_classes(pool: web::Data) -> actix_web::Result { - let item_classes = manage::item_class::get_all_as_map(&mut pool.get().await.unwrap()) +async fn list_item_classes(pool: web::Data) -> actix_web::Result { + let item_classes = manage::item_class::get_all_as_map(&pool) .await .map_err(error::ErrorInternalServerError)?; @@ -177,9 +175,9 @@ async fn add_item_class() -> actix_web::Result { #[post("/item-classes/add")] async fn add_item_class_post( data: web::Form, - pool: web::Data, + pool: web::Data, ) -> actix_web::Result { - let item = manage::item_class::add(&mut pool.get().await.unwrap(), data.into_inner()) + let item = manage::item_class::add(&pool, data.into_inner()) .await .map_err(error::ErrorInternalServerError)?; Ok(web::Redirect::to("/item-class/".to_owned() + &item.id.to_string()).see_other()) @@ -187,12 +185,12 @@ async fn add_item_class_post( #[get("/item-class/{id}/edit")] async fn edit_item_class( - pool: web::Data, + pool: web::Data, path: web::Path, ) -> actix_web::Result { let id = path.into_inner(); - let item_class = manage::item_class::get(&mut pool.get().await.unwrap(), id) + let item_class = manage::item_class::get(&pool, id) .await .map_err(error::ErrorInternalServerError)?; @@ -241,16 +239,15 @@ async fn edit_item_class( #[post("/item-class/{id}/edit")] async fn edit_item_class_post( - pool: web::Data, + pool: web::Data, path: web::Path, data: web::Form, ) -> actix_web::Result { let id = path.into_inner(); - let item_class = - manage::item_class::update(&mut pool.get().await.unwrap(), id, data.into_inner()) - .await - .map_err(error::ErrorInternalServerError)?; + let item_class = manage::item_class::update(&pool, id, data.into_inner()) + .await + .map_err(error::ErrorInternalServerError)?; Ok(web::Redirect::to("/item-class/".to_owned() + &item_class.id.to_string()).see_other()) } diff --git a/src/lib.rs b/src/lib.rs index cec0a00..ff840c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,9 +7,3 @@ pub mod frontend; pub mod label; pub mod manage; pub mod models; -pub mod schema; - -use diesel_async::pg::AsyncPgConnection; -use diesel_async::pooled_connection::deadpool::Pool; - -type DbPool = Pool; diff --git a/src/main.rs b/src/main.rs index 2d2a4cd..181b0ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,41 +5,22 @@ use std::env; use actix_web::{web, App, HttpServer}; -use diesel::pg::Pg; -use diesel_async::async_connection_wrapper::AsyncConnectionWrapper; -use diesel_async::pg::AsyncPgConnection; -use diesel_async::pooled_connection::deadpool::Pool; -use diesel_async::pooled_connection::AsyncDieselConnectionManager; -use diesel_async::AsyncConnection; -use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; use log::{debug, info}; -pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!(); - -// adapted from https://github.com/weiznich/diesel_async/blob/002c67e4d09acd9b38d0fb08ff0efc24954b2558/examples/sync-wrapper/src/main.rs#L36-L48 -async fn run_migrations + 'static>(async_connection: A) { - let mut async_wrapper: AsyncConnectionWrapper = - AsyncConnectionWrapper::from(async_connection); - - web::block(move || { - async_wrapper.run_pending_migrations(MIGRATIONS).unwrap(); - }) - .await - .expect("failed to run migrations"); -} - #[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::init(); - let manager = AsyncDieselConnectionManager::::new( - env::var("DATABASE_URL").expect("DATABASE_URL must be set"), - ); - let pool: Pool = Pool::builder(manager) - .build() - .expect("database URL must be valid"); + let pool: sqlx::PgPool = sqlx::Pool::::connect( + &env::var("DATABASE_URL").expect("DATABASE_URL must be set"), + ) + .await + .expect("failed to connect to database"); - run_migrations(pool.get().await.unwrap()).await; + sqlx::migrate!() + .run(&pool) + .await + .expect("failed to run migrations"); let address = env::var("LISTEN_ADDRESS").unwrap_or("::1".to_string()); let port = env::var("LISTEN_PORT").map_or(8080, |s| { diff --git a/src/manage/item.rs b/src/manage/item.rs index a85cbdd..66dc39e 100644 --- a/src/manage/item.rs +++ b/src/manage/item.rs @@ -4,132 +4,95 @@ use std::collections::HashMap; -use diesel::prelude::*; -use diesel::sql_types; -use diesel_async::pg::AsyncPgConnection; -use diesel_async::RunQueryDsl; +use sqlx::{query, query_as, query_scalar, PgPool}; use uuid::Uuid; -use crate::{models::*, schema}; +use crate::models::{Item, NewItem}; -pub async fn add( - conn: &mut AsyncPgConnection, - new_item: NewItem, -) -> Result { - diesel::insert_into(schema::items::table) - .values(new_item) - .returning(Item::as_returning()) - .get_result(conn) +pub async fn add(pool: &PgPool, new_item: NewItem) -> Result { + query_as!( + Item, + "INSERT INTO items (name, parent, class) VALUES ($1, $2, $3) RETURNING *", + new_item.name, + new_item.parent, + new_item.class + ) + .fetch_one(pool) + .await +} + +pub async fn get(pool: &PgPool, id: Uuid) -> Result { + query_as!(Item, "SELECT * FROM items WHERE id = $1", id) + .fetch_one(pool) .await } -pub async fn get(conn: &mut AsyncPgConnection, id: Uuid) -> Result { - schema::items::table - .filter(schema::items::id.eq(id)) - .select(Item::as_select()) - .first(conn) - .await +pub async fn get_all(pool: &PgPool) -> Result, sqlx::Error> { + query_as!(Item, "SELECT * FROM items").fetch_all(pool).await } -pub async fn get_all(conn: &mut AsyncPgConnection) -> Result, diesel::result::Error> { - schema::items::table - .select(Item::as_select()) - .load(conn) - .await -} - -pub async fn get_all_as_map( - conn: &mut AsyncPgConnection, -) -> Result, diesel::result::Error> { - Ok(get_all(conn) +pub async fn get_all_as_map(pool: &PgPool) -> Result, sqlx::Error> { + Ok(get_all(pool) .await? .into_iter() .map(|i| (i.id, i)) .collect()) } -pub async fn update( - conn: &mut AsyncPgConnection, - id: Uuid, - modified_item: NewItem, -) -> Result { - diesel::update(schema::items::table.filter(schema::items::id.eq(id))) - .set(modified_item) - .returning(Item::as_returning()) - .get_result(conn) - .await +pub async fn update(pool: &PgPool, id: Uuid, modified_item: NewItem) -> Result { + query_as!( + Item, + "UPDATE items SET name = $2, parent = $3, class = $4 WHERE id = $1 RETURNING *", + id, + modified_item.name, + modified_item.parent, + modified_item.class + ) + .fetch_one(pool) + .await } -pub async fn delete(conn: &mut AsyncPgConnection, id: Uuid) -> Result<(), diesel::result::Error> { - let num_deleted = diesel::delete(schema::items::table.filter(schema::items::id.eq(id))) - .execute(conn) +pub async fn delete(pool: &PgPool, id: Uuid) -> Result<(), sqlx::Error> { + let res = query!("DELETE FROM items WHERE id = $1", id) + .execute(pool) .await?; - assert_eq!(num_deleted, 1); + assert_eq!(res.rows_affected(), 1); Ok(()) } -/// Helper type for querying parents of items -#[derive(Debug, Queryable, Selectable)] -#[diesel(table_name = schema::item_tree)] -#[diesel(check_for_backend(diesel::pg::Pg))] -struct ItemTreeMapping { - pub id: Uuid, - pub parents: Vec, +pub async fn get_parents(pool: &PgPool, id: Uuid) -> Result, sqlx::Error> { + // force nullable is required for all columns in views + query_scalar!( + r#"SELECT unnest(parents) as "parents!" FROM item_tree WHERE id = $1"#, + id + ) + .fetch_all(pool) + .await } -pub async fn get_parents( - conn: &mut AsyncPgConnection, - id: Uuid, -) -> Result, diesel::result::Error> { - schema::item_tree::table - .filter(schema::item_tree::id.eq(id)) - .select(ItemTreeMapping::as_select()) - .first(conn) - .await - .map(|itm| itm.parents) +pub async fn get_all_parents(pool: &PgPool) -> Result>, sqlx::Error> { + let mut parents = HashMap::new(); + for row in query!(r#"SELECT id as "id!", parents as "parents!" FROM item_tree"#) + .fetch_all(pool) + .await? + { + parents.insert(row.id, row.parents); + } + Ok(parents) } -pub async fn get_all_parents( - conn: &mut AsyncPgConnection, -) -> Result>, diesel::result::Error> { - schema::item_tree::table - .select(ItemTreeMapping::as_select()) - .load(conn) - .await - .map(|itms| { - itms.into_iter() - .map(|ItemTreeMapping { id, parents }| (id, parents)) - .collect::>>() - }) +pub async fn get_parents_details(pool: &PgPool, id: Uuid) -> Result, sqlx::Error> { + query_as!( + Item, + "SELECT * FROM items WHERE id = ANY (SELECT unnest(parents) FROM item_tree WHERE id = $1)", + id + ) + .fetch_all(pool) + .await } -pub async fn get_parents_details( - conn: &mut AsyncPgConnection, - id: Uuid, -) -> Result, diesel::result::Error> { - define_sql_function!(fn unnest(a: sql_types::Array) -> sql_types::Uuid); - - schema::items::table - .filter( - schema::items::id.eq_any( - schema::item_tree::table - .filter(schema::item_tree::id.eq(id)) - .select(unnest(schema::item_tree::parents)) - .into_boxed(), - ), - ) - .select(Item::as_select()) - .load(conn) - .await -} - -pub async fn get_children( - conn: &mut AsyncPgConnection, - id: Uuid, -) -> Result, diesel::result::Error> { - schema::items::table - .filter(schema::items::parent.eq(id)) - .select(Item::as_select()) - .load(conn) +pub async fn get_children(pool: &PgPool, id: Uuid) -> Result, sqlx::Error> { + query_as!(Item, "SELECT * FROM items WHERE parent = $1", id) + .fetch_all(pool) .await } diff --git a/src/manage/item_class.rs b/src/manage/item_class.rs index f4552d9..2eecb33 100644 --- a/src/manage/item_class.rs +++ b/src/manage/item_class.rs @@ -4,48 +4,36 @@ use std::collections::HashMap; -use diesel::prelude::*; -use diesel_async::pg::AsyncPgConnection; -use diesel_async::RunQueryDsl; +use sqlx::{query, query_as, PgPool}; use uuid::Uuid; -use crate::{models::*, schema}; +use crate::models::{Item, ItemClass, NewItemClass}; -pub async fn add( - conn: &mut AsyncPgConnection, - new_item_class: NewItemClass, -) -> Result { - diesel::insert_into(schema::item_classes::table) - .values(new_item_class) - .returning(ItemClass::as_returning()) - .get_result(conn) +pub async fn add(pool: &PgPool, new_item_class: NewItemClass) -> Result { + query_as!( + ItemClass, + "INSERT INTO item_classes (name, parent) VALUES ($1, $2) RETURNING *", + new_item_class.name, + new_item_class.parent + ) + .fetch_one(pool) + .await +} + +pub async fn get(pool: &PgPool, id: Uuid) -> Result { + query_as!(ItemClass, "SELECT * FROM item_classes WHERE id = $1", id) + .fetch_one(pool) .await } -pub async fn get( - conn: &mut AsyncPgConnection, - id: Uuid, -) -> Result { - schema::item_classes::table - .filter(schema::item_classes::id.eq(id)) - .select(ItemClass::as_select()) - .first(conn) +pub async fn get_all(pool: &PgPool) -> Result, sqlx::Error> { + query_as!(ItemClass, "SELECT * FROM item_classes") + .fetch_all(pool) .await } -pub async fn get_all( - conn: &mut AsyncPgConnection, -) -> Result, diesel::result::Error> { - schema::item_classes::table - .select(ItemClass::as_select()) - .load(conn) - .await -} - -pub async fn get_all_as_map( - conn: &mut AsyncPgConnection, -) -> Result, diesel::result::Error> { - Ok(get_all(conn) +pub async fn get_all_as_map(pool: &PgPool) -> Result, sqlx::Error> { + Ok(get_all(pool) .await? .into_iter() .map(|ic| (ic.id, ic)) @@ -53,44 +41,41 @@ pub async fn get_all_as_map( } pub async fn update( - conn: &mut AsyncPgConnection, + pool: &PgPool, id: Uuid, modified_item_class: NewItemClass, -) -> Result { - diesel::update(schema::item_classes::table.filter(schema::item_classes::id.eq(id))) - .set(modified_item_class) - .returning(ItemClass::as_returning()) - .get_result(conn) +) -> Result { + query_as!( + ItemClass, + "UPDATE item_classes SET name = $2, parent = $3 WHERE id = $1 RETURNING *", + id, + modified_item_class.name, + modified_item_class.parent + ) + .fetch_one(pool) + .await +} + +pub async fn items(pool: &PgPool, id: Uuid) -> Result, sqlx::Error> { + query_as!(Item, "SELECT * FROM items WHERE class = $1", id) + .fetch_all(pool) .await } -pub async fn items( - conn: &mut AsyncPgConnection, - id: Uuid, -) -> Result, diesel::result::Error> { - schema::items::table - .filter(schema::items::class.eq(id)) - .select(Item::as_select()) - .load(conn) - .await -} - -pub async fn delete(conn: &mut AsyncPgConnection, id: Uuid) -> Result<(), diesel::result::Error> { - let num_deleted = - diesel::delete(schema::item_classes::table.filter(schema::item_classes::id.eq(id))) - .execute(conn) - .await?; - assert_eq!(num_deleted, 1); +pub async fn delete(pool: &PgPool, id: Uuid) -> Result<(), sqlx::Error> { + let res = query!("DELETE FROM item_classes WHERE id = $1", id) + .execute(pool) + .await?; + assert_eq!(res.rows_affected(), 1); Ok(()) } -pub async fn children( - conn: &mut AsyncPgConnection, - id: Uuid, -) -> Result, diesel::result::Error> { - schema::item_classes::table - .filter(schema::item_classes::parent.eq(id)) - .select(ItemClass::as_select()) - .load(conn) - .await +pub async fn children(pool: &PgPool, id: Uuid) -> Result, sqlx::Error> { + query_as!( + ItemClass, + "SELECT * FROM item_classes WHERE parent = $1", + id + ) + .fetch_all(pool) + .await } diff --git a/src/models.rs b/src/models.rs index 5a662b2..d03ea3e 100644 --- a/src/models.rs +++ b/src/models.rs @@ -2,15 +2,10 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later -use diesel::prelude::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use crate::schema::*; - -#[derive(Clone, Debug, Queryable, Selectable, Insertable, Serialize)] -#[diesel(table_name = items)] -#[diesel(check_for_backend(diesel::pg::Pg))] +#[derive(Clone, Debug, Serialize, sqlx::FromRow)] pub struct Item { pub id: Uuid, pub name: Option, @@ -18,10 +13,7 @@ pub struct Item { pub class: Uuid, } -#[derive(Debug, Insertable, Deserialize, AsChangeset)] -#[diesel(table_name = items)] -#[diesel(check_for_backend(diesel::pg::Pg))] -#[diesel(treat_none_as_null = true)] +#[derive(Debug, Deserialize)] pub struct NewItem { #[serde(default)] pub name: Option, @@ -30,9 +22,7 @@ pub struct NewItem { pub class: Uuid, } -#[derive(Clone, Debug, Queryable, Selectable, Insertable, Serialize)] -#[diesel(table_name = item_classes)] -#[diesel(check_for_backend(diesel::pg::Pg))] +#[derive(Clone, Debug, Serialize)] pub struct ItemClass { pub id: Uuid, pub name: String, @@ -40,10 +30,7 @@ pub struct ItemClass { pub parent: Option, } -#[derive(Debug, Insertable, Deserialize, AsChangeset)] -#[diesel(table_name = item_classes)] -#[diesel(check_for_backend(diesel::pg::Pg))] -#[diesel(treat_none_as_null = true)] +#[derive(Debug, Deserialize)] pub struct NewItemClass { pub name: String, #[serde(default)] diff --git a/src/schema.rs b/src/schema.rs deleted file mode 100644 index 61e7195..0000000 --- a/src/schema.rs +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Simon Bruder -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -diesel::table! { - items (id) { - id -> Uuid, - name -> Nullable, - parent -> Nullable, - class -> Uuid, - } -} - -diesel::table! { - item_tree (id) { - id -> Uuid, - parents -> Array, - } -} - -diesel::table! { - item_classes (id) { - id -> Uuid, - name -> Varchar, - parent -> Nullable, - } -} - -diesel::joinable!(items -> item_classes (class)); - -diesel::allow_tables_to_appear_in_same_query!(item_classes, items); -diesel::allow_tables_to_appear_in_same_query!(items, item_tree);