Query statements - JGdijk/ords GitHub Wiki

The following functions are added to select your models (more comming):

  • where(key, action, value)

    action: '=', '!=', '<', '>'

  • orWhere(key, action, value)

  • whereIn(key, values) / whereNotIn(key, values)

    values: [1, 2, ...]

  • whereBetween(key, min, max) / whereNotBetween(key, min, max)

  • whereEmpty(key) / whereNotEmpty(key)

  • whereHas(relation) / whereDoesntHave(relation)

  • orderBy(key, order)

    order 'asc' / 'desc'

*They are placed before one of the retrieving functions:

ords.use('task')
    .where('id', '<', 3)
    .orderBy('id', 'desc')
    .get(); 

The where() and orWhere() function also except a callback function on which all the where functions can be applied:

ords.use('task')
    .where((callback: WhereCallback) => { callback
        .where('id', '<', 3).whereNotEmpty('name')... 
    })
    .get(); 

The whereHas() function also accepts a callback function as second argument:

ords.use('task')
    .whereHas('RelationName', (callback: WhereHasCallback) => { callback
        .where('id', '<', 3).whereNotEmpty('name')... 
    })
    .get(); 

All the where functions can be used in combination with the update() or remove() functions:

ords.use('task').where('id', '=', 1).remove(); // will only remove the task with id 1
⚠️ **GitHub.com Fallback** ⚠️