1- import { ValueTypeToParse } from './utils' ;
2- import { LambdaMetadata } from './lambda-metadata' ;
1+ import * as moment from "moment" ;
2+ import { ValueTypeToParse } from "./utils" ;
33import { WhereBuilder } from "./../crud/where-builder" ;
44import { DatabaseHelper } from "./../database-helper" ;
55import { ProjectionBuilder } from "./../crud/projection-builder" ;
6- import { Expression , ExpressionUtils , LambdaExpression , LambdaColumnMetadata } from "lambda-expression" ;
7- import * as moment from "moment " ;
6+ import { Expression , ExpressionUtils , LambdaColumnMetadata , LambdaExpression } from "lambda-expression" ;
7+ import { LambdaMetadata } from "./lambda-metadata " ;
88import { ExpressionOrColumnEnum } from "./enums/expression-or-column-enum" ;
99import { FieldType } from "./enums/field-type" ;
1010import { ColumnType } from "./enums/column-type" ;
@@ -46,11 +46,11 @@ export class Utils {
4646 }
4747
4848 public static isOnlyNumber ( value : any ) : boolean {
49- return / ^ [ 0 - 9 ] * $ / . test ( value )
49+ return / ^ [ 0 - 9 ] * $ / . test ( value ) ;
5050 }
5151
5252 public static isStartWithNumber ( value : any ) : boolean {
53- return / ^ [ 0 - 9 ] / . test ( value )
53+ return / ^ [ 0 - 9 ] / . test ( value ) ;
5454 }
5555
5656 public static isValueNumber ( value : any ) : boolean {
@@ -134,10 +134,6 @@ export class Utils {
134134 return this . getDatabaseHelper ( ) . parseToColumnType ( type ) ;
135135 }
136136
137- private static isColumnReservedNameOrNotAllowed ( columnName : string ) : boolean {
138- return this . isStartWithNumber ( columnName ) || this . isReservedBoolean ( columnName )
139- }
140-
141137 public static isNameColumn ( column : string ) : boolean {
142138 const isNameColumn = / ^ [ a - z A - Z 0 - 9 _ \* ] * $ / ;
143139 return isNameColumn . test ( column ) && ! this . isColumnReservedNameOrNotAllowed ( column ) ;
@@ -155,80 +151,84 @@ export class Utils {
155151 }
156152
157153 public static normalizeSqlString ( inputSql : string ) : string {
158- return inputSql . replace ( / \s + / g, ' ' ) . trim ( ) ;
154+ return inputSql . replace ( / \s + / g, " " ) . trim ( ) ;
159155 }
160156
161157 public static getLambdaMetadata < T > ( expression : LambdaExpression < T > ) : LambdaMetadata {
162- let columnMetadata = this . getLambdaColumnMetadata ( expression ) ;
163- return < LambdaMetadata > {
158+ const columnMetadata = this . getLambdaColumnMetadata ( expression ) ;
159+ return {
164160 left : columnMetadata . columnLeft ,
165161 condition : this . conditionSql ( columnMetadata ) ,
166162 right : columnMetadata . columnRight ,
167- }
163+ } as LambdaMetadata ;
168164 }
169165
170166 public static clearParam ( param : ValueTypeToParse ) : ValueTypeToParse {
171167 if ( Utils . isString ( param ) ) {
172- if ( Utils . isOnlyNumber ( param ) ) {
168+ if ( Utils . isOnlyNumber ( param ) ) {
173169 return + param ;
174170 }
175- if ( Utils . isReservedBoolean ( param ) ) {
176- return param === ' true' ;
171+ if ( Utils . isReservedBoolean ( param ) ) {
172+ return param === " true" ;
177173 }
178174 // remove possiveis " ou ' (aspas duplas ou simples) no inicio ou fim de uma string de valor de parametro
179- return ( < string > param ) . replace ( / ( ^ [ " ' ] | [ " ' ] $ ) / mg, "" ) ;
175+ return ( param as string ) . replace ( / ( ^ [ " ' ] | [ " ' ] $ ) / mg, "" ) ;
180176 }
181177 return param ;
182178 }
183179
180+ private static isColumnReservedNameOrNotAllowed ( columnName : string ) : boolean {
181+ return this . isStartWithNumber ( columnName ) || this . isReservedBoolean ( columnName ) ;
182+ }
183+
184184 private static getLambdaColumnMetadata < T > ( expression : LambdaExpression < T > ) : LambdaColumnMetadata {
185185 return this . getExpressionUtils ( ) . getColumnByLambdaExpression ( expression ) ;
186186 }
187187
188188 private static conditionSql ( metadata : LambdaColumnMetadata ) : Condition [ ] {
189189 switch ( metadata . operator ) {
190- case '==' :
191- case ' ===' :
190+ case "==" :
191+ case " ===" :
192192 if ( this . isEquivalentNullExpression ( metadata . columnRight ) ) {
193- return [ Condition . IsNull ]
193+ return [ Condition . IsNull ] ;
194194 }
195195 return [ Condition . Equal ] ;
196- case '>' :
196+ case ">" :
197197 return [ Condition . Great ] ;
198- case '>=' :
198+ case ">=" :
199199 return [ Condition . GreatAndEqual ] ;
200- case '<' :
200+ case "<" :
201201 return [ Condition . Less ] ;
202- case '<=' :
202+ case "<=" :
203203 return [ Condition . LessAndEqual ] ;
204- case '!' :
204+ case "!" :
205205 return [ Condition . Not ] ;
206- case '!=' :
207- case ' !==' :
206+ case "!=" :
207+ case " !==" :
208208 if ( this . isEquivalentNullExpression ( metadata . columnRight ) ) {
209- return [ Condition . Not , Condition . IsNull ]
209+ return [ Condition . Not , Condition . IsNull ] ;
210210 }
211211 return [ Condition . Not , Condition . Equal ] ;
212- case 'XX' :
212+ case "XX" :
213213 // TODO: not implemented
214214 return [ Condition . Between ] ;
215- case ' XXX' :
215+ case " XXX" :
216216 // TODO: not implemented
217217 return [ Condition . In ] ;
218218 // case '':
219219 // return Condition.
220220 default :
221- throw `Not found condition (${ metadata . operator } )`
221+ throw new Error ( `Not found condition (${ metadata . operator } )` ) ;
222222 }
223223 }
224224
225225 private static isEquivalentNullExpression ( value : string ) : boolean {
226226 switch ( value ) {
227- case ' null' :
228- case ' void 0' :
229- case ' void' :
230- case ' undefined' :
231- case ' nil' :
227+ case " null" :
228+ case " void 0" :
229+ case " void" :
230+ case " undefined" :
231+ case " nil" :
232232 return true ;
233233 default :
234234 return false ;
0 commit comments