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