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

How to chain/assign conditions? #1287

Closed
figaro-smartotum opened this issue May 10, 2024 · 4 comments
Closed

How to chain/assign conditions? #1287

figaro-smartotum opened this issue May 10, 2024 · 4 comments

Comments

@figaro-smartotum
Copy link

figaro-smartotum commented May 10, 2024

Hi,
in order to prevent the duplications of long code fragments, I am looking for a way to chain where conditions in switch/if clauses.

Please look at the following code snippet:

    using namespace sqlite_orm;

    auto condition = c(&HaccpDetail::event) == HACCP_EVENT_START or  c(&HaccpDetail::event) == HACCP_EVENT_STOP;

    switch (typeFilter) {
        case HACCP_TYPE_EVERYTHING:
            break;

        case HACCP_TYPE_COOKINGS:
           // Missing operator= error
            condition = condition and c(&Haccp::type) == HaccpType::HACCP_TYPE_COOKING; 
            break;

        case HACCP_TYPE_ALARMS:
            // Missing operator= error
            condition = condition and c(&Haccp::type) == HaccpType::HACCP_TYPE_ALARM;
            break;
    }

auto result = this->storage->iterate<HaccpSamples>(where(condition));

// Iterate results

Is there a way to achieve this coding style?

@fnc12
Copy link
Owner

fnc12 commented May 10, 2024

Hi. No there is no way to make AST dynamic in sqlite_orm cause AST is based on templates. But you can achieve your idea differently. Please read #459 and #671

@figaro-smartotum
Copy link
Author

Many thanks,
alternatively, is there a way to perform raw-queries instead?

@fnc12
Copy link
Owner

fnc12 commented May 10, 2024

is there a way to perform raw-queries instead?

no. To use raw query you can always use any other regular ORM or libsqlite

@fnc12
Copy link
Owner

fnc12 commented May 16, 2024

@figaro-smartotum I am closing this issue cause it doesn't look like something that requires commits to be made. If you have something else please feel free to reopen it

@fnc12 fnc12 closed this as completed May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants