clickhouse: added specifcNotNull dialect option

This commit is contained in:
Jan Prochazka
2024-09-11 15:41:26 +02:00
parent fb39cd1302
commit f74533b42f
11 changed files with 17 additions and 9 deletions

View File

@@ -246,7 +246,7 @@ export class SqlDumper implements AlterProcessor {
this.putRaw(' '); this.putRaw(' ');
this.specialColumnOptions(column); this.specialColumnOptions(column);
if (includeNullable) { if (includeNullable && !this.dialect?.specificNotNull) {
this.put(column.notNull ? '^not ^null' : '^null'); this.put(column.notNull ? '^not ^null' : '^null');
} }
if (includeDefault && column.defaultValue?.trim()) { if (includeDefault && column.defaultValue?.trim()) {

View File

@@ -49,6 +49,7 @@ export interface ColumnInfo extends NamedObjectInfo {
notNull?: boolean; notNull?: boolean;
autoIncrement?: boolean; autoIncrement?: boolean;
dataType: string; dataType: string;
displayedDataType?: string;
precision?: number; precision?: number;
scale?: number; scale?: number;
length?: number; length?: number;

View File

@@ -34,6 +34,8 @@ export interface SqlDialect {
createCheck?: boolean; createCheck?: boolean;
dropCheck?: boolean; dropCheck?: boolean;
specificNotNull?: boolean;
// syntax for create column: ALTER TABLE table ADD COLUMN column // syntax for create column: ALTER TABLE table ADD COLUMN column
createColumnWithColumnKeyword?: boolean; createColumnWithColumnKeyword?: boolean;

View File

@@ -31,7 +31,7 @@
return [ return [
{ text: 'Rename column', onClick: handleRenameColumn }, { text: 'Rename column', onClick: handleRenameColumn },
{ text: 'Drop column', onClick: handleDropColumn }, { text: 'Drop column', onClick: handleDropColumn },
{ text: 'Copy name', onClick: () => navigator.clipboard.writeText(data.columnName)}, { text: 'Copy name', onClick: () => navigator.clipboard.writeText(data.columnName) },
]; ];
} }

View File

@@ -88,9 +88,9 @@
{/if} {/if}
<ColumnLabel {...column} /> <ColumnLabel {...column} />
{#if _.isString(column.dataType) && !order} {#if _.isString(column.displayedDataType || column.dataType) && !order}
<span class="data-type" title={column.dataType}> <span class="data-type" title={column.dataType}>
{column.dataType.toLowerCase()} {(column.displayedDataType || column.dataType).toLowerCase()}
</span> </span>
{/if} {/if}
</div> </div>

View File

@@ -196,7 +196,7 @@
<div class="space" /> <div class="space" />
{#if designer?.style?.showDataType && column?.dataType} {#if designer?.style?.showDataType && column?.dataType}
<div class="ml-2"> <div class="ml-2">
{column?.dataType.toLowerCase()} {(column?.displayedDataType || column?.dataType).toLowerCase()}
</div> </div>
{/if} {/if}
{#if designer?.style?.showNullability} {#if designer?.style?.showNullability}

View File

@@ -19,6 +19,7 @@
export let columnName = ''; export let columnName = '';
export let extInfo = null; export let extInfo = null;
export let dataType = null; export let dataType = null;
export let displayedDataType = null;
export let showDataType = false; export let showDataType = false;
export let foreignKey; export let foreignKey;
export let conid = undefined; export let conid = undefined;
@@ -59,7 +60,7 @@
{/if} {/if}
</span> </span>
{:else if dataType} {:else if dataType}
<span class="extinfo">{dataType.toLowerCase()}</span> <span class="extinfo">{(displayedDataType || dataType).toLowerCase()}</span>
{/if} {/if}
{/if} {/if}
</span> </span>

View File

@@ -32,7 +32,9 @@
<FormTextField name="columnName" label="Column name" focused disabled={isReadOnly} /> <FormTextField name="columnName" label="Column name" focused disabled={isReadOnly} />
<DataTypeEditor dialect={driver?.dialect} disabled={isReadOnly} /> <DataTypeEditor dialect={driver?.dialect} disabled={isReadOnly} />
<FormCheckboxField name="notNull" label="NOT NULL" disabled={isReadOnly} /> {#if !driver?.dialect?.specificNotNull}
<FormCheckboxField name="notNull" label="NOT NULL" disabled={isReadOnly} />
{/if}
<FormCheckboxField name="isPrimaryKey" label="Is Primary Key" disabled={isReadOnly} /> <FormCheckboxField name="isPrimaryKey" label="Is Primary Key" disabled={isReadOnly} />
<FormCheckboxField name="autoIncrement" label="Is Autoincrement" disabled={isReadOnly} /> <FormCheckboxField name="autoIncrement" label="Is Autoincrement" disabled={isReadOnly} />
<FormTextField <FormTextField

View File

@@ -187,7 +187,7 @@
on:clickrow={e => showModal(ColumnEditorModal, { columnInfo: e.detail, tableInfo, setTableInfo, driver })} on:clickrow={e => showModal(ColumnEditorModal, { columnInfo: e.detail, tableInfo, setTableInfo, driver })}
onAddNew={isWritable ? addColumn : null} onAddNew={isWritable ? addColumn : null}
columns={[ columns={[
{ !driver?.dialect?.specificNotNull && {
fieldName: 'notNull', fieldName: 'notNull',
header: 'Nullability', header: 'Nullability',
sortable: true, sortable: true,

View File

@@ -4,9 +4,10 @@ const sql = require('./sql');
function extractDataType(dataType) { function extractDataType(dataType) {
if (!dataType) return {}; if (!dataType) return {};
if (dataType.startsWith('Nullable(')) { if (dataType.startsWith('Nullable(')) {
dataType = dataType.substring('Nullable('.length, dataType.length - 1); const displayedDataType = dataType.substring('Nullable('.length, dataType.length - 1);
return { return {
dataType, dataType,
displayedDataType,
notNull: false, notNull: false,
}; };
} }

View File

@@ -64,6 +64,7 @@ const dialect = {
dropIndex: true, dropIndex: true,
anonymousPrimaryKey: true, anonymousPrimaryKey: true,
createColumnWithColumnKeyword: true, createColumnWithColumnKeyword: true,
specificNotNull: true,
columnProperties: { columnProperties: {
columnComment: true, columnComment: true,