[#24] Initialized diesel project
parent
5e28949b5c
commit
727589b10f
3
.env
3
.env
|
@ -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
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
# This file is read by the container, and therefore by fej
|
||||
DATABASE_URL=postgres://fej:fej@fej_db:5432/fej
|
|
@ -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"
|
||||
|
|
|
@ -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
3
build
|
@ -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
|
||||
|
|
|
@ -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"
|
|
@ -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();
|
|
@ -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;
|
Loading…
Reference in New Issue