Skip to content

Commit

Permalink
test: change "advanced_queries" to be compile-able
Browse files Browse the repository at this point in the history
  • Loading branch information
hasezoey committed Jan 16, 2024
1 parent 19eb3f8 commit 82ddae5
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 30 deletions.
10 changes: 10 additions & 0 deletions test/Cargo.lock

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

1 change: 1 addition & 0 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"simple_table_sqlite",
"custom_model_and_schema_path",
"single_model_file",
"advanced_queries",
]
resolver = "2"

Expand Down
17 changes: 17 additions & 0 deletions test/advanced_queries/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[lib]
path = "lib.rs"

[package]
name = "advanced_queries"
version = "0.1.0"
edition = "2021"

[dependencies]
diesel = { version = "*", default-features = false, features = [
"postgres",
"r2d2",
"chrono",
] }
r2d2.workspace = true
chrono.workspace = true
serde.workspace = true
6 changes: 6 additions & 0 deletions test/advanced_queries/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod models;
pub mod schema;

pub mod diesel {
pub use diesel::*;
}
50 changes: 23 additions & 27 deletions test/advanced_queries/models/todos/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,56 @@ pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::Connectio
pub struct Todos {
/// Field representing column `id`
pub id: i32,
/// Field representing column `unsigned`
pub unsigned: u32,
/// Field representing column `unsigned_nullable`
pub unsigned_nullable: Option<u32>,
/// Field representing column `text`
pub text: String,
/// Field representing column `completed`
pub completed: bool,
/// Field representing column `type`
pub type_: String,
/// Field representing column `smallint`
pub smallint: i16,
/// Field representing column `bigint`
pub bigint: i64,
/// Field representing column `created_at`
pub created_at: chrono::DateTime<chrono::Utc>,
/// Field representing column `updated_at`
pub updated_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::NaiveDateTime,
}

/// Create Struct for a row in table `todos` for [`Todos`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Insertable)]
#[diesel(table_name=todos)]
pub struct CreateTodos {
/// Field representing column `unsigned`
pub unsigned: u32,
/// Field representing column `unsigned_nullable`
pub unsigned_nullable: Option<u32>,
/// Field representing column `text`
pub text: String,
/// Field representing column `completed`
pub completed: bool,
/// Field representing column `type`
pub type_: String,
/// Field representing column `smallint`
pub smallint: i16,
/// Field representing column `bigint`
pub bigint: i64,
}

/// Update Struct for a row in table `todos` for [`Todos`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::AsChangeset, PartialEq, Default)]
#[diesel(table_name=todos)]
pub struct UpdateTodos {
/// Field representing column `unsigned`
pub unsigned: Option<u32>,
/// Field representing column `unsigned_nullable`
pub unsigned_nullable: Option<Option<u32>>,
/// Field representing column `text`
pub text: Option<String>,
/// Field representing column `completed`
pub completed: Option<bool>,
/// Field representing column `type`
pub type_: Option<String>,
/// Field representing column `smallint`
pub smallint: Option<i16>,
/// Field representing column `bigint`
pub bigint: Option<i64>,
/// Field representing column `created_at`
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
/// Field representing column `updated_at`
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
pub updated_at: Option<chrono::NaiveDateTime>,
}

/// Result of a `.paginate` function
Expand Down Expand Up @@ -134,16 +134,6 @@ impl Todos {
if let Some(filter_id) = filter.id.clone() {
query = query.filter(crate::schema::todos::id.eq(filter_id));
}
if let Some(filter_unsigned) = filter.unsigned.clone() {
query = query.filter(crate::schema::todos::unsigned.eq(filter_unsigned));
}
if let Some(filter_unsigned_nullable) = filter.unsigned_nullable.clone() {
query = if filter_unsigned_nullable.is_some() {
query.filter(crate::schema::todos::unsigned_nullable.eq(filter_unsigned_nullable))
} else {
query.filter(crate::schema::todos::unsigned_nullable.is_null())
};
}
if let Some(filter_text) = filter.text.clone() {
query = query.filter(crate::schema::todos::text.eq(filter_text));
}
Expand All @@ -153,6 +143,12 @@ impl Todos {
if let Some(filter_type_) = filter.type_.clone() {
query = query.filter(crate::schema::todos::type_.eq(filter_type_));
}
if let Some(filter_smallint) = filter.smallint.clone() {
query = query.filter(crate::schema::todos::smallint.eq(filter_smallint));
}
if let Some(filter_bigint) = filter.bigint.clone() {
query = query.filter(crate::schema::todos::bigint.eq(filter_bigint));
}
if let Some(filter_created_at) = filter.created_at.clone() {
query = query.filter(crate::schema::todos::created_at.eq(filter_created_at));
}
Expand Down Expand Up @@ -180,11 +176,11 @@ impl Todos {
#[derive(Debug, Default, Clone)]
pub struct TodosFilter {
pub id: Option<i32>,
pub unsigned: Option<u32>,
pub unsigned_nullable: Option<Option<u32>>,
pub text: Option<String>,
pub completed: Option<bool>,
pub type_: Option<String>,
pub smallint: Option<i16>,
pub bigint: Option<i64>,
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
pub updated_at: Option<chrono::NaiveDateTime>,
}
6 changes: 3 additions & 3 deletions test/advanced_queries/schema.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
diesel::table! {
todos (id) {
id -> Int4,
unsigned -> Unsigned<Integer>,
unsigned_nullable -> Nullable<Unsigned<Integer>>,
text -> Text,
completed -> Bool,
#[sql_name = "type"]
#[max_length = 255]
type_ -> Varchar,
smallint -> Int2,
bigint -> Int8,
created_at -> Timestamptz,
updated_at -> Timestamptz,
updated_at -> Timestamp,
}
}

0 comments on commit 82ddae5

Please sign in to comment.