[#24] Initialized diesel project

master^2
Jef Roosens 2021-04-15 17:53:35 +02:00
parent 5e28949b5c
commit 727589b10f
Signed by: Jef Roosens
GPG Key ID: 955C0660072F691F
9 changed files with 88 additions and 7 deletions

3
.env
View File

@ -1 +1,2 @@
DATABASE_URL=postgres://fej:fej@fej_db:5432/fej
# This file is read by diesel
DATABASE_URL=postgres://fej:fej@localhost:5432/fej

2
.env.container 100644
View File

@ -0,0 +1,2 @@
# This file is read by the container, and therefore by fej
DATABASE_URL=postgres://fej:fej@fej_db:5432/fej

33
Cargo.lock generated
View File

@ -321,6 +321,29 @@ dependencies = [
"syn 0.15.44",
]
[[package]]
name = "diesel"
version = "1.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "047bfc4d5c3bd2ef6ca6f981941046113524b9a9f9a7cbdfdd7ff40f58e6f542"
dependencies = [
"bitflags",
"byteorder",
"diesel_derives",
"pq-sys",
]
[[package]]
name = "diesel_derives"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
dependencies = [
"proc-macro2 1.0.26",
"quote 1.0.9",
"syn 1.0.69",
]
[[package]]
name = "digest"
version = "0.9.0"
@ -351,6 +374,7 @@ version = "1.0.1"
dependencies = [
"chrono",
"chrono-tz",
"diesel",
"regex",
"reqwest",
"rocket",
@ -1119,6 +1143,15 @@ version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "pq-sys"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda"
dependencies = [
"vcpkg",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"

View File

@ -25,11 +25,8 @@ serde = "1.0.124"
chrono = "0.4.19"
chrono-tz = "0.5.3"
regex = "1.4.5"
[dependencies.reqwest]
version = "0.11.2"
default-features = true
features = ["blocking", "json", "cookies"]
reqwest = { version = "0.11.2", features = ["blocking", "json", "cookies"] }
diesel = { version = "1.4.6", features = ["postgres"] }
[dependencies.rocket_contrib]
version = "0.4.7"

3
build
View File

@ -81,6 +81,7 @@ elif [[ "$action" = run ]]; then
--detach \
--name fej_db \
--network fej \
-p 5432:5432 \
-e "POSTGRES_DB=fej" \
-e "POSTGRES_USER=fej" \
-e "POSTGRES_PASSWORD=fej" \
@ -101,7 +102,7 @@ elif [[ "$action" = run ]]; then
--tty \
--publish 8000:8000 \
--name fej \
--env-file .env \
--env-file .env.container \
--network fej \
"$image$([[ "$mode" != "rel" ]] && echo "-dev"):$tags" "$@"
fi

5
diesel.toml 100644
View File

@ -0,0 +1,5 @@
# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src/schema.rs"

View File

View File

@ -0,0 +1,6 @@
-- 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();

View File

@ -0,0 +1,36 @@
-- 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;