Skip to content

Commit

Permalink
editoast: move model v2 database tools to editoast_models
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadjetz committed Jul 1, 2024
1 parent e79e415 commit e7046be
Show file tree
Hide file tree
Showing 115 changed files with 254 additions and 199 deletions.
19 changes: 19 additions & 0 deletions editoast/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 30 additions & 16 deletions editoast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,35 @@ members = [
".",
"editoast_common",
"editoast_derive",
"editoast_models",
"editoast_schemas",
"osm_to_railjson",
]

[workspace.dependencies]
chrono = { version = "0.4.38", features = ["serde"] }
derivative = "2.2.0"
diesel = { version = "2.1.6", features = [
"chrono",
"postgres",
"serde_json",
"uuid",
] }
diesel-async = { version = "0.4.1", features = ["deadpool", "postgres"] }
editoast_common = { path = "./editoast_common" }
editoast_derive = { path = "./editoast_derive" }
editoast_models = { path = "./editoast_models" }
editoast_schemas = { path = "./editoast_schemas" }
enum-map = "2.7.3"
futures = "0.3.30"
futures-util = "0.3.30"
geojson = "*"
geos = { version = "8.3.1", features = ["json"] }
mvt = "0.9.3"
openssl = "*"
paste = "1.0.15"
postgis_diesel = { version = "2.3.1", features = ["serde"] }
postgres-openssl = "0.5.0"
rand = "0.8.5"
rangemap = "1.5.1"
rstest = "0.19.0"
Expand All @@ -33,7 +47,10 @@ serde_json = "1.0.118"
strum = { version = "0.26.3", features = ["derive"] }
tempfile = "3.10.1"
thiserror = "1.0.61"
tokio = "*"
tokio-postgres = "*"
tracing = { version = "0.1.40", features = ["log"] }
url = { version = "2.5.2", features = ["serde"] }
utoipa = { version = "4.2.3", features = ["actix_extras", "chrono", "uuid"] }
uuid = { version = "1.9.1", features = ["serde", "v4"] }

