fnc12/sqlite_orm

How to chain/assign conditions?

Closed this issue · 4 comments

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?

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

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

is there a way to perform raw-queries instead?

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

@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