diff --git a/Cargo.lock b/Cargo.lock index c134efb..ed472ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -509,27 +509,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bindgen" -version = "0.65.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" -dependencies = [ - "bitflags 1.3.2", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "peeking_take_while", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash 1.1.0", - "shlex", - "syn 2.0.77", -] - [[package]] name = "bit-set" version = "0.5.3" @@ -699,17 +678,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bzip2-sys" -version = "0.1.11+1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "camino" version = "1.1.9" @@ -757,8 +725,6 @@ version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" dependencies = [ - "jobserver", - "libc", "shlex", ] @@ -819,15 +785,6 @@ dependencies = [ "unicode-security", ] -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfb" version = "0.7.3" @@ -912,17 +869,6 @@ dependencies = [ "inout", ] -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "concurrent-queue" version = "2.5.0" @@ -1019,25 +965,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.20" @@ -1691,19 +1618,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "ext-sort" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf73e44617eab501beba39234441a194cf138629d3b6447f81f573e1c3d0a13" -dependencies = [ - "log", - "rayon", - "rmp-serde", - "serde", - "tempfile", -] - [[package]] name = "fastrand" version = "2.1.1" @@ -1969,12 +1883,6 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - [[package]] name = "gloo" version = "0.8.1" @@ -2633,15 +2541,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "jobserver" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" -dependencies = [ - "libc", -] - [[package]] name = "js-sys" version = "0.3.70" @@ -2727,12 +2626,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "lexicmp" version = "0.1.0" @@ -2748,16 +2641,6 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" -[[package]] -name = "libloading" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" -dependencies = [ - "cfg-if", - "windows-targets 0.52.6", -] - [[package]] name = "libm" version = "0.2.8" @@ -2774,33 +2657,6 @@ dependencies = [ "libc", ] -[[package]] -name = "librocksdb-sys" -version = "0.11.0+8.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3386f101bcb4bd252d8e9d2fb41ec3b0862a15a62b478c355b2982efa469e3e" -dependencies = [ - "bindgen", - "bzip2-sys", - "cc", - "glob", - "libc", - "libz-sys", - "lz4-sys", - "zstd-sys", -] - -[[package]] -name = "libz-sys" -version = "1.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - [[package]] name = "linfa-linalg" version = "0.1.0" @@ -2850,16 +2706,6 @@ dependencies = [ "hashbrown 0.14.5", ] -[[package]] -name = "lz4-sys" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb44a01837a858d47e5a630d2ccf304c8efcc4b83b8f9f75b7a9ee4fcc6e57d" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "mac" version = "0.1.1" @@ -3003,12 +2849,6 @@ 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" @@ -3126,16 +2966,6 @@ dependencies = [ "num-traits", ] -[[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 = "nu-ansi-term" version = "0.46.0" @@ -3359,12 +3189,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "pem" version = "3.0.4" @@ -3769,26 +3593,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" -[[package]] -name = "rayon" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "reblessive" version = "0.4.0" @@ -4039,17 +3843,6 @@ dependencies = [ "paste", ] -[[package]] -name = "rmp-serde" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" -dependencies = [ - "byteorder", - "rmp", - "serde", -] - [[package]] name = "rmpv" version = "1.3.0" @@ -4077,16 +3870,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbf4a6aa5f6d6888f39e980649f3ad6b666acdce1d78e95b8a2cb076e687ae30" -[[package]] -name = "rocksdb" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6f170a4041d50a0ce04b0d2e14916d6ca863ea2e422689a5b694395d299ffe" -dependencies = [ - "libc", - "librocksdb-sys", -] - [[package]] name = "rstar" version = "0.12.0" @@ -4899,7 +4682,6 @@ dependencies = [ "dashmap", "deunicode", "dmp", - "ext-sort", "fst", "futures", "fuzzy-matcher", @@ -4930,7 +4712,6 @@ dependencies = [ "ring", "rmpv", "roaring", - "rocksdb", "rust-stemmers", "rust_decimal", "scrypt", @@ -4944,7 +4725,6 @@ dependencies = [ "storekey", "subtle", "surrealdb-derive", - "tempfile", "thiserror", "tokio", "tracing", @@ -6145,13 +5925,3 @@ name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" - -[[package]] -name = "zstd-sys" -version = "2.0.13+zstd.1.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" -dependencies = [ - "cc", - "pkg-config", -] diff --git a/Cargo.toml b/Cargo.toml index d31366b..248d866 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ axum = { version = "0.7", optional = true } axum-extra = { version = "0.9", features = ["cookie"], optional = true } time = { version = "0.3", optional = true } once_cell = { version = "1.19", optional = true } -surrealdb = { version = "2.0", features = ["kv-rocksdb"], optional = true } +surrealdb = { version = "2.0", optional = true } thiserror = { version = "1.0" } csv = { version = "1.3", optional = true } diff --git a/assets/tailwind.css b/assets/tailwind.css index 234a596..1f4cb91 100644 --- a/assets/tailwind.css +++ b/assets/tailwind.css @@ -2990,6 +2990,11 @@ details.collapse summary::-webkit-details-marker { height: max-content; } +.h-min { + height: -moz-min-content; + height: min-content; +} + .h-screen { height: 100vh; } @@ -3040,6 +3045,12 @@ details.collapse summary::-webkit-details-marker { user-select: none; } +.select-all { + -webkit-user-select: all; + -moz-user-select: all; + user-select: all; +} + .flex-col { flex-direction: column; } @@ -3056,6 +3067,10 @@ details.collapse summary::-webkit-details-marker { align-items: center; } +.justify-start { + justify-content: flex-start; +} + .justify-center { justify-content: center; } @@ -3102,6 +3117,16 @@ details.collapse summary::-webkit-details-marker { white-space: nowrap; } +.rounded-b-none { + border-bottom-right-radius: 0px; + border-bottom-left-radius: 0px; +} + +.rounded-t-none { + border-top-left-radius: 0px; + border-top-right-radius: 0px; +} + .bg-base-200 { --tw-bg-opacity: 1; background-color: var(--fallback-b2,oklch(var(--b2)/var(--tw-bg-opacity))); diff --git a/devenv.lock b/devenv.lock index dfbf6c3..868f058 100644 --- a/devenv.lock +++ b/devenv.lock @@ -3,11 +3,10 @@ "devenv": { "locked": { "dir": "src/modules", - "lastModified": 1726826452, + "lastModified": 1728113618, "owner": "cachix", "repo": "devenv", - "rev": "2bdf6461e88c7e93b94d72d8b11d5a61f167cbf5", - "treeHash": "e10f5d7f21ef64fb0a9c269c400af0cd8f43fb35", + "rev": "a8495abab31ce52cd45d343caa760046c0c7ee74", "type": "github" }, "original": { @@ -25,11 +24,10 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1726986637, + "lastModified": 1728196311, "owner": "nix-community", "repo": "fenix", - "rev": "f5a9b01cd81b46228b3737669e8275b1f2da7d35", - "treeHash": "97be3a5a79be99410ddfc81f61377daba4df0ec5", + "rev": "26971356e387b5ec0578f52be1bbd82ecf6dbad4", "type": "github" }, "original": { @@ -45,7 +43,6 @@ "owner": "edolstra", "repo": "flake-compat", "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "treeHash": "2addb7b71a20a25ea74feeaf5c2f6a6b30898ecb", "type": "github" }, "original": { @@ -66,7 +63,6 @@ "owner": "hercules-ci", "repo": "gitignore.nix", "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "treeHash": "ca14199cabdfe1a06a7b1654c76ed49100a689f9", "type": "github" }, "original": { @@ -77,11 +73,10 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726838390, + "lastModified": 1728067476, "owner": "NixOS", "repo": "nixpkgs", - "rev": "944b2aea7f0a2d7c79f72468106bc5510cbf5101", - "treeHash": "5ff7724fe1272ea9b66c97c25e00bb1dc9782aaf", + "rev": "6e6b3dd395c3b1eb9be9f2d096383a8d05add030", "type": "github" }, "original": { @@ -93,11 +88,10 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1726838390, + "lastModified": 1728067476, "owner": "NixOS", "repo": "nixpkgs", - "rev": "944b2aea7f0a2d7c79f72468106bc5510cbf5101", - "treeHash": "5ff7724fe1272ea9b66c97c25e00bb1dc9782aaf", + "rev": "6e6b3dd395c3b1eb9be9f2d096383a8d05add030", "type": "github" }, "original": { @@ -117,11 +111,10 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1726745158, + "lastModified": 1728092656, "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "4e743a6920eab45e8ba0fbe49dc459f1423a4b74", - "treeHash": "56fbe2a9610b3ad9163a74011131e7624f6b3b81", + "rev": "1211305a5b237771e13fcca0c51e60ad47326a9a", "type": "github" }, "original": { @@ -141,11 +134,10 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1726443025, + "lastModified": 1728064742, "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "94b526fc86eaa0e90fb4d54a5ba6313aa1e9b269", - "treeHash": "3a9ddbe34b25b2921864f029988d2d48049b2d4a", + "rev": "5982d9c420d0dc90739171829f0d2e9c80d98979", "type": "github" }, "original": { diff --git a/devenv.nix b/devenv.nix index e7b6bed..42b3cbe 100644 --- a/devenv.nix +++ b/devenv.nix @@ -41,6 +41,7 @@ # https://devenv.sh/processes/ processes.tailwind.exec = "watchexec -e rs ${lib.getExe pkgs.tailwindcss} -i input.css -o assets/tailwind.css"; processes.dioxus.exec = "dx serve"; + processes.surrealdb.exec = "docker compose up"; # See full reference at https://devenv.sh/reference/options/ } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2bc8eeb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +services: + surrealdb: + image: surrealdb/surrealdb:latest + container_name: surrealdb-wrbapp + ports: + - 8000:8000 + volumes: + - ./database:/data + user: "${UID}:${GID}" + entrypoint: + - /surreal + - start + - --user + - "root" + - --pass + - "root" + - rocksdb:/data/database.db diff --git a/src/components/admin.rs b/src/components/admin.rs index 424919c..aecd750 100644 --- a/src/components/admin.rs +++ b/src/components/admin.rs @@ -1 +1,28 @@ +use crate::Route; +use dioxus::prelude::*; + pub mod members; +pub mod users; + +#[component] +pub fn Admin() -> Element { + rsx! { + div { + class: "w-full max-w-2xl space-y-3", + div { + class: "group join-vertical", + Link { + class: "btn join-item w-full justify-start rounded-b-none", + to: Route::Users {}, + "Gebruikers beheer" + }, + div { class: "divider join-item my-0 h-min" }, + Link { + class: "btn join-item w-full justify-start rounded-t-none", + to: Route::Members {}, + "Leden beheer" + }, + } + }, + } +} diff --git a/src/components/admin/members.rs b/src/components/admin/members.rs index fa21ae6..db23a08 100644 --- a/src/components/admin/members.rs +++ b/src/components/admin/members.rs @@ -58,7 +58,7 @@ fn MemberRow(props: MemberRowProps) -> Element { class: "hover hover:cursor-pointer", th { "{props.member.id}" } td { "{props.member.name.full}" } - td { "{registration_token}" } + td { "{registration_token} {props.member.hours:?}" } } } } diff --git a/src/components/admin/users.rs b/src/components/admin/users.rs new file mode 100644 index 0000000..e50fefa --- /dev/null +++ b/src/components/admin/users.rs @@ -0,0 +1,61 @@ +use dioxus::prelude::*; + +use crate::util::model::user::User; + +pub fn Users() -> Element { + let users = use_resource(fetch_users); + + rsx! { + div { + class: "flex justify-center", + div { + class: "max-w-4xl w-full", + h2 { class: "font-bold text-lg", "Gebruikers" }, + match &*users.read_unchecked() { + Some(Ok(res)) => rsx! { + div { + class: "overflow-x-auto", + table { + class: "table table-zebra table-pin-rows", + thead { + tr { + th { "Id" } + th { "Email" } + } + } + tbody { + for user in res { + UserRow { user: user.clone() } + } + } + } + } + }, + Some(Err(_)) => rsx! { div { "Error while loading users" } }, + None => rsx! { div { "Loading..." } }, + } + } + } + } +} + +#[derive(Props, Clone, PartialEq)] +struct UserRowProps { + user: User, +} + +fn UserRow(props: UserRowProps) -> Element { + rsx! { + tr { + class: "hover hover:cursor-pointer", + th { "{props.user.id}" } + td { "{props.user.email}" } + } + } +} + +#[server] +async fn fetch_users() -> Result, ServerFnError> { + let users = User::fetch_all().await?; + Ok(users) +} diff --git a/src/components/layout/topbar.rs b/src/components/layout/topbar.rs index ffe8aa8..212d68e 100644 --- a/src/components/layout/topbar.rs +++ b/src/components/layout/topbar.rs @@ -16,7 +16,7 @@ pub fn Topbar() -> Element { class: "flex-none gap-2", Link { class: "btn btn-ghost font-normal", - to: Route::Home {}, + to: Route::Admin {}, "Administration" } Link { diff --git a/src/components/settings.rs b/src/components/settings.rs index 3f176c9..fe55d36 100644 --- a/src/components/settings.rs +++ b/src/components/settings.rs @@ -51,7 +51,7 @@ fn Account() -> Element { class: "label", span { class: "label-text", "Account ID" } } - b { "{user.id}" }, + b { class: "select-all", "{user.id}" }, } label { class: "form-control w-full", diff --git a/src/main.rs b/src/main.rs index a9e18a3..c5bcdd2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,8 @@ use tracing::Level; // Use routes use components::admin::members::migration::Migration; use components::admin::members::Members; +use components::admin::users::Users; +use components::admin::Admin; use components::agenda::Agenda; use components::home::Home; use components::layout::Global; @@ -30,6 +32,10 @@ pub enum Route { News {}, #[route("/settings")] Settings {}, + #[route("/admin")] + Admin {}, + #[route("/admin/users")] + Users {}, #[route("/admin/members")] Members {}, #[route("/admin/members/migration")] diff --git a/src/util/model/member/migration.rs b/src/util/model/member/migration.rs index 957661e..e99da23 100644 --- a/src/util/model/member/migration.rs +++ b/src/util/model/member/migration.rs @@ -227,7 +227,7 @@ impl MembersMigration { // TODO add hours and diploma support let id = member.id.clone(); - transaction = transaction.query(format!("CREATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id}, registration_token = rand::string(16);")) + transaction = transaction.query(format!("CREATE type::thing('member', $id_{id}) SET name.first = $name_first_{id}, name.full = $name_full_{id}, hours = $hours_{id}, groups = $groups_{id};")) .bind((format!("id_{id}"), member.id)) .bind((format!("name_first_{id}"), member.name.first)) .bind((format!("name_full_{id}"), member.name.full)) diff --git a/src/util/model/user.rs b/src/util/model/user.rs index fdd012d..17b46f5 100644 --- a/src/util/model/user.rs +++ b/src/util/model/user.rs @@ -18,6 +18,16 @@ pub struct User { #[cfg(feature = "server")] impl User { + pub async fn fetch_all() -> Result, surrealdb::Error> { + let mut res = DB.query("SELECT id, email FROM user").await?; + + res = res.check()?; + + let users: Vec = res.take(0)?; + + Ok(users) + } + pub async fn new( email: String, password: String, @@ -93,17 +103,17 @@ impl User { password: String, ) -> Result { let mut res = DB - .query("SELECT VALUE id FROM user WHERE email = $email AND crypto::argon2::compare(password, $password)") + .query("SELECT id, email FROM user WHERE email = $email AND crypto::argon2::compare(password, $password)") .bind(("email", email)) .bind(("password", password)) .await?; res = res.check()?; - let id: Option = res.take(0)?; + let user: Option = res.take(0)?; - match id { - Some(i) => Ok(i), + match user { + Some(u) => Ok(u.id), None => Err(crate::Error::NoDocument), } } diff --git a/src/util/surrealdb.rs b/src/util/surrealdb.rs index 8eb9c4a..d6b3115 100644 --- a/src/util/surrealdb.rs +++ b/src/util/surrealdb.rs @@ -1,10 +1,11 @@ use once_cell::sync::Lazy; use serde::{Deserialize, Deserializer}; -use surrealdb::engine::local::{Db, RocksDb}; +use surrealdb::engine::remote::ws::{Client, Ws}; +use surrealdb::opt::auth::Root; use surrealdb::sql::Thing; use surrealdb::Surreal; -pub static DB: Lazy> = Lazy::new(|| Surreal::init()); +pub static DB: Lazy> = Lazy::new(|| Surreal::init()); pub fn thing_to_string<'de, D>(deserializer: D) -> Result where @@ -15,9 +16,15 @@ where } pub async fn initialize() -> surrealdb::Result<()> { - DB.connect::("./database").await?; + DB.connect::("localhost:8000").await?; - DB.use_ns("xvmcmm").use_db("xvmcmm").await?; + DB.signin(Root { + username: "root", + password: "root", + }) + .await?; + + DB.use_ns("wrbapp").use_db("wrbapp").await?; apply_queries().await?; @@ -47,6 +54,22 @@ async fn apply_queries() -> surrealdb::Result<()> { ) .await?; + // Define member table + DB.query( + " + DEFINE TABLE OVERWRITE member SCHEMAFULL; + + DEFINE FIELD name ON TABLE member TYPE object; + DEFINE FIELD name.first ON TABLE member TYPE string; + DEFINE FIELD name.full ON TABLE member TYPE string; + DEFINE FIELD registration_token ON TABLE member TYPE string + VALUE rand::string(16); + DEFINE FIELD hours ON TABLE member TYPE set; + DEFINE FIELD groups ON TABLE member TYPE set; + ", + ) + .await?; + // Define session table DB.query( "