Skip to content

Commit 82ddae5

Browse files
committed
test: change "advanced_queries" to be compile-able
1 parent 19eb3f8 commit 82ddae5

File tree

6 files changed

+60
-30
lines changed

6 files changed

+60
-30
lines changed

test/Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"simple_table_sqlite",
77
"custom_model_and_schema_path",
88
"single_model_file",
9+
"advanced_queries",
910
]
1011
resolver = "2"
1112

test/advanced_queries/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[lib]
2+
path = "lib.rs"
3+
4+
[package]
5+
name = "advanced_queries"
6+
version = "0.1.0"
7+
edition = "2021"
8+
9+
[dependencies]
10+
diesel = { version = "*", default-features = false, features = [
11+
"postgres",
12+
"r2d2",
13+
"chrono",
14+
] }
15+
r2d2.workspace = true
16+
chrono.workspace = true
17+
serde.workspace = true

test/advanced_queries/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub mod models;
2+
pub mod schema;
3+
4+
pub mod diesel {
5+
pub use diesel::*;
6+
}

test/advanced_queries/models/todos/generated.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,56 @@ pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::Connectio
1111
pub struct Todos {
1212
/// Field representing column `id`
1313
pub id: i32,
14-
/// Field representing column `unsigned`
15-
pub unsigned: u32,
16-
/// Field representing column `unsigned_nullable`
17-
pub unsigned_nullable: Option<u32>,
1814
/// Field representing column `text`
1915
pub text: String,
2016
/// Field representing column `completed`
2117
pub completed: bool,
2218
/// Field representing column `type`
2319
pub type_: String,
20+
/// Field representing column `smallint`
21+
pub smallint: i16,
22+
/// Field representing column `bigint`
23+
pub bigint: i64,
2424
/// Field representing column `created_at`
2525
pub created_at: chrono::DateTime<chrono::Utc>,
2626
/// Field representing column `updated_at`
27-
pub updated_at: chrono::DateTime<chrono::Utc>,
27+
pub updated_at: chrono::NaiveDateTime,
2828
}
2929

3030
/// Create Struct for a row in table `todos` for [`Todos`]
3131
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::Insertable)]
3232
#[diesel(table_name=todos)]
3333
pub struct CreateTodos {
34-
/// Field representing column `unsigned`
35-
pub unsigned: u32,
36-
/// Field representing column `unsigned_nullable`
37-
pub unsigned_nullable: Option<u32>,
3834
/// Field representing column `text`
3935
pub text: String,
4036
/// Field representing column `completed`
4137
pub completed: bool,
4238
/// Field representing column `type`
4339
pub type_: String,
40+
/// Field representing column `smallint`
41+
pub smallint: i16,
42+
/// Field representing column `bigint`
43+
pub bigint: i64,
4444
}
4545

4646
/// Update Struct for a row in table `todos` for [`Todos`]
4747
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, diesel::AsChangeset, PartialEq, Default)]
4848
#[diesel(table_name=todos)]
4949
pub struct UpdateTodos {
50-
/// Field representing column `unsigned`
51-
pub unsigned: Option<u32>,
52-
/// Field representing column `unsigned_nullable`
53-
pub unsigned_nullable: Option<Option<u32>>,
5450
/// Field representing column `text`
5551
pub text: Option<String>,
5652
/// Field representing column `completed`
5753
pub completed: Option<bool>,
5854
/// Field representing column `type`
5955
pub type_: Option<String>,
56+
/// Field representing column `smallint`
57+
pub smallint: Option<i16>,
58+
/// Field representing column `bigint`
59+
pub bigint: Option<i64>,
6060
/// Field representing column `created_at`
6161
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
6262
/// Field representing column `updated_at`
63-
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
63+
pub updated_at: Option<chrono::NaiveDateTime>,
6464
}
6565

6666
/// Result of a `.paginate` function
@@ -134,16 +134,6 @@ impl Todos {
134134
if let Some(filter_id) = filter.id.clone() {
135135
query = query.filter(crate::schema::todos::id.eq(filter_id));
136136
}
137-
if let Some(filter_unsigned) = filter.unsigned.clone() {
138-
query = query.filter(crate::schema::todos::unsigned.eq(filter_unsigned));
139-
}
140-
if let Some(filter_unsigned_nullable) = filter.unsigned_nullable.clone() {
141-
query = if filter_unsigned_nullable.is_some() {
142-
query.filter(crate::schema::todos::unsigned_nullable.eq(filter_unsigned_nullable))
143-
} else {
144-
query.filter(crate::schema::todos::unsigned_nullable.is_null())
145-
};
146-
}
147137
if let Some(filter_text) = filter.text.clone() {
148138
query = query.filter(crate::schema::todos::text.eq(filter_text));
149139
}
@@ -153,6 +143,12 @@ impl Todos {
153143
if let Some(filter_type_) = filter.type_.clone() {
154144
query = query.filter(crate::schema::todos::type_.eq(filter_type_));
155145
}
146+
if let Some(filter_smallint) = filter.smallint.clone() {
147+
query = query.filter(crate::schema::todos::smallint.eq(filter_smallint));
148+
}
149+
if let Some(filter_bigint) = filter.bigint.clone() {
150+
query = query.filter(crate::schema::todos::bigint.eq(filter_bigint));
151+
}
156152
if let Some(filter_created_at) = filter.created_at.clone() {
157153
query = query.filter(crate::schema::todos::created_at.eq(filter_created_at));
158154
}
@@ -180,11 +176,11 @@ impl Todos {
180176
#[derive(Debug, Default, Clone)]
181177
pub struct TodosFilter {
182178
pub id: Option<i32>,
183-
pub unsigned: Option<u32>,
184-
pub unsigned_nullable: Option<Option<u32>>,
185179
pub text: Option<String>,
186180
pub completed: Option<bool>,
187181
pub type_: Option<String>,
182+
pub smallint: Option<i16>,
183+
pub bigint: Option<i64>,
188184
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
189-
pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
185+
pub updated_at: Option<chrono::NaiveDateTime>,
190186
}

test/advanced_queries/schema.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
diesel::table! {
22
todos (id) {
33
id -> Int4,
4-
unsigned -> Unsigned<Integer>,
5-
unsigned_nullable -> Nullable<Unsigned<Integer>>,
64
text -> Text,
75
completed -> Bool,
86
#[sql_name = "type"]
97
#[max_length = 255]
108
type_ -> Varchar,
9+
smallint -> Int2,
10+
bigint -> Int8,
1111
created_at -> Timestamptz,
12-
updated_at -> Timestamptz,
12+
updated_at -> Timestamp,
1313
}
1414
}

0 commit comments

Comments
 (0)