import { BooleanQuery , Query } from './query' ; import { Expression , InternalExpression } from './expression' ; import { ParameterToken , StringToken , Token } from './tokens' ; import { DbConfig } from './config' ; export class CaseStatement < Config extends DbConfig , DataType , IsNotNull extends boolean = false > { constructor ( private readonly tokens ) { } when < Q extends Query < any > > ( expression ) { const self = this ; return { then < T > ( result ) { return new CaseStatement < Config , DataType | T > ( [ ... self . tokens , new StringToken ( `WHEN` ) , ... expression . toTokens ( ) , new StringToken ( `THEN` ) , new ParameterToken ( result ) , ] ) ; } , } ; } else < T > ( result ) { return new CaseStatement < Config , DataType | T , true > ( [ ... this . tokens , new StringToken ( `ELSE` ) , new ParameterToken ( result ) , ] ) ; } end ( ) { return new InternalExpression ( this . tokens , `case` ) as any ; } }