sqlite_orm icon indicating copy to clipboard operation
sqlite_orm copied to clipboard

How to chain/assign conditions?

Open figaro-smartotum opened this issue 1 year ago • 3 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?

figaro-smartotum avatar May 10 '24 08:05 figaro-smartotum

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 https://github.com/fnc12/sqlite_orm/issues/459 and https://github.com/fnc12/sqlite_orm/issues/671

fnc12 avatar May 10 '24 08:05 fnc12

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

figaro-smartotum avatar May 10 '24 09:05 figaro-smartotum

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 avatar May 10 '24 09:05 fnc12

@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 avatar May 16 '24 06:05 fnc12