diff --git a/Cargo.lock b/Cargo.lock index e8d5330..4ebfac9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1762,6 +1762,7 @@ dependencies = [ "postgres-protocol", "serde", "serde_json", + "time", ] [[package]] @@ -2245,6 +2246,7 @@ dependencies = [ "rust_decimal", "serde", "serde_json", + "time", "tokio-postgres", ] @@ -2763,6 +2765,7 @@ checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", "itoa", + "js-sys", "num-conv", "powerfmt", "serde", diff --git a/clorinde.toml b/clorinde.toml new file mode 100644 index 0000000..74782ea --- /dev/null +++ b/clorinde.toml @@ -0,0 +1,9 @@ +[package] +name = "samling-clorinde" +version = "0.12.0" +license = "MIT" +publish = true +description = "Database queries etc for the `samling` crate" +repository = "https://github.com/hyperkliv/samling" +documentation = "https://docs.rs/samling/" +homepage = "https://github.com/hyperkliv/samling" diff --git a/samling-clorinde/Cargo.toml b/samling-clorinde/Cargo.toml index 9124959..397b51c 100644 --- a/samling-clorinde/Cargo.toml +++ b/samling-clorinde/Cargo.toml @@ -2,17 +2,22 @@ [package] name = "samling-clorinde" version = "0.12.0" -license = "MIT" edition = "2021" +publish = true description = "Database queries etc for the `samling` crate" -repository = "https://github.com/hyperkliv/samling" documentation = "https://docs.rs/samling/" homepage = "https://github.com/hyperkliv/samling" +repository = "https://github.com/hyperkliv/samling" +license = "MIT" + [features] -default = ["deadpool"] +default = ["deadpool", "chrono"] deadpool = ["dep:deadpool-postgres", "tokio-postgres/default"] -wasm-async = ["tokio-postgres/js", "chrono/wasmbind"] +wasm-async = ["tokio-postgres/js", "chrono/wasmbind", "time/wasm-bindgen"] + +chrono = ["dep:chrono"] +time = ["dep:time"] [dependencies] ## Core dependencies @@ -25,21 +30,19 @@ fallible-iterator = "0.2.0" ## Types dependencies # JSON or JSONB -serde_json = { version = "1.0.135", features = ["raw_value"] } +serde_json = { version = "1.0.134", features = ["raw_value"] } serde = { version = "1.0.217", features = ["derive"] } # TIME, DATE, TIMESTAMP or TIMESTAMPZ -chrono = "0.4.39" +chrono = { version = "0.4.39", optional = true } +time = { version = "0.3.37", optional = true } # DECIMAL rust_decimal = { version = "1.36.0", features = ["db-postgres"] } ## Async client dependencies # Postgres async client -tokio-postgres = { version = "0.7.12", default-features = false, features = [ - "with-serde_json-1", - "with-chrono-0_4", -] } +tokio-postgres = { version = "0.7.12", default-features = false, features = ["with-serde_json-1","with-chrono-0_4","with-time-0_3",] } # Async utils -async-trait = "0.1.85" +async-trait = "0.1.78" futures = "0.3.31" ## Async features dependencies diff --git a/samling-clorinde/src/queries/attribute.rs b/samling-clorinde/src/queries/attribute.rs index f688d94..9ad4a0f 100644 --- a/samling-clorinde/src/queries/attribute.rs +++ b/samling-clorinde/src/queries/attribute.rs @@ -63,8 +63,8 @@ pub struct AttributeRow { pub slug: String, pub external_id: Option, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub r#type: serde_json::Value, } pub struct AttributeRowBorrowed<'a> { @@ -76,8 +76,8 @@ pub struct AttributeRowBorrowed<'a> { pub slug: &'a str, pub external_id: Option<&'a str>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub r#type: postgres_types::Json<&'a serde_json::value::RawValue>, } impl<'a> From> for AttributeRow { diff --git a/samling-clorinde/src/queries/attributetype.rs b/samling-clorinde/src/queries/attributetype.rs index 2c9a6ae..9f9db8a 100644 --- a/samling-clorinde/src/queries/attributetype.rs +++ b/samling-clorinde/src/queries/attributetype.rs @@ -44,8 +44,8 @@ pub struct AttributeTypeRow { pub slug: String, pub external_id: Option, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, } pub struct AttributeTypeRowBorrowed<'a> { pub id: i32, @@ -54,8 +54,8 @@ pub struct AttributeTypeRowBorrowed<'a> { pub slug: &'a str, pub external_id: Option<&'a str>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, } impl<'a> From> for AttributeTypeRow { fn from( diff --git a/samling-clorinde/src/queries/category.rs b/samling-clorinde/src/queries/category.rs index b5b86a9..252d3c3 100644 --- a/samling-clorinde/src/queries/category.rs +++ b/samling-clorinde/src/queries/category.rs @@ -47,8 +47,8 @@ pub struct CategoryRow { pub external_id: Option, pub name: serde_json::Value, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, } pub struct CategoryRowBorrowed<'a> { pub id: i32, @@ -57,8 +57,8 @@ pub struct CategoryRowBorrowed<'a> { pub external_id: Option<&'a str>, pub name: postgres_types::Json<&'a serde_json::value::RawValue>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, } impl<'a> From> for CategoryRow { fn from( diff --git a/samling-clorinde/src/queries/collection.rs b/samling-clorinde/src/queries/collection.rs index 9981da3..049146e 100644 --- a/samling-clorinde/src/queries/collection.rs +++ b/samling-clorinde/src/queries/collection.rs @@ -89,8 +89,8 @@ pub struct CollectionRow { pub external_id: Option, pub name: serde_json::Value, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub image_url: Option, pub acronym: serde_json::Value, pub pricing: serde_json::Value, @@ -103,8 +103,8 @@ pub struct CollectionRowBorrowed<'a> { pub external_id: Option<&'a str>, pub name: postgres_types::Json<&'a serde_json::value::RawValue>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub image_url: Option<&'a str>, pub acronym: postgres_types::Json<&'a serde_json::value::RawValue>, pub pricing: postgres_types::Json<&'a serde_json::value::RawValue>, @@ -151,8 +151,8 @@ pub struct CollectionSummaryRow { pub external_id: Option, pub name: serde_json::Value, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub image_url: Option, pub acronym: serde_json::Value, pub num_sizes: i64, @@ -167,8 +167,8 @@ pub struct CollectionSummaryRowBorrowed<'a> { pub external_id: Option<&'a str>, pub name: postgres_types::Json<&'a serde_json::value::RawValue>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub image_url: Option<&'a str>, pub acronym: postgres_types::Json<&'a serde_json::value::RawValue>, pub num_sizes: i64, diff --git a/samling-clorinde/src/queries/color.rs b/samling-clorinde/src/queries/color.rs index 97c8a06..e628379 100644 --- a/samling-clorinde/src/queries/color.rs +++ b/samling-clorinde/src/queries/color.rs @@ -65,8 +65,8 @@ pub struct ColorRow { pub number: String, pub name: serde_json::Value, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub style: serde_json::Value, pub images: serde_json::Value, } @@ -79,8 +79,8 @@ pub struct ColorRowBorrowed<'a> { pub number: &'a str, pub name: postgres_types::Json<&'a serde_json::value::RawValue>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub style: postgres_types::Json<&'a serde_json::value::RawValue>, pub images: postgres_types::Json<&'a serde_json::value::RawValue>, } diff --git a/samling-clorinde/src/queries/group.rs b/samling-clorinde/src/queries/group.rs index dcc1c6c..b368c7b 100644 --- a/samling-clorinde/src/queries/group.rs +++ b/samling-clorinde/src/queries/group.rs @@ -77,8 +77,8 @@ pub struct GroupRow { pub name: String, pub description: String, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub users: serde_json::Value, pub collections: serde_json::Value, pub price_lists: serde_json::Value, @@ -91,8 +91,8 @@ pub struct GroupRowBorrowed<'a> { pub name: &'a str, pub description: &'a str, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub users: postgres_types::Json<&'a serde_json::value::RawValue>, pub collections: postgres_types::Json<&'a serde_json::value::RawValue>, pub price_lists: postgres_types::Json<&'a serde_json::value::RawValue>, diff --git a/samling-clorinde/src/queries/image.rs b/samling-clorinde/src/queries/image.rs index 21bcf69..0f1ef90 100644 --- a/samling-clorinde/src/queries/image.rs +++ b/samling-clorinde/src/queries/image.rs @@ -51,8 +51,8 @@ pub struct ImageRow { pub position: i32, pub color_id: i32, pub uploaded_by: Option, - pub uploaded_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub uploaded_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub color: serde_json::Value, } pub struct ImageRowBorrowed<'a> { @@ -64,8 +64,8 @@ pub struct ImageRowBorrowed<'a> { pub position: i32, pub color_id: i32, pub uploaded_by: Option, - pub uploaded_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub uploaded_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub color: postgres_types::Json<&'a serde_json::value::RawValue>, } impl<'a> From> for ImageRow { diff --git a/samling-clorinde/src/queries/organization.rs b/samling-clorinde/src/queries/organization.rs index 255a817..112e9a1 100644 --- a/samling-clorinde/src/queries/organization.rs +++ b/samling-clorinde/src/queries/organization.rs @@ -17,16 +17,16 @@ pub struct OrganizationRow { pub id: i32, pub name: String, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub logo_url: Option, } pub struct OrganizationRowBorrowed<'a> { pub id: i32, pub name: &'a str, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub logo_url: Option<&'a str>, } impl<'a> From> for OrganizationRow { diff --git a/samling-clorinde/src/queries/price.rs b/samling-clorinde/src/queries/price.rs index 3f9e95d..37a23a9 100644 --- a/samling-clorinde/src/queries/price.rs +++ b/samling-clorinde/src/queries/price.rs @@ -22,8 +22,8 @@ pub struct InsertPriceParams, pub currency: T2, pub amount: rust_decimal::Decimal, - pub start: chrono::NaiveDate, - pub end: chrono::NaiveDate, + pub start: crate::types::time::Date, + pub end: crate::types::time::Date, pub style_id: i32, pub list_id: i32, pub external_id: Option, @@ -36,8 +36,8 @@ pub struct UpdatePriceParams, pub currency: Option, pub amount: Option, - pub start: Option, - pub end: Option, + pub start: Option, + pub end: Option, pub style_id: Option, pub list_id: Option, pub external_id: Option, @@ -59,11 +59,11 @@ pub struct PriceRow { pub external_id: Option, pub style_id: i32, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub amount: rust_decimal::Decimal, - pub start: chrono::NaiveDate, - pub end: chrono::NaiveDate, + pub start: crate::types::time::Date, + pub end: crate::types::time::Date, pub style: serde_json::Value, pub list: serde_json::Value, } @@ -77,11 +77,11 @@ pub struct PriceRowBorrowed<'a> { pub external_id: Option<&'a str>, pub style_id: i32, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub amount: rust_decimal::Decimal, - pub start: chrono::NaiveDate, - pub end: chrono::NaiveDate, + pub start: crate::types::time::Date, + pub end: crate::types::time::Date, pub style: postgres_types::Json<&'a serde_json::value::RawValue>, pub list: postgres_types::Json<&'a serde_json::value::RawValue>, } @@ -429,8 +429,8 @@ impl InsertPriceStmt { uom: &'a Option, currency: &'a T2, amount: &'a rust_decimal::Decimal, - start: &'a chrono::NaiveDate, - end: &'a chrono::NaiveDate, + start: &'a crate::types::time::Date, + end: &'a crate::types::time::Date, style_id: &'a i32, list_id: &'a i32, external_id: &'a Option, @@ -516,8 +516,8 @@ impl UpdatePriceStmt { uom: &'a Option, currency: &'a Option, amount: &'a Option, - start: &'a Option, - end: &'a Option, + start: &'a Option, + end: &'a Option, style_id: &'a Option, list_id: &'a Option, external_id: &'a Option, diff --git a/samling-clorinde/src/queries/pricelist.rs b/samling-clorinde/src/queries/pricelist.rs index f7e127c..e24aa74 100644 --- a/samling-clorinde/src/queries/pricelist.rs +++ b/samling-clorinde/src/queries/pricelist.rs @@ -57,8 +57,8 @@ pub struct PriceListRow { pub slug: String, pub external_id: Option, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, } pub struct PriceListRowBorrowed<'a> { pub id: i32, @@ -67,8 +67,8 @@ pub struct PriceListRowBorrowed<'a> { pub slug: &'a str, pub external_id: Option<&'a str>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, } impl<'a> From> for PriceListRow { fn from( diff --git a/samling-clorinde/src/queries/size.rs b/samling-clorinde/src/queries/size.rs index 56f68a9..6cf66f0 100644 --- a/samling-clorinde/src/queries/size.rs +++ b/samling-clorinde/src/queries/size.rs @@ -29,7 +29,7 @@ pub struct InsertSizeParams< pub number: T3, pub name: T4, pub service_item: Option, - pub delivery_period: Option, + pub delivery_period: Option, pub ean_code: Option, pub status: Option, pub organization_id: i32, @@ -51,7 +51,7 @@ pub struct UpdateSizeParams< pub position: Option, pub name: Option, pub service_item: Option, - pub delivery_period: Option, + pub delivery_period: Option, pub ean_code: Option, pub status: Option, pub id: i32, @@ -71,10 +71,10 @@ pub struct SizeRow { pub number: String, pub name: serde_json::Value, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub service_item: Option, - pub delivery_period: Option, + pub delivery_period: Option, pub ean_code: Option, pub status: Option, pub position: i16, @@ -89,10 +89,10 @@ pub struct SizeRowBorrowed<'a> { pub number: &'a str, pub name: postgres_types::Json<&'a serde_json::value::RawValue>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub service_item: Option, - pub delivery_period: Option, + pub delivery_period: Option, pub ean_code: Option<&'a str>, pub status: Option<&'a str>, pub position: i16, @@ -514,7 +514,7 @@ impl InsertSizeStmt { number: &'a T3, name: &'a T4, service_item: &'a Option, - delivery_period: &'a Option, + delivery_period: &'a Option, ean_code: &'a Option, status: &'a Option, organization_id: &'a i32, @@ -619,7 +619,7 @@ impl UpdateSizeStmt { position: &'a Option, name: &'a Option, service_item: &'a Option, - delivery_period: &'a Option, + delivery_period: &'a Option, ean_code: &'a Option, status: &'a Option, id: &'a i32, diff --git a/samling-clorinde/src/queries/style.rs b/samling-clorinde/src/queries/style.rs index 0927e00..9a6b28c 100644 --- a/samling-clorinde/src/queries/style.rs +++ b/samling-clorinde/src/queries/style.rs @@ -107,8 +107,8 @@ pub struct StyleRow { pub number: String, pub name: serde_json::Value, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub description: serde_json::Value, pub core: Option, pub country_of_origin: Option, @@ -127,8 +127,8 @@ pub struct StyleRowBorrowed<'a> { pub number: &'a str, pub name: postgres_types::Json<&'a serde_json::value::RawValue>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub description: postgres_types::Json<&'a serde_json::value::RawValue>, pub core: Option, pub country_of_origin: Option<&'a str>, @@ -193,8 +193,8 @@ pub struct NestedStyleRow { pub number: String, pub name: serde_json::Value, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub description: serde_json::Value, pub core: Option, pub country_of_origin: Option, @@ -216,8 +216,8 @@ pub struct NestedStyleRowBorrowed<'a> { pub number: &'a str, pub name: postgres_types::Json<&'a serde_json::value::RawValue>, pub created_by: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub description: postgres_types::Json<&'a serde_json::value::RawValue>, pub core: Option, pub country_of_origin: Option<&'a str>, diff --git a/samling-clorinde/src/queries/user.rs b/samling-clorinde/src/queries/user.rs index 5a30338..40871e1 100644 --- a/samling-clorinde/src/queries/user.rs +++ b/samling-clorinde/src/queries/user.rs @@ -64,10 +64,10 @@ pub struct UserRow { pub name: String, pub email: String, pub password_hash: Option, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub profile_image: Option, - pub last_sign_in: Option>, + pub last_sign_in: Option, pub organizations: serde_json::Value, pub groups: serde_json::Value, } @@ -76,10 +76,10 @@ pub struct UserRowBorrowed<'a> { pub name: &'a str, pub email: &'a str, pub password_hash: Option<&'a str>, - pub created_at: chrono::DateTime, - pub updated_at: chrono::DateTime, + pub created_at: crate::types::time::TimestampTz, + pub updated_at: crate::types::time::TimestampTz, pub profile_image: Option<&'a str>, - pub last_sign_in: Option>, + pub last_sign_in: Option, pub organizations: postgres_types::Json<&'a serde_json::value::RawValue>, pub groups: postgres_types::Json<&'a serde_json::value::RawValue>, } diff --git a/samling-clorinde/src/types.rs b/samling-clorinde/src/types.rs index 3720630..f157558 100644 --- a/samling-clorinde/src/types.rs +++ b/samling-clorinde/src/types.rs @@ -1,12 +1,26 @@ // This file was generated with `clorinde`. Do not modify. +#[cfg(feature = "chrono")] +pub mod time { + pub type Timestamp = chrono::NaiveDateTime; + pub type TimestampTz = chrono::DateTime; + pub type Date = chrono::NaiveDate; + pub type Time = chrono::NaiveTime; +} +#[cfg(feature = "time")] +pub mod time { + pub type Timestamp = time::PrimitiveDateTime; + pub type TimestampTz = time::OffsetDateTime; + pub type Date = time::Date; + pub type Time = time::Time; +} #[derive(Debug, postgres_types::FromSql, Copy, Clone, PartialEq)] #[postgres(name = "collection_pricelist_relation")] pub struct CollectionPricelistRelation { #[postgres(name = "pricelist_id")] pub pricelist_id: i32, #[postgres(name = "price_date")] - pub price_date: chrono::NaiveDate, + pub price_date: crate::types::time::Date, #[postgres(name = "created_by")] pub created_by: i32, } @@ -62,7 +76,7 @@ impl<'a> postgres_types::ToSql for CollectionPricelistRelation { fields.iter().all(|f| match f.name() { "pricelist_id" => ::accepts(f.type_()), "price_date" => { - ::accepts(f.type_()) + ::accepts(f.type_()) } "created_by" => ::accepts(f.type_()), _ => false,