|
1 | 1 | import { TokenType } from "../lexer/Token.js"; |
2 | 2 |
|
3 | | -type CheckFunction = (columnIdentifier: string, parameterValues: number[]) => string; |
4 | | -type OutputFunction = (value: any, parameterValues: number[]) => string; |
| 3 | +type CheckFunction = (columnIdentifier: string, parameterValues: any[]) => string; |
| 4 | +type OutputFunction = (value: any, parameterValues: any[]) => string; |
5 | 5 |
|
6 | 6 | export abstract class SQLType { |
7 | 7 |
|
@@ -173,6 +173,71 @@ export class SQLBaseType extends SQLType { |
173 | 173 |
|
174 | 174 | } |
175 | 175 |
|
| 176 | +class SQLNumberEnumType extends SQLBaseType { |
| 177 | + |
| 178 | + constructor(public values: string[]){ |
| 179 | + super("enum", [], |
| 180 | + (ci, pv) => `check(${ci} in (${(<string[]>pv).join(', ')}))`, |
| 181 | + (v: string, pv) => v, |
| 182 | + ["decimal", "integer", "double", "float"] |
| 183 | + ) |
| 184 | + } |
| 185 | + |
| 186 | + getBinaryResultType(operator: TokenType, secondType: SQLType): SQLType { |
| 187 | + return operator == TokenType.concatenation ? SQLBaseType.getBaseType('double') : null; |
| 188 | + } |
| 189 | + |
| 190 | + getUnaryResultType(operator: TokenType): SQLType { |
| 191 | + return null; |
| 192 | + } |
| 193 | + |
| 194 | + getBinaryResult(operator: TokenType, value1: any, value2: any) { |
| 195 | + return value1 + value2; |
| 196 | + } |
| 197 | + |
| 198 | + toString(): string { |
| 199 | + return "double"; |
| 200 | + } |
| 201 | + |
| 202 | + getBaseTypeName(): string { |
| 203 | + return "enum"; |
| 204 | + } |
| 205 | + |
| 206 | +} |
| 207 | + |
| 208 | + |
| 209 | +class SQLTextEnumType extends SQLBaseType { |
| 210 | + |
| 211 | + constructor(public values: string[]){ |
| 212 | + super("enum", [], |
| 213 | + (ci, pv) => `check(${ci} in (${(<string[]>pv).map(v => '"' + v + '"').join(', ')}))`, |
| 214 | + (v: string, pv) => v, |
| 215 | + ["text", "varchar", "char"] |
| 216 | + ) |
| 217 | + } |
| 218 | + |
| 219 | + getBinaryResultType(operator: TokenType, secondType: SQLType): SQLType { |
| 220 | + return operator == TokenType.concatenation ? SQLBaseType.getBaseType('text') : null; |
| 221 | + } |
| 222 | + |
| 223 | + getUnaryResultType(operator: TokenType): SQLType { |
| 224 | + return null; |
| 225 | + } |
| 226 | + |
| 227 | + getBinaryResult(operator: TokenType, value1: any, value2: any) { |
| 228 | + return value1 + value2; |
| 229 | + } |
| 230 | + |
| 231 | + toString(): string { |
| 232 | + return "text"; |
| 233 | + } |
| 234 | + |
| 235 | + getBaseTypeName(): string { |
| 236 | + return "enum"; |
| 237 | + } |
| 238 | + |
| 239 | +} |
| 240 | + |
176 | 241 | let tens: number[] = [1, 10, 100, 1000, 100000, 100000, 1000000, 10000000, 100000000, 1000000000]; |
177 | 242 |
|
178 | 243 | export class SQLDerivedType extends SQLType { |
|
0 commit comments