Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Allow using any type in #[filter]
Browse files Browse the repository at this point in the history
  • Loading branch information
popen2 committed Oct 30, 2023
1 parent 8f2be07 commit 6ae4317
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 51 deletions.
182 changes: 182 additions & 0 deletions examples/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 examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.0"

[dependencies]
diesel = { version = "2", features = ["postgres", "uuid"] }
diesel-derive-newtype = "2.1.0"
diesel_filter = { path = "../../core", features = ["pagination"] }
serde = { version = "1.0" }
uuid = "1.2.2"
30 changes: 26 additions & 4 deletions examples/simple/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,39 @@ extern crate diesel;

use crate::schema::thingies;
use diesel::prelude::*;
use diesel_derive_newtype::DieselNewType;
use diesel_filter::Paginate;
use std::env;
use uuid::Uuid;

mod schema;

#[derive(Debug, DieselNewType)]
pub struct CustomType(String);

#[derive(DieselFilter, Queryable, Debug)]
#[diesel(table_name = thingies)]
#[pagination]
pub struct Thingy {
pub id: Uuid,
#[filter(insensitive)]
pub name: String,
#[filter]
pub num32: i32,
#[filter]
pub option_num32: Option<i32>,
#[filter]
pub num64: i64,
#[filter]
pub option_num64: Option<i64>,
#[filter(multiple)]
pub category: String,
pub text: String,
#[filter]
pub option_text: Option<String>,
#[filter]
pub custom: CustomType,
#[filter]
pub other: Option<String>,
pub option_custom: Option<CustomType>,
}

fn main() {
Expand All @@ -31,8 +47,14 @@ fn main() {

let filters = ThingyFilters {
name: Some("coucou".to_owned()),
category: None,
other: None,
num32: Some(1),
option_num32: Some(1),
num64: Some(1),
option_num64: Some(1),
text: None,
option_text: None,
custom: Some(CustomType("".into())),
option_custom: Some(CustomType("".into())),
page: None,
per_page: None,
};
Expand Down
10 changes: 8 additions & 2 deletions examples/simple/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ table! {
thingies (id) {
id -> Uuid,
name -> Varchar,
category -> Varchar,
other -> Nullable<Varchar>,
num32 -> Int4,
option_num32 -> Nullable<Int4>,
num64 -> Int8,
option_num64 -> Nullable<Int8>,
text -> Varchar,
option_text -> Nullable<Varchar>,
custom -> Varchar,
option_custom -> Nullable<Varchar>,
}
}
Loading

0 comments on commit 6ae4317

Please sign in to comment.