Expand All @@ -53,29 +70,25 @@ chrono.workspace = true
clap = { version = "4.5.7", features = ["derive", "env"] }
colored = "2.1.0"
derivative.workspace = true
diesel = { version = "2.1.6", features = [
"chrono",
"postgres",
"serde_json",
"uuid",
] }
diesel-async = { version = "0.4.1", features = ["deadpool", "postgres"] }
diesel.workspace = true
diesel-async = { workspace = true }
diesel_json = "0.2.1"
editoast_common = { workspace = true }
editoast_derive = { path = "./editoast_derive" }
editoast_schemas = { workspace = true }
editoast_derive.workspace = true
editoast_models.workspace = true
editoast_schemas.workspace = true
enum-map.workspace = true
enumset = "1.1.3"
futures = "0.3.30"
futures-util = "*"
futures.workspace = true
futures-util.workspace = true
geos.workspace = true
heck = "0.5.0"
image = "0.25.1"
inventory = "0.3"
itertools = "0.13.0"
json-patch = { version = "2.0.0", features = ["utoipa"] }
mvt.workspace = true
openssl = "*"
openssl.workspace = true
opentelemetry = "0.23.0"
opentelemetry-datadog = { version = "0.11.0", features = ["reqwest-client"] }
opentelemetry-otlp = "0.16.0"
Expand All @@ -85,7 +98,7 @@ osm_to_railjson = { path = "./osm_to_railjson" }
paste.workspace = true
pathfinding = "4.10.0"
postgis_diesel.workspace = true
postgres-openssl = "0.5.0"
postgres-openssl.workspace = true
rand.workspace = true
rangemap.workspace = true
redis = { version = "0.25.4", features = [
Expand All @@ -105,18 +118,19 @@ serde_yaml = "0.9.34"
sha1 = "0.10"
strum.workspace = true
thiserror.workspace = true
tokio = "*"
tokio-postgres = "*"
tokio.workspace = true
tokio-postgres.workspace = true
tracing.workspace = true
tracing-opentelemetry = "0.24.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
url = { version = "2.5.2", features = ["serde"] }
url.workspace = true
utoipa.workspace = true
uuid.workspace = true
validator = { version = "0.18.1", features = ["derive"] }

[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
editoast_models = { workspace = true, features = ["testing"] }
pretty_assertions = "1.4.0"
rstest.workspace = true
serial_test = "3.1.1"
Expand Down
14 changes: 7 additions & 7 deletions editoast/editoast_derive/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ fn create_functions(config: &Config) -> TokenStream {
quote! {
#[async_trait::async_trait]
impl crate::models::Create for #model_name {
async fn create_conn(self, conn: &mut crate::modelsv2::DbConnection) -> crate::error::Result<Self> {
async fn create_conn(self, conn: &mut editoast_models::database::DbConnection) -> crate::error::Result<Self> {
use #table::table;
use diesel_async::RunQueryDsl;

Ok(diesel::insert_into(table).values(&self).get_result(conn).await?)
}

#[doc = #documentation]
async fn create(self, db_pool: std::sync::Arc<crate::modelsv2::DbConnectionPool>) -> crate::error::Result<Self> {
async fn create(self, db_pool: std::sync::Arc<editoast_models::database::DbConnectionPool>) -> crate::error::Result<Self> {
let mut conn = db_pool.get().await?;
self.create_conn(&mut conn).await
}
Expand Down Expand Up @@ -126,7 +126,7 @@ fn retrieve_functions(config: &Config) -> TokenStream {
quote! {
#[async_trait::async_trait]
impl crate::models::Retrieve for #model_name {
async fn retrieve_conn(conn: &mut crate::modelsv2::DbConnection, obj_id: i64) -> crate::error::Result<Option<Self>> {
async fn retrieve_conn(conn: &mut editoast_models::database::DbConnection, obj_id: i64) -> crate::error::Result<Option<Self>> {
use #table::table;
use #table::dsl;
use diesel_async::RunQueryDsl;
Expand All @@ -142,7 +142,7 @@ fn retrieve_functions(config: &Config) -> TokenStream {
}

#[doc = #retrieve_documentation]
async fn retrieve(db_pool: std::sync::Arc<crate::modelsv2::DbConnectionPool>, id: i64) -> crate::error::Result<Option<Self>> {
async fn retrieve(db_pool: std::sync::Arc<editoast_models::database::DbConnectionPool>, id: i64) -> crate::error::Result<Option<Self>> {
let mut conn = db_pool.get().await?;
Self::retrieve_conn(&mut conn, id).await
}
Expand Down Expand Up @@ -174,7 +174,7 @@ fn delete_functions(config: &Config) -> TokenStream {
quote! {
#[async_trait::async_trait]
impl crate::models::Delete for #model_name {
async fn delete_conn(conn: &mut crate::modelsv2::DbConnection, obj_id: i64) -> crate::error::Result<bool> {
async fn delete_conn(conn: &mut editoast_models::database::DbConnection, obj_id: i64) -> crate::error::Result<bool> {
use #table::table;
use #table::dsl;
use diesel_async::RunQueryDsl;
Expand All @@ -188,7 +188,7 @@ fn delete_functions(config: &Config) -> TokenStream {
}

#[doc = #documentation]
async fn delete(db_pool: std::sync::Arc<crate::modelsv2::DbConnectionPool>, id: i64) -> crate::error::Result<bool> {
async fn delete(db_pool: std::sync::Arc<editoast_models::database::DbConnectionPool>, id: i64) -> crate::error::Result<bool> {
let mut conn = db_pool.get().await?;
Self::delete_conn(&mut conn, id).await
}
Expand All @@ -207,7 +207,7 @@ fn update_functions(config: &Config) -> TokenStream {
quote! {
#[async_trait::async_trait]
impl crate::models::Update for #model_name {
async fn update_conn(self, conn: &mut crate::modelsv2::DbConnection, obj_id: i64) -> crate::error::Result<Option<Self>> {
async fn update_conn(self, conn: &mut editoast_models::database::DbConnection, obj_id: i64) -> crate::error::Result<Option<Self>> {
use #table::table;

match diesel::update(table.find(obj_id)).set(&self).get_result(conn).await
Expand Down
2 changes: 1 addition & 1 deletion editoast/editoast_derive/src/modelv2/codegen/count_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl ToTokens for CountImpl {
offset,
))]
async fn count(
conn: &'async_trait mut crate::modelsv2::DbConnection,
conn: &'async_trait mut editoast_models::database::DbConnection,
settings: crate::modelsv2::prelude::SelectionSettings<Self>,
) -> crate::error::Result<u64> {
use diesel::QueryDsl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl ToTokens for CreateBatchImpl {
I: std::iter::IntoIterator<Item = #changeset> + Send + 'async_trait,
C: Default + std::iter::Extend<Self> + Send + std::fmt::Debug,
>(
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
values: I,
) -> crate::error::Result<C> {
use crate::modelsv2::Model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl ToTokens for CreateBatchWithKeyImpl {
I: std::iter::IntoIterator<Item = #changeset> + Send + 'async_trait,
C: Default + std::iter::Extend<(#ty, Self)> + Send + std::fmt::Debug,
>(
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
values: I,
) -> crate::error::Result<C> {
use crate::models::Identifiable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl ToTokens for CreateImpl {
#[tracing::instrument(name = #span_name, skip_all, err)]
async fn create(
self,
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
) -> crate::error::Result<#model> {
use diesel_async::RunQueryDsl;
diesel::insert_into(#table_mod::table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ToTokens for DeleteBatchImpl {
impl crate::modelsv2::DeleteBatch<#ty> for #model {
#[tracing::instrument(name = #span_name, skip_all, ret, err, fields(query_ids))]
async fn delete_batch<I: std::iter::IntoIterator<Item = #ty> + Send + 'async_trait>(
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
ids: I,
) -> crate::error::Result<usize> {
use #table_mod::dsl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl ToTokens for DeleteImpl {
#[tracing::instrument(name = #span_name, skip_all, ret, err, fields(query_id = ?self.#primary_key))]
async fn delete(
&self,
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
) -> crate::error::Result<bool> {
use diesel::prelude::*;
use diesel_async::RunQueryDsl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ToTokens for DeleteStaticImpl {
impl crate::modelsv2::DeleteStatic<#ty> for #model {
#[tracing::instrument(name = #span_name, skip_all, ret, err, fields(query_id))]
async fn delete_static(
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
#id_ident: #ty,
) -> crate::error::Result<bool> {
use diesel::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ToTokens for ExistsImpl {
impl crate::modelsv2::Exists<#ty> for #model {
#[tracing::instrument(name = #span_name, skip_all, ret, err, fields(query_id))]
async fn exists(
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
#id_ident: #ty,
) -> crate::error::Result<bool> {
use diesel::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion editoast/editoast_derive/src/modelv2/codegen/list_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl ToTokens for ListImpl {
offset,
))]
async fn list(
conn: &'async_trait mut crate::modelsv2::DbConnection,
conn: &'async_trait mut editoast_models::database::DbConnection,
settings: crate::modelsv2::prelude::SelectionSettings<Self>,
) -> crate::error::Result<Vec<Self>> {
use diesel::QueryDsl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl ToTokens for RetrieveBatchImpl {
I: std::iter::IntoIterator<Item = #ty> + Send + 'async_trait,
C: Default + std::iter::Extend<#model> + Send + std::fmt::Debug,
>(
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
ids: I,
) -> crate::error::Result<C> {
use crate::modelsv2::Model;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl ToTokens for RetrieveBatchImpl {
I: std::iter::IntoIterator<Item = #ty> + Send + 'async_trait,
C: Default + std::iter::Extend<(#ty, #model)> + Send + std::fmt::Debug,
>(
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
ids: I,
) -> crate::error::Result<C> {
use crate::models::Identifiable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl ToTokens for RetrieveImpl {
impl crate::modelsv2::Retrieve<#ty> for #model {
#[tracing::instrument(name = #span_name, skip_all, err, fields(query_id))]
async fn retrieve(
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
#id_ident: #ty,
) -> crate::error::Result<Option<#model>> {
use diesel::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl ToTokens for UpdateBatchImpl {
C: Default + std::iter::Extend<#model> + Send + std::fmt::Debug,
>(
self,
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
ids: I,
) -> crate::error::Result<C> {
use crate::modelsv2::Model;
Expand Down Expand Up @@ -80,7 +80,7 @@ impl ToTokens for UpdateBatchImpl {
C: Default + std::iter::Extend<(#ty, #model)> + Send,
>(
self,
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
ids: I,
) -> crate::error::Result<C> {
use crate::models::Identifiable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ToTokens for UpdateImpl {
#[tracing::instrument(name = #span_name, skip_all, err, fields(query_id))]
async fn update(
self,
conn: &mut crate::modelsv2::DbConnection,
conn: &mut editoast_models::database::DbConnection,
#id_ident: #ty,
) -> crate::error::Result<Option<#model>> {
use diesel::prelude::*;
Expand Down
21 changes: 21 additions & 0 deletions editoast/editoast_models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "editoast_models"
version = "0.1.0"
edition = "2021"

[features]
testing = []

[dependencies]
diesel.workspace = true
diesel-async.workspace = true
editoast_derive.workspace = true
futures.workspace = true
futures-util.workspace = true
openssl.workspace = true
postgres-openssl.workspace = true
thiserror.workspace = true
tokio.workspace = true
tokio-postgres.workspace = true
tracing.workspace = true
url.workspace = true
File renamed without changes.
Loading

0 comments on commit e7046be

Please sign in to comment.