Skip to content

Support for Composable Queries #55

Description

@jadamwilson2

I would like to conditionally compose queries based on optional parameters passed to a function. A simple example would be:

auto do_query(const std::optional<Date>& date, const std::optional<User>& user, const std::optional<size_t> hash) {
auto query = EmptyCondition{};
if (date) {
    query &= "date"_c == *date;
}
if (user) {
    query &= "user"_c == *user;
}
if (hash) {
    query &= "hash"_c == hash;
}

return session().and_then(
          sqlgen::read<std::vector<DataType>> |
          sqlgen::where(query).value();
}

Is something like this possible now? If not, is it possible to add?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions