Skip to content

Commit 3633200

Browse files
committed
Added limit and offset by default as usize fields
1 parent 0010713 commit 3633200

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
22
**/.idea
33
**/Cargo.lock
4-
**/target
4+
**/target
5+
.vscode

my-postgres-macros/src/where_fields.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ impl<'s> WhereFields<'s> {
1616
let mut offset = None;
1717
let mut other_fields = Vec::new();
1818
for struct_prop in src_fields.get_fields() {
19-
if struct_prop.attrs.has_attr("limit") {
19+
if struct_prop.attrs.has_attr("limit") || (struct_prop.name == "limit" && struct_prop.ty.is_usize()) {
2020
limit = Some(struct_prop);
21-
} else if struct_prop.attrs.has_attr("offset") {
21+
} else if struct_prop.attrs.has_attr("offset")|| (struct_prop.name == "offset" && struct_prop.ty.is_usize()) {
2222
offset = Some(struct_prop);
2323
} else {
2424
other_fields.push(struct_prop);

my-postgres-tests/src/dto/test_where_raw_model.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ pub struct WhereRawModel {
55
pub field_1: String,
66
pub field_2: bool,
77
pub field_3: Vec<i32>,
8+
9+
pub limit: usize,
10+
pub offset: usize,
811
}
912

1013
#[cfg(test)]
@@ -19,6 +22,8 @@ mod tests {
1922
field_1: "test".to_string(),
2023
field_2: true,
2124
field_3: vec![1, 2, 3],
25+
limit: 10,
26+
offset: 5,
2227
};
2328

2429
let mut params = my_postgres::sql::SqlValues::new();
@@ -38,6 +43,8 @@ mod tests {
3843
field_1: "test".to_string(),
3944
field_2: true,
4045
field_3: vec![],
46+
limit: 10,
47+
offset: 5,
4148
};
4249

4350
let mut params = my_postgres::sql::SqlValues::new();
@@ -54,6 +61,8 @@ mod tests {
5461
field_1: "test".to_string(),
5562
field_2: true,
5663
field_3: vec![1],
64+
limit: 10,
65+
offset: 5,
5766
};
5867

5968
let mut params = my_postgres::sql::SqlValues::new();

0 commit comments

Comments
 (0)