import { Expression , Operator } from './criteria' ; import { QueryBuilder } from './query/query.builder' ; export const NOT_EQUAL = ( expression , property , value ) : void => { expression ( `${ property } <> ?` , value ) ; } ; export const EQUAL = ( expression , property , value ) : void => { expression ( `${ property } = ?` , value ) ; } ; export const LESS_EQUAL = ( expression , property , value ) : void => { expression ( `${ property } <= ?` , value ) ; } ; export const GREATER_EQUAL = ( expression , property , value ) : void => { expression ( `${ property } >= ?` , value ) ; } ; export const LESS_THAN = ( expression , property , value ) : void => { expression ( `${ property } < ?` , value ) ; } ; export const GREATER_THAN = ( expression , property , value ) : void => { expression ( `${ property } > ?` , value ) ; } ; export const LIKE = ( expression , property , value ) : void => { value = '%' + value . replace ( /(%)|(_)|(\*)/g , '*$1$2$3' ) . replace ( /\*{2}/g , '%' ) + '%' ; expression ( property + ' LIKE ? ESCAPE \'*\'' , value ) ; } ; export const ILIKE = ( expression , property , value ) : void => { value = '%' + value . toUpperCase ( ) . replace ( /(%)|(_)|(\*)/g , '*$1$2$3' ) . replace ( /\*{2}/g , '%' ) + '%' ; expression ( 'UPPER(' + property + ') LIKE ? ESCAPE \'*\'' , value ) ; } ; export const ILIKE_START = ( expression , property , value ) : void => { value = value . toUpperCase ( ) . replace ( /(%)|(_)|(\*)/g , '*$1$2$3' ) . replace ( /\*{2}/g , '%' ) + '%' ; expression ( 'UPPER(' + property + ') LIKE ? ESCAPE \'*\'' , value ) ; } ; export const BETWEEN = ( expression , property , values , queryBuilder ) : void => { queryBuilder . query . where ( property + ' BETWEEN ? AND ?' , values [ 0 ] , values [ 1 ] ) ; } ; export const IN = ( expression , property , values ) : void => { if ( values && values . length ) { expression ( property + ' IN ?' , values ) ; } else { expression ( '0 = 1' ) ; } } ; export const NOT_IN = ( expression , property , values ) : void => { if ( values && values . length > 0 ) { expression ( property + ' NOT IN ?' , values ) ; } else { expression ( '1 = 1' ) ; } } ; export const IS_NULL = ( expression , property ) : void => { expression ( `${ property } IS NULL` ) ; } ; export const IS_NOT_NULL = ( expression , property ) : void => { expression ( `${ property } IS NOT NULL` ) ; } ;