chore: field type map (#3516)
* chore: field type map * chore: type map
This commit is contained in:
parent
c0b8fa27ec
commit
ca8d6347c6
@ -1,6 +1,7 @@
|
||||
const postgres = {
|
||||
'character varying': 'string',
|
||||
varchar: 'string',
|
||||
character: 'string',
|
||||
text: 'text',
|
||||
char: 'string',
|
||||
oid: 'string',
|
||||
@ -9,36 +10,53 @@ const postgres = {
|
||||
smallint: 'integer',
|
||||
integer: 'integer',
|
||||
bigint: 'bigInt',
|
||||
decimal: 'float',
|
||||
decimal: 'decimal',
|
||||
numeric: 'float',
|
||||
real: 'float',
|
||||
'double precision': 'float',
|
||||
|
||||
'timestamp without time zone': 'date',
|
||||
'timestamp with time zone': 'date',
|
||||
'time without time zone': 'time',
|
||||
|
||||
date: 'date',
|
||||
boolean: 'boolean',
|
||||
|
||||
json: ['json', 'array'],
|
||||
jsonb: ['json', 'array', 'jsonb'],
|
||||
|
||||
point: 'point',
|
||||
path: 'lineString',
|
||||
polygon: 'polygon',
|
||||
circle: 'circle',
|
||||
point: 'json',
|
||||
path: 'json',
|
||||
polygon: 'json',
|
||||
circle: 'json',
|
||||
uuid: 'string',
|
||||
};
|
||||
|
||||
const mysql = {
|
||||
smallint: ['integer', 'boolean'],
|
||||
tinyint: ['integer', 'boolean'],
|
||||
mediumint: ['integer', 'boolean'],
|
||||
|
||||
'smallint unsigned': ['integer', 'boolean'],
|
||||
'tinyint unsigned': ['integer', 'boolean'],
|
||||
'mediumint unsigned': ['integer', 'boolean'],
|
||||
|
||||
char: 'string',
|
||||
date: 'date',
|
||||
time: 'time',
|
||||
varchar: 'string',
|
||||
text: 'text',
|
||||
longtext: 'text',
|
||||
int: 'integer',
|
||||
'int unsigned': 'integer',
|
||||
integer: 'integer',
|
||||
bigint: 'bigInt',
|
||||
'bigint unsigned': 'bigInt',
|
||||
float: 'float',
|
||||
double: 'float',
|
||||
boolean: 'boolean',
|
||||
decimal: 'decimal',
|
||||
|
||||
tinyint: 'integer',
|
||||
datetime: 'date',
|
||||
timestamp: 'date',
|
||||
json: ['json', 'array'],
|
||||
|
@ -13,6 +13,16 @@ type InferredFieldResult = {
|
||||
};
|
||||
|
||||
export class ViewFieldInference {
|
||||
static extractTypeFromDefinition(typeDefinition) {
|
||||
const leftParenIndex = typeDefinition.indexOf('(');
|
||||
|
||||
if (leftParenIndex === -1) {
|
||||
return typeDefinition.toLowerCase();
|
||||
}
|
||||
|
||||
return typeDefinition.substring(0, leftParenIndex).toLowerCase().trim();
|
||||
}
|
||||
|
||||
static async inferFields(options: {
|
||||
db: Database;
|
||||
viewName: string;
|
||||
@ -128,7 +138,7 @@ export class ViewFieldInference {
|
||||
};
|
||||
}
|
||||
|
||||
const queryType = options.type.toLowerCase().replace(/\(\d+\)/, '');
|
||||
const queryType = this.extractTypeFromDefinition(options.type);
|
||||
const mappedType = fieldTypeMap[queryType];
|
||||
|
||||
if (isArray(mappedType)) {
|
||||
|
Loading…
Reference in New Issue
Block a user