mythix-orm
Advanced tools
Comparing version 1.11.0 to 1.11.1
@@ -53,10 +53,74 @@ 'use strict'; | ||
function wrapOrderClause(func) { | ||
func.DESC = (...args) => { | ||
const applyQueryOrder = (_order, replace) => { | ||
let query = this; | ||
let order = Nife.toArray(_order).filter(Boolean); | ||
let asc = order.filter((thisOrder) => { | ||
if (!Nife.instanceOf(thisOrder, 'string')) | ||
return true; | ||
if (thisOrder.charAt(0) === '-') | ||
return false; | ||
return true; | ||
}); | ||
let desc = order.filter((thisOrder) => { | ||
if (!Nife.instanceOf(thisOrder, 'string')) | ||
return false; | ||
if (thisOrder.charAt(0) !== '-') | ||
return false; | ||
return true; | ||
}); | ||
if (Nife.isNotEmpty(asc)) { | ||
asc = asc.map((thisOrder) => { | ||
if (!Nife.instanceOf(thisOrder, 'string')) | ||
return thisOrder; | ||
return thisOrder.replace(/^\+/, ''); | ||
}); | ||
// eslint-disable-next-line new-cap | ||
query = (replace) ? ASC(asc) : ASC('+', asc); | ||
} | ||
if (Nife.isNotEmpty(desc)) { | ||
desc = desc.map((thisOrder) => { | ||
if (!Nife.instanceOf(thisOrder, 'string')) | ||
return thisOrder; | ||
return thisOrder.replace(/^-/, ''); | ||
}); | ||
// eslint-disable-next-line new-cap | ||
query = (replace) ? DESC(desc) : DESC('+', desc); | ||
} | ||
return query; | ||
}; | ||
const DESC = (...args) => { | ||
return applyOrderClause.call(this, { direction: '-' }, ...args); | ||
}; | ||
func.ASC = (...args) => { | ||
const ASC = (...args) => { | ||
return applyOrderClause.call(this, { direction: '+' }, ...args); | ||
}; | ||
const ADD = (...args) => { | ||
return applyQueryOrder(args, false); | ||
}; | ||
const REPLACE = (...args) => { | ||
return applyQueryOrder(args, true); | ||
}; | ||
func.DESC = DESC; | ||
func.ASC = ASC; | ||
func.ADD = ADD; | ||
func.REPLACE = REPLACE; | ||
return func; | ||
@@ -63,0 +127,0 @@ } |
@@ -82,3 +82,2 @@ import ConnectionBase from '../connection/connection-base'; | ||
public OFFSET(value: number): QueryEngine; | ||
public ORDER(...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>): QueryEngine; | ||
public GROUP_BY(...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>): QueryEngine; | ||
@@ -89,2 +88,13 @@ public HAVING(query: QueryEngine): QueryEngine; | ||
declare public ORDER: { | ||
(...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>): QueryEngine; | ||
ASC: (...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>) => QueryEngine; | ||
DESC: (...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>) => QueryEngine; | ||
ADD: (...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>) => QueryEngine; | ||
REPLACE: (...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>) => QueryEngine; | ||
name: QueryEngine; | ||
}; | ||
declare public NOT: { | ||
@@ -91,0 +101,0 @@ (): QueryEngine; |
{ | ||
"name": "mythix-orm", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"description": "ORM for Mythix framework", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
652751
15791