more data types in table editor #285

This commit is contained in:
Jan Prochazka 2022-05-22 12:04:59 +02:00
parent 6a35107c5f
commit 09e3be9ec3
7 changed files with 115 additions and 2 deletions

View File

@ -32,4 +32,6 @@ export interface SqlDialect {
dropReferencesWhenDropTable?: boolean;
disableExplicitTransaction?: boolean;
predefinedDataTypes: string[];
}

View File

@ -26,7 +26,7 @@
>
<FormTextField name="columnName" label="Column name" focused />
<DataTypeEditor />
<DataTypeEditor dialect={driver?.dialect} />
<FormCheckboxField name="notNull" label="NOT NULL" />
<FormCheckboxField name="isPrimaryKey" label="Is Primary Key" />

View File

@ -4,7 +4,7 @@
const { values, setFieldValue } = getFormContext();
$: dataTypes = ['int', 'nvarchar(250)', 'datetime', 'numeric(10,2)', 'float'];
$: dataTypes = dialect?.predefinedDataTypes || ['int', 'varchar(250)', 'datetime', 'numeric(10,2)', 'float'];
function createDataTypesMenu() {
return dataTypes.map(type => ({
@ -13,6 +13,7 @@
}));
}
export let dialect;
</script>
<FormDropDownTextField name="dataType" label="Data type" menu={createDataTypesMenu} />

View File

@ -40,6 +40,36 @@ const dialect = {
isSparse: true,
isPersisted: true,
},
predefinedDataTypes: [
'bigint',
'bit',
'decimal(10,2)',
'int',
'money',
'numeric',
'smallint',
'smallmoney',
'tinyint',
'float',
'real',
'date',
'datetime2',
'datetime',
'datetimeofffset',
'smalldatetime',
'time',
'char(20)',
'varchar(250)',
'text',
'nchar(20)',
'nvarchar(250)',
'ntext',
'binary(100)',
'varbinary(100)',
'image',
'xml',
],
};
/** @type {import('dbgate-types').EngineDriver} */

View File

@ -36,6 +36,38 @@ const dialect = {
isUnsigned: true,
isZerofill: true,
},
predefinedDataTypes: [
'char(20)',
'varchar(250)',
'binary(250)',
'varbinary(250)',
'tinyblob',
'tinytext',
'text(1000)',
'blob(1000)',
'mediumtext',
'mediumblob',
'longtext',
'longblob',
'enum(val1,val2,val3)',
'set(val1,val2,val3)',
'bit(32)',
'tinyint',
'bool',
'smallint',
'mediumint',
'int',
'bigint',
'float',
'double',
'decimal',
'date',
'datetime',
'timestamp',
'time',
'year',
],
};
const mysqlDriverBase = {

View File

@ -32,6 +32,52 @@ const dialect = {
dropCheck: true,
dropReferencesWhenDropTable: true,
predefinedDataTypes: [
'bigint',
'bigserial',
'bit',
'varbit',
'boolean',
'box',
'bytea',
'char(20)',
'varchar(250)',
'cidr',
'circle',
'date',
'double precision',
'inet',
'int',
'interval',
'json',
'jsonb',
'line',
'lseg',
'macaddr',
'macaddr8',
'money',
'numeric(10,2)',
'path',
'pg_lsn',
'pg_snapshot',
'point',
'polygon',
'real',
'smallint',
'smallserial',
'serial',
'text',
'time',
'timetz',
'timestamp',
'timestamptz',
'tsquery',
'tsvector',
'txid_snapshot',
'uuid',
'xml',
],
};
const postgresDriverBase = {

View File

@ -53,6 +53,8 @@ const driver = {
getQuerySplitterOptions: (usage) => (usage == 'stream' ? noSplitSplitterOptions : sqliteSplitterOptions),
// isFileDatabase: true,
isElectronOnly: true,
predefinedDataTypes: ['integer', 'real', 'text', 'blob'],
};
module.exports = driver;