seaqs
A mini tool to convert a querystring into seaquery's condition.
Description
Let's say we have a user table and we want to provide a rest endpoint for some admin panel. With this crate we can define a filter struct and use it with sea_query(or sea_orm, sqlx should work too).
use Deserialize;
use ;
use ;
use ;
// It's part of the sea_query definition of a table.
// And we define a filter struct like below
// Then we should impl the 'ToCond' trait, which should be done using a macro but there isn't one yet.
// I'm using serde_querystring here, but serde_json works too(whatever works with serde_with, works here)
let filters =
.unwrap;
// And create your query normally
let q = select
.column
.from
// Just use ApplyConds trait from seaqs
.apply_conds
// You shouldn't use to_string, it's just here for the test
.to_string;
assert_eq!;
// You can also use the provided QueryFilter to add sort/order/page/limit to your query. It's designed to work well with react-admin or similar admin panels.
use ;
// You need to impl Filter for it to work
// Notice that we need to use the `filter` key now.
let filters =
.unwrap;
// And create your query normally
let q = select
.column
.from
// Just use ApplyFilters trait from seaqs
.apply_filters
// You shouldn't use to_string, it's just here for the test
.to_string;
assert_eq!