Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

look into sqlx #26

Open
jrheard opened this issue Aug 15, 2021 · 1 comment
Open

look into sqlx #26

jrheard opened this issue Aug 15, 2021 · 1 comment

Comments

@jrheard
Copy link
Owner

jrheard commented Aug 15, 2021

figuring out how to do simple stuff in diesel is giving me a lot of trouble. here's my first attempt at splitting out a portion of a WHERE clause so that it can be reused:

pub fn alive_tasks<'a>() -> Box<dyn BoxableExpression<task::table, Pg, SqlType = Bool> + 'a> {
    Box::new(task::mode.eq(any(vec![MODE_PENDING.0, MODE_ACTIVE.0])))
}

absolutely hideous.

also, afaict i can't do this:

    let query = task::table.find(task_id);
    if !include_deleted {
        query = query.filter(task::mode.ne(MODE_DELETED.0));
    }

because the second query value has a different type from the first.

hopefully i'm just doing stuff wrong and diesel is actually great! but comradeblue in irc uses https://github.com/launchbadge/sqlx , so i should do some research on that someday. low-priority.

@jrheard
Copy link
Owner Author

jrheard commented Aug 15, 2021

got help from the diesel maintainer via gitter, he suggested using a typedef for the first one and .into_boxed() for the second. ended up with this:

pub fn alive_tasks<'a>() -> SqlExpr<'a, task::table, Bool> {
    Box::new(task::mode.eq(any(vec![MODE_PENDING.0, MODE_ACTIVE.0])))
}

and

let mut query = task::table.find(task_id).into_boxed();
if !include_deleted {
    query = query.filter(task::mode.ne(MODE_DELETED.0));
}

which seems p reasonable! so this sqlx investigation ticket is super non-urgent / low-priority

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant