import Entity from "../entity/entity" ; import Search from "./search" ; import WhereField from "./where-field" ; export default class WhereNumber < TEntity extends Entity > extends WhereField < TEntity > { private lower : number = Number . NEGATIVE_INFINITY ; private upper : number = Number . POSITIVE_INFINITY ; private lowerExclusive : boolean = false ; private upperExclusive : boolean = false ; eq ( value ) { this . lower = value ; this . upper = value ; return this . search ; } gt ( value ) { this . lower = value ; this . lowerExclusive = true ; return this . search ; } gte ( value ) { this . lower = value ; return this . search ; } lt ( value ) { this . upper = value ; this . upperExclusive = true ; return this . search ; } lte ( value ) { this . upper = value ; return this . search ; } between ( lower , upper ) { this . lower = lower ; this . upper = upper ; return this . search ; } equal ( value ) { return this . eq ( value ) ; } equals ( value ) { return this . eq ( value ) ; } equalTo ( value ) { return this . eq ( value ) ; } greaterThan ( value ) { return this . gt ( value ) ; } greaterThanOrEqualTo ( value ) { return this . gte ( value ) ; } lessThan ( value ) { return this . lt ( value ) ; } lessThanOrEqualTo ( value ) { return this . lte ( value ) ; } toString ( ) { let lower = this . makeLowerString ( ) ; let upper = this . makeUpperString ( ) ; return this . buildQuery ( `[${ lower } ${ upper }]` ) ; } private makeLowerString ( ) { if ( this . lower === Number . NEGATIVE_INFINITY ) return '-inf' ; if ( this . lowerExclusive ) return `(${ this . lower }` ; return this . lower . toString ( ) ; } private makeUpperString ( ) { if ( this . upper === Number . POSITIVE_INFINITY ) return '+inf' ; if ( this . upperExclusive ) return `(${ this . upper }` ; return this . upper . toString ( ) ; } }