Added all sql queries for agent & location + Dao methods
This commit is contained in:
parent
39d97f3660
commit
cfa25d2bf7
|
@ -80,7 +80,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6"
|
checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -195,7 +195,7 @@ dependencies = [
|
||||||
"actix-router",
|
"actix-router",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -521,9 +521,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cxx"
|
name = "cxx"
|
||||||
version = "1.0.92"
|
version = "1.0.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72"
|
checksum = "a9c00419335c41018365ddf7e4d5f1c12ee3659ddcf3e01974650ba1de73d038"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"cxxbridge-flags",
|
"cxxbridge-flags",
|
||||||
|
@ -533,9 +533,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cxx-build"
|
name = "cxx-build"
|
||||||
version = "1.0.92"
|
version = "1.0.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613"
|
checksum = "fb8307ad413a98fff033c8545ecf133e3257747b3bae935e7602aab8aa92d4ca"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"codespan-reporting",
|
"codespan-reporting",
|
||||||
|
@ -543,24 +543,24 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"scratch",
|
"scratch",
|
||||||
"syn",
|
"syn 2.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cxxbridge-flags"
|
name = "cxxbridge-flags"
|
||||||
version = "1.0.92"
|
version = "1.0.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97"
|
checksum = "edc52e2eb08915cb12596d29d55f0b5384f00d697a646dbd269b6ecb0fbd9d31"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cxxbridge-macro"
|
name = "cxxbridge-macro"
|
||||||
version = "1.0.92"
|
version = "1.0.93"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56"
|
checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -573,7 +573,7 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -629,7 +629,7 @@ dependencies = [
|
||||||
"proc-macro-hack",
|
"proc-macro-hack",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1562,22 +1562,22 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.156"
|
version = "1.0.157"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4"
|
checksum = "707de5fcf5df2b5788fca98dd7eab490bc2fd9b7ef1404defc462833b83f25ca"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.156"
|
version = "1.0.157"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d"
|
checksum = "78997f4555c22a7971214540c4a661291970619afd56de19f77e0de86296e1e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1765,7 +1765,7 @@ dependencies = [
|
||||||
"sha2",
|
"sha2",
|
||||||
"sqlx-core",
|
"sqlx-core",
|
||||||
"sqlx-rt",
|
"sqlx-rt",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1807,6 +1807,17 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4cff13bb1732bccfe3b246f3fdb09edfd51c01d6f5299b7ccd9457c2e4e37774"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "termcolor"
|
name = "termcolor"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
@ -1818,22 +1829,22 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.39"
|
version = "1.0.40"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c"
|
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror-impl"
|
name = "thiserror-impl"
|
||||||
version = "1.0.39"
|
version = "1.0.40"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
|
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 2.0.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1917,7 +1928,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1997,9 +2008,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
version = "0.3.11"
|
version = "0.3.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "524b68aca1d05e03fdf03fcdce2c6c94b6daf6d16861ddaa7e4f2b6638a9052c"
|
checksum = "7d502c968c6a838ead8e69b2ee18ec708802f99db92a0d156705ec9ef801993b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
|
@ -2071,7 +2082,7 @@ checksum = "c1b300a878652a387d2a0de915bdae8f1a548f0c6d45e072fe2688794b656cc9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2123,7 +2134,7 @@ dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2157,7 +2168,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn 1.0.109",
|
||||||
"wasm-bindgen-backend",
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
|
@ -23,4 +23,4 @@ uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
|
||||||
actix-web-utils = { git = "https://git.franklinblanco.dev/franklinblanco/actix-web-utils.git" }
|
actix-web-utils = { git = "https://git.franklinblanco.dev/franklinblanco/actix-web-utils.git" }
|
||||||
err = { git = "https://git.franklinblanco.dev/franklinblanco/err.git" }
|
err = { git = "https://git.franklinblanco.dev/franklinblanco/err.git" }
|
||||||
|
|
||||||
jl-types = { path = "../jl-types" }
|
jl-types = { path = "../jl-types", features = ["sqlx"]}
|
|
@ -0,0 +1 @@
|
||||||
|
DELETE FROM agent WHERE id = $1;
|
|
@ -0,0 +1,9 @@
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
full_name,
|
||||||
|
credential,
|
||||||
|
credential_type as "credential_type: _",
|
||||||
|
time_created,
|
||||||
|
last_updated
|
||||||
|
FROM agent where id = ANY($1)
|
||||||
|
ORDER BY time_created DESC;
|
|
@ -0,0 +1,8 @@
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
full_name,
|
||||||
|
credential,
|
||||||
|
credential_type as "credential_type: _",
|
||||||
|
time_created,
|
||||||
|
last_updated
|
||||||
|
FROM agent WHERE id = $1
|
|
@ -0,0 +1,11 @@
|
||||||
|
INSERT INTO agent (
|
||||||
|
id, full_name, credential, credential_type, time_created, last_updated
|
||||||
|
) VALUES (
|
||||||
|
$1, $2, $3, $4, $5, $5
|
||||||
|
) RETURNING
|
||||||
|
id,
|
||||||
|
full_name,
|
||||||
|
credential,
|
||||||
|
credential_type as "credential_type: _",
|
||||||
|
time_created,
|
||||||
|
last_updated;
|
|
@ -0,0 +1,12 @@
|
||||||
|
UPDATE agent SET
|
||||||
|
full_name = $1,
|
||||||
|
credential = $2,
|
||||||
|
credential_type = $3,
|
||||||
|
last_updated = $4
|
||||||
|
RETURNING
|
||||||
|
id,
|
||||||
|
full_name,
|
||||||
|
credential,
|
||||||
|
credential_type as "credential_type: _",
|
||||||
|
time_created,
|
||||||
|
last_updated;
|
|
@ -0,0 +1 @@
|
||||||
|
DELETE FROM location where id = $1;
|
|
@ -0,0 +1 @@
|
||||||
|
SELECT * FROM location WHERE city = $1 ORDER BY district DESC;
|
|
@ -0,0 +1 @@
|
||||||
|
SELECT * FROM location WHERE id = $1;
|
|
@ -0,0 +1,5 @@
|
||||||
|
INSERT INTO location (
|
||||||
|
id, city, district
|
||||||
|
) VALUES (
|
||||||
|
$1, $2, $3
|
||||||
|
) RETURNING *;
|
|
@ -0,0 +1,24 @@
|
||||||
|
use jl_types::domain::agent::Agent;
|
||||||
|
use sqlx::{Transaction, Postgres, PgPool, postgres::PgQueryResult};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn insert_agent(tx: &mut Transaction<'_, Postgres>, agent: &Agent) -> Result<Agent, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Agent, "sql/agent/insert.sql", agent.id, agent.full_name, agent.credential, agent.credential_type as _, agent.time_created).fetch_one(tx).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_agent_with_id(conn: &PgPool, agent_id: &Uuid) -> Result<Option<Agent>, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Agent, "sql/agent/get_with_id.sql", agent_id).fetch_optional(conn).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_agents_with_ids(conn: &PgPool, agent_ids: &Vec<Uuid>) -> Result<Vec<Agent>, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Agent, "sql/agent/fetch_with_ids.sql", agent_ids).fetch_all(conn).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_agent(tx: &mut Transaction<'_, Postgres>, agent: Agent) -> Result<Agent, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Agent, "sql/agent/update.sql", agent.full_name, agent.credential, agent.credential_type as _, agent.last_updated).fetch_one(tx).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_agent(tx: &mut Transaction<'_, Postgres>, agent_id: &Uuid) -> Result<PgQueryResult, sqlx::Error> {
|
||||||
|
sqlx::query_file!("sql/agent/delete.sql", agent_id).execute(tx).await
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
use jl_types::domain::location::Location;
|
||||||
|
use sqlx::{Transaction, Postgres, postgres::PgQueryResult, PgPool};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn insert_location(tx: &mut Transaction<'_, Postgres>, location: Location) -> Result<Location, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Location, "sql/location/insert.sql", location.id, location.city, location.district).fetch_one(tx).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_location_with_id(conn: &PgPool, location_id: &Uuid) -> Result<Option<Location>, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Location, "sql/location/get_with_id.sql", location_id).fetch_optional(conn).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_locations_in_city(conn: &PgPool, city: &String) -> Result<Vec<Location>, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Location, "sql/location/fetch_with_city.sql", city).fetch_all(conn).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_location(tx: &mut Transaction<'_, Postgres>, location_id: Uuid) -> Result<PgQueryResult, sqlx::Error> {
|
||||||
|
sqlx::query_file!("sql/location/delete.sql", location_id).execute(tx).await
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
pub mod main_dao;
|
pub mod main_dao;
|
||||||
|
|
||||||
pub mod project;
|
pub mod project;
|
||||||
pub mod agent;
|
pub mod agent;
|
||||||
pub mod location;
|
pub mod location;
|
||||||
|
|
Loading…
Reference in New Issue