clickhouse: nullable types

This commit is contained in:
SPRINX0\prochazka
2024-09-10 15:18:57 +02:00
parent ceb51a2597
commit 8d865ab3b3
2 changed files with 32 additions and 1 deletions

View File

@@ -1,6 +1,21 @@
const { DatabaseAnalyser } = require('dbgate-tools');
const sql = require('./sql');
function extractDataType(dataType) {
if (!dataType) return {};
if (dataType.startsWith('Nullable(')) {
dataType = dataType.substring('Nullable('.length, dataType.length - 1);
return {
dataType,
notNull: false,
};
}
return {
dataType,
notNull: true,
};
}
class Analyser extends DatabaseAnalyser {
constructor(connection, driver) {
super(connection, driver);
@@ -23,7 +38,12 @@ class Analyser extends DatabaseAnalyser {
...table,
primaryKeyColumns: undefined,
sortingKeyColumns: undefined,
columns: columns.rows.filter((col) => col.pureName == table.pureName),
columns: columns.rows
.filter((col) => col.pureName == table.pureName)
.map((col) => ({
...col,
...extractDataType(col.dataType),
})),
primaryKey: { columns: (table.primaryKeyColumns || '').split(',').map((columnName) => ({ columnName })) },
sortingKey: { columns: (table.sortingKeyColumns || '').split(',').map((columnName) => ({ columnName })) },
foreignKeys: [],

View File

@@ -8,6 +8,17 @@ const dialect = {
rangeSelect: true,
stringEscapeChar: "'",
fallbackDataType: 'String',
createColumn: true,
dropColumn: true,
changeColumn: true,
createIndex: true,
dropIndex: true,
columnProperties: {
columnComment: true,
},
quoteIdentifier(s) {
return `"${s}"`;
},