kysely
Version:
Type safe SQL query builder
70 lines (69 loc) • 1.33 kB
JavaScript
/// <reference types="./data-type-node.d.ts" />
import { freeze } from '../util/object-utils.js';
const SIMPLE_COLUMN_DATA_TYPES = [
'varchar',
'char',
'text',
'integer',
'int2',
'int4',
'int8',
'smallint',
'bigint',
'boolean',
'real',
'double precision',
'float4',
'float8',
'decimal',
'numeric',
'binary',
'bytea',
'date',
'datetime',
'time',
'timetz',
'timestamp',
'timestamptz',
'serial',
'bigserial',
'uuid',
'json',
'jsonb',
'blob',
];
const COLUMN_DATA_TYPE_REGEX = [
/^varchar\(\d+\)$/,
/^char\(\d+\)$/,
/^decimal\(\d+, \d+\)$/,
/^numeric\(\d+, \d+\)$/,
/^binary\(\d+\)$/,
/^datetime\(\d+\)$/,
/^time\(\d+\)$/,
/^timez\(\d+\)$/,
/^timestamp\(\d+\)$/,
/^timestamptz\(\d+\)$/,
];
/**
* @internal
*/
export const DataTypeNode = freeze({
is(node) {
return node.kind === 'DataTypeNode';
},
create(dataType) {
return freeze({
kind: 'DataTypeNode',
dataType,
});
},
});
export function isColumnDataType(dataType) {
if (SIMPLE_COLUMN_DATA_TYPES.includes(dataType)) {
return true;
}
if (COLUMN_DATA_TYPE_REGEX.some((r) => r.test(dataType))) {
return true;
}
return false;
}