@@ -3,12 +3,28 @@ import { TSparkParameter, TSparkParameterValue } from '../thrift/TCLIService_typ
33
44export type DBSQLParameterValue = boolean | number | bigint | Int64 | Date | string ;
55
6+ export enum DBSQLParameterType {
7+ STRING = 'STRING' ,
8+ DATE = 'DATE' ,
9+ TIMESTAMP = 'TIMESTAMP' ,
10+ FLOAT = 'FLOAT' ,
11+ DECIMAL = 'DECIMAL' ,
12+ DOUBLE = 'DOUBLE' ,
13+ INTEGER = 'INTEGER' ,
14+ BIGINT = 'BIGINT' ,
15+ SMALLINT = 'SMALLINT' ,
16+ TINYINT = 'TINYINT' ,
17+ BOOLEAN = 'BOOLEAN' ,
18+ INTERVALMONTH = 'INTERVAL MONTH' ,
19+ INTERVALDAY = 'INTERVAL DAY' ,
20+ }
21+
622interface DBSQLParameterOptions {
7- type ?: string ;
23+ type ?: DBSQLParameterType ;
824 value : DBSQLParameterValue ;
925}
1026
11- export default class DBSQLParameter {
27+ export class DBSQLParameter {
1228 public readonly type ?: string ;
1329
1430 public readonly value : DBSQLParameterValue ;
@@ -21,7 +37,7 @@ export default class DBSQLParameter {
2137 public toSparkParameter ( ) : TSparkParameter {
2238 if ( typeof this . value === 'boolean' ) {
2339 return new TSparkParameter ( {
24- type : this . type ?? ' BOOLEAN' ,
40+ type : this . type ?? DBSQLParameterType . BOOLEAN ,
2541 value : new TSparkParameterValue ( {
2642 stringValue : this . value ? 'TRUE' : 'FALSE' ,
2743 } ) ,
@@ -30,7 +46,7 @@ export default class DBSQLParameter {
3046
3147 if ( typeof this . value === 'number' ) {
3248 return new TSparkParameter ( {
33- type : this . type ?? ( Number . isInteger ( this . value ) ? ' INTEGER' : ' DOUBLE' ) ,
49+ type : this . type ?? ( Number . isInteger ( this . value ) ? DBSQLParameterType . INTEGER : DBSQLParameterType . DOUBLE ) ,
3450 value : new TSparkParameterValue ( {
3551 stringValue : Number ( this . value ) . toString ( ) ,
3652 } ) ,
@@ -39,7 +55,7 @@ export default class DBSQLParameter {
3955
4056 if ( this . value instanceof Int64 || typeof this . value === 'bigint' ) {
4157 return new TSparkParameter ( {
42- type : this . type ?? ' BIGINT' ,
58+ type : this . type ?? DBSQLParameterType . BIGINT ,
4359 value : new TSparkParameterValue ( {
4460 stringValue : this . value . toString ( ) ,
4561 } ) ,
@@ -48,15 +64,15 @@ export default class DBSQLParameter {
4864
4965 if ( this . value instanceof Date ) {
5066 return new TSparkParameter ( {
51- type : this . type ?? ' TIMESTAMP' ,
67+ type : this . type ?? DBSQLParameterType . TIMESTAMP ,
5268 value : new TSparkParameterValue ( {
5369 stringValue : this . value . toISOString ( ) ,
5470 } ) ,
5571 } ) ;
5672 }
5773
5874 return new TSparkParameter ( {
59- type : this . type ?? ' STRING' ,
75+ type : this . type ?? DBSQLParameterType . STRING ,
6076 value : new TSparkParameterValue ( {
6177 stringValue : this . value ,
6278 } ) ,
0 commit comments