mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 21:46:00 +00:00
oracle: import data works
This commit is contained in:
@@ -56,24 +56,42 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, pool, n
|
|||||||
const rows = writable.buffer;
|
const rows = writable.buffer;
|
||||||
writable.buffer = [];
|
writable.buffer = [];
|
||||||
|
|
||||||
const dmp = driver.createDumper();
|
if (driver.dialect.allowMultipleValuesInsert) {
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
dmp.putRaw(`INSERT INTO ${fullNameQuoted} (`);
|
||||||
|
dmp.putCollection(',', writable.columnNames, col => dmp.putRaw(driver.dialect.quoteIdentifier(col as string)));
|
||||||
|
dmp.putRaw(')\n VALUES\n');
|
||||||
|
|
||||||
dmp.putRaw(`INSERT INTO ${fullNameQuoted} (`);
|
let wasRow = false;
|
||||||
dmp.putCollection(',', writable.columnNames, col => dmp.putRaw(driver.dialect.quoteIdentifier(col as string)));
|
for (const row of rows) {
|
||||||
dmp.putRaw(')\n VALUES\n');
|
if (wasRow) dmp.putRaw(',\n');
|
||||||
|
dmp.putRaw('(');
|
||||||
|
dmp.putCollection(',', writable.columnNames, col => dmp.putValue(row[col as string]));
|
||||||
|
dmp.putRaw(')');
|
||||||
|
wasRow = true;
|
||||||
|
}
|
||||||
|
dmp.putRaw(';');
|
||||||
|
// require('fs').writeFileSync('/home/jena/test.sql', dmp.s);
|
||||||
|
// console.log(dmp.s);
|
||||||
|
await driver.query(pool, dmp.s, { discardResult: true });
|
||||||
|
} else {
|
||||||
|
for (const row of rows) {
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
dmp.putRaw(`INSERT INTO ${fullNameQuoted} (`);
|
||||||
|
dmp.putCollection(',', writable.columnNames, col => dmp.putRaw(driver.dialect.quoteIdentifier(col as string)));
|
||||||
|
dmp.putRaw(')\n VALUES\n');
|
||||||
|
|
||||||
let wasRow = false;
|
dmp.putRaw('(');
|
||||||
for (const row of rows) {
|
dmp.putCollection(',', writable.columnNames, col => dmp.putValue(row[col as string]));
|
||||||
if (wasRow) dmp.putRaw(',\n');
|
dmp.putRaw(')');
|
||||||
dmp.putRaw('(');
|
await driver.query(pool, dmp.s, { discardResult: true });
|
||||||
dmp.putCollection(',', writable.columnNames, col => dmp.putValue(row[col as string]));
|
}
|
||||||
dmp.putRaw(')');
|
}
|
||||||
wasRow = true;
|
if (options.commitAfterInsert) {
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
dmp.commitTransaction();
|
||||||
|
await driver.query(pool, dmp.s, { discardResult: true });
|
||||||
}
|
}
|
||||||
dmp.putRaw(';');
|
|
||||||
// require('fs').writeFileSync('/home/jena/test.sql', dmp.s);
|
|
||||||
// console.log(dmp.s);
|
|
||||||
await driver.query(pool, dmp.s, { discardResult: true });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
writable.sendIfFull = async () => {
|
writable.sendIfFull = async () => {
|
||||||
|
|||||||
1
packages/types/dialect.d.ts
vendored
1
packages/types/dialect.d.ts
vendored
@@ -12,6 +12,7 @@ export interface SqlDialect {
|
|||||||
defaultSchemaName?: string;
|
defaultSchemaName?: string;
|
||||||
enableConstraintsPerTable?: boolean;
|
enableConstraintsPerTable?: boolean;
|
||||||
requireStandaloneSelectForScopeIdentity?: boolean;
|
requireStandaloneSelectForScopeIdentity?: boolean;
|
||||||
|
allowMultipleValuesInsert?: boolean;
|
||||||
|
|
||||||
dropColumnDependencies?: string[];
|
dropColumnDependencies?: string[];
|
||||||
changeColumnDependencies?: string[];
|
changeColumnDependencies?: string[];
|
||||||
|
|||||||
1
packages/types/engines.d.ts
vendored
1
packages/types/engines.d.ts
vendored
@@ -24,6 +24,7 @@ export interface WriteTableOptions {
|
|||||||
dropIfExists?: boolean;
|
dropIfExists?: boolean;
|
||||||
truncate?: boolean;
|
truncate?: boolean;
|
||||||
createIfNotExists?: boolean;
|
createIfNotExists?: boolean;
|
||||||
|
commitAfterInsert?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EngineAuthType {
|
export interface EngineAuthType {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const dialect = {
|
|||||||
enableConstraintsPerTable: false,
|
enableConstraintsPerTable: false,
|
||||||
anonymousPrimaryKey: true,
|
anonymousPrimaryKey: true,
|
||||||
explicitDropConstraint: true,
|
explicitDropConstraint: true,
|
||||||
|
allowMultipleValuesInsert: true,
|
||||||
quoteIdentifier(s) {
|
quoteIdentifier(s) {
|
||||||
return '`' + s + '`';
|
return '`' + s + '`';
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _computeSingleObjectId() {
|
async _computeSingleObjectId() {
|
||||||
const { typeField, schemaName, pureName } = this.singleObjectFilter;
|
const { typeField, pureName } = this.singleObjectFilter;
|
||||||
this.singleObjectId = `${typeField}:${schemaName || 'public'}.${pureName}`;
|
this.singleObjectId = `${typeField}:${pureName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _runAnalysis() {
|
async _runAnalysis() {
|
||||||
@@ -78,7 +78,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
|
|
||||||
const fkColumnsMapped = fkColumns.rows.map(x => ({
|
const fkColumnsMapped = fkColumns.rows.map(x => ({
|
||||||
pureName: x.pure_name,
|
pureName: x.pure_name,
|
||||||
schemaName: x.schema_name,
|
// schemaName: x.schema_name,
|
||||||
constraintSchema: x.constraint_schema,
|
constraintSchema: x.constraint_schema,
|
||||||
constraintName: x.constraint_name,
|
constraintName: x.constraint_name,
|
||||||
columnName: x.column_name,
|
columnName: x.column_name,
|
||||||
@@ -86,11 +86,11 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
updateAction: x.update_action,
|
updateAction: x.update_action,
|
||||||
deleteAction: x.delete_action,
|
deleteAction: x.delete_action,
|
||||||
refTableName: x.ref_table_name,
|
refTableName: x.ref_table_name,
|
||||||
refSchemaName: x.ref_schema_name,
|
// refSchemaName: x.ref_schema_name,
|
||||||
}));
|
}));
|
||||||
const pkColumnsMapped = pkColumns.rows.map(x => ({
|
const pkColumnsMapped = pkColumns.rows.map(x => ({
|
||||||
pureName: x.pure_name,
|
pureName: x.pure_name,
|
||||||
schemaName: x.schema_name,
|
// schemaName: x.schema_name,
|
||||||
constraintSchema: x.constraint_schema,
|
constraintSchema: x.constraint_schema,
|
||||||
constraintName: x.constraint_name,
|
constraintName: x.constraint_name,
|
||||||
columnName: x.column_name,
|
columnName: x.column_name,
|
||||||
@@ -103,8 +103,8 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
tables: tables.rows.map(table => {
|
tables: tables.rows.map(table => {
|
||||||
const newTable = {
|
const newTable = {
|
||||||
pureName: table.pure_name,
|
pureName: table.pure_name,
|
||||||
schemaName: table.schema_name,
|
// schemaName: table.schema_name,
|
||||||
objectId: `tables:${table.schema_name}.${table.pure_name}`,
|
objectId: `tables:${table.pure_name}`,
|
||||||
contentHash: table.hash_code_columns ? `${table.hash_code_columns}-${table.hash_code_constraints}` : null,
|
contentHash: table.hash_code_columns ? `${table.hash_code_columns}-${table.hash_code_constraints}` : null,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
@@ -146,39 +146,39 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
views: views.rows.map(view => ({
|
views: views.rows.map(view => ({
|
||||||
objectId: `views:${view.schema_name}.${view.pure_name}`,
|
objectId: `views:${view.pure_name}`,
|
||||||
pureName: view.pure_name,
|
pureName: view.pure_name,
|
||||||
schemaName: view.schema_name,
|
// schemaName: view.schema_name,
|
||||||
contentHash: view.hash_code,
|
contentHash: view.hash_code,
|
||||||
createSql: `CREATE VIEW "${view.schema_name}"."${view.pure_name}"\nAS\n${view.create_sql}`,
|
createSql: `CREATE VIEW "${view.pure_name}"\nAS\n${view.create_sql}`,
|
||||||
columns: (columnsGrouped[columnGroup(view)] || []).map(col => getColumnInfo(col)),
|
columns: (columnsGrouped[columnGroup(view)] || []).map(col => getColumnInfo(col)),
|
||||||
})),
|
})),
|
||||||
matviews: matviews
|
matviews: matviews
|
||||||
? matviews.rows.map(matview => ({
|
? matviews.rows.map(matview => ({
|
||||||
objectId: `matviews:${matview.schema_name}.${matview.pure_name}`,
|
objectId: `matviews:${matview.pure_name}`,
|
||||||
pureName: matview.pure_name,
|
pureName: matview.pure_name,
|
||||||
schemaName: matview.schema_name,
|
// schemaName: matview.schema_name,
|
||||||
contentHash: matview.hash_code,
|
contentHash: matview.hash_code,
|
||||||
createSql: `CREATE MATERIALIZED VIEW "${matview.schema_name}"."${matview.pure_name}"\nAS\n${matview.definition}`,
|
createSql: `CREATE MATERIALIZED VIEW "${matview.pure_name}"\nAS\n${matview.definition}`,
|
||||||
columns: (columnsGrouped[columnGroup(view)] || []).map(col => getColumnInfo(col)),
|
columns: (columnsGrouped[columnGroup(view)] || []).map(col => getColumnInfo(col)),
|
||||||
}))
|
}))
|
||||||
: undefined,
|
: undefined,
|
||||||
procedures: routines.rows
|
procedures: routines.rows
|
||||||
.filter(x => x.object_type == 'PROCEDURE')
|
.filter(x => x.object_type == 'PROCEDURE')
|
||||||
.map(proc => ({
|
.map(proc => ({
|
||||||
objectId: `procedures:${proc.schema_name}.${proc.pure_name}`,
|
objectId: `procedures:${proc.pure_name}`,
|
||||||
pureName: proc.pure_name,
|
pureName: proc.pure_name,
|
||||||
schemaName: proc.schema_name,
|
// schemaName: proc.schema_name,
|
||||||
createSql: `CREATE PROCEDURE "${proc.schema_name}"."${proc.pure_name}"() LANGUAGE ${proc.language}\nAS\n$$\n${proc.definition}\n$$`,
|
createSql: `CREATE PROCEDURE "${proc.pure_name}"() LANGUAGE ${proc.language}\nAS\n$$\n${proc.definition}\n$$`,
|
||||||
contentHash: proc.hash_code,
|
contentHash: proc.hash_code,
|
||||||
})),
|
})),
|
||||||
functions: routines.rows
|
functions: routines.rows
|
||||||
.filter(x => x.object_type == 'FUNCTION')
|
.filter(x => x.object_type == 'FUNCTION')
|
||||||
.map(func => ({
|
.map(func => ({
|
||||||
objectId: `functions:${func.schema_name}.${func.pure_name}`,
|
objectId: `functions:${func.pure_name}`,
|
||||||
createSql: `CREATE FUNCTION "${func.schema_name}"."${func.pure_name}"() RETURNS ${func.data_type} LANGUAGE ${func.language}\nAS\n$$\n${func.definition}\n$$`,
|
createSql: `CREATE FUNCTION "${func.pure_name}"() RETURNS ${func.data_type} LANGUAGE ${func.language}\nAS\n$$\n${func.definition}\n$$`,
|
||||||
pureName: func.pure_name,
|
pureName: func.pure_name,
|
||||||
schemaName: func.schema_name,
|
// schemaName: func.schema_name,
|
||||||
contentHash: func.hash_code,
|
contentHash: func.hash_code,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
},
|
},
|
||||||
async writeTable(pool, name, options) {
|
async writeTable(pool, name, options) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return createBulkInsertStreamBase(this, stream, pool, name, options);
|
return createBulkInsertStreamBase(this, stream, pool, name, { ...options, commitAfterInsert: true });
|
||||||
},
|
},
|
||||||
async listDatabases(client) {
|
async listDatabases(client) {
|
||||||
const { rows } = await this.query(client, 'SELECT username as "name" from all_users order by username');
|
const { rows } = await this.query(client, 'SELECT username as "name" from all_users order by username');
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ select
|
|||||||
data_scale as "numeric_scale",
|
data_scale as "numeric_scale",
|
||||||
data_default as "default_value"
|
data_default as "default_value"
|
||||||
FROM all_tab_columns av
|
FROM all_tab_columns av
|
||||||
where OWNER='$owner' AND TABLE_NAME =OBJECT_ID_CONDITION
|
where OWNER='$owner' AND 'tables:' || TABLE_NAME =OBJECT_ID_CONDITION
|
||||||
order by column_id
|
order by column_id
|
||||||
`;
|
`;
|
||||||
@@ -19,6 +19,6 @@ and basecol.table_name = fk.table_name
|
|||||||
and refcol.owner = ref.owner
|
and refcol.owner = ref.owner
|
||||||
and refcol.constraint_name = ref.constraint_name
|
and refcol.constraint_name = ref.constraint_name
|
||||||
and refcol.table_name = ref.table_name
|
and refcol.table_name = ref.table_name
|
||||||
AND fk.constraint_name =OBJECT_ID_CONDITION
|
AND 'tables:' || fk.table_name =OBJECT_ID_CONDITION
|
||||||
order by basecol.position
|
order by basecol.position
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ select i.table_name as "tableName",
|
|||||||
from all_ind_columns ic, all_indexes i
|
from all_ind_columns ic, all_indexes i
|
||||||
where INDEX_OWNER = '$owner' AND ic.index_owner = i.owner
|
where INDEX_OWNER = '$owner' AND ic.index_owner = i.owner
|
||||||
and ic.index_name = i.index_name
|
and ic.index_name = i.index_name
|
||||||
and i.index_name =OBJECT_ID_CONDITION
|
and 'tables:' || i.table_name =OBJECT_ID_CONDITION
|
||||||
order by i.table_owner,
|
order by i.table_owner,
|
||||||
i.table_name,
|
i.table_name,
|
||||||
i.index_name,
|
i.index_name,
|
||||||
|
|||||||
@@ -14,6 +14,6 @@ SELECT -- owner as schema_name,
|
|||||||
'//text()'
|
'//text()'
|
||||||
)) definition
|
)) definition
|
||||||
FROM all_mviews
|
FROM all_mviews
|
||||||
where OWNER = '$owner' AND mview_name=OBJECT_ID_CONDITION
|
where OWNER = '$owner' AND 'matviews:' || mview_name=OBJECT_ID_CONDITION
|
||||||
order by owner, mview_name
|
order by owner, mview_name
|
||||||
`;
|
`;
|
||||||
@@ -11,7 +11,7 @@ where constraint_type = 'P'
|
|||||||
and basecol.owner = pk.owner
|
and basecol.owner = pk.owner
|
||||||
and basecol.constraint_name = pk.constraint_name
|
and basecol.constraint_name = pk.constraint_name
|
||||||
and basecol.table_name = pk.table_name
|
and basecol.table_name = pk.table_name
|
||||||
and pk.constraint_name =OBJECT_ID_CONDITION
|
and 'tables:' || basecol.table_name =OBJECT_ID_CONDITION
|
||||||
and pk.owner = '$owner'
|
and pk.owner = '$owner'
|
||||||
order by basecol.position
|
order by basecol.position
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select
|
||||||
-- owner "schema_name",
|
-- owner "schema_name",
|
||||||
table_name "pure_name"
|
table_name "pure_name"
|
||||||
from
|
from
|
||||||
all_tables
|
all_tables
|
||||||
where OWNER='$owner' AND TABLE_NAME =OBJECT_ID_CONDITION
|
where OWNER='$owner' AND 'tables:' || TABLE_NAME =OBJECT_ID_CONDITION
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ module.exports = `
|
|||||||
select constraint_name as "constraintName"
|
select constraint_name as "constraintName"
|
||||||
from all_constraints
|
from all_constraints
|
||||||
where owner='$owner' and constraint_type = 'U'
|
where owner='$owner' and constraint_type = 'U'
|
||||||
and constraint_name =OBJECT_ID_CONDITION
|
and 'tables:' || table_name =OBJECT_ID_CONDITION
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ from (select
|
|||||||
from all_views av
|
from all_views av
|
||||||
where owner = '$owner' and text_vc is not null
|
where owner = '$owner' and text_vc is not null
|
||||||
) avv
|
) avv
|
||||||
where "pure_name" =OBJECT_ID_CONDITION
|
where 'views:' || "pure_name" =OBJECT_ID_CONDITION
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const dialect = {
|
|||||||
dropUnique: true,
|
dropUnique: true,
|
||||||
createCheck: true,
|
createCheck: true,
|
||||||
dropCheck: true,
|
dropCheck: true,
|
||||||
|
allowMultipleValuesInsert: true,
|
||||||
|
|
||||||
dropReferencesWhenDropTable: true,
|
dropReferencesWhenDropTable: true,
|
||||||
requireStandaloneSelectForScopeIdentity: true,
|
requireStandaloneSelectForScopeIdentity: true,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const dialect = {
|
|||||||
explicitDropConstraint: true,
|
explicitDropConstraint: true,
|
||||||
stringEscapeChar: "'",
|
stringEscapeChar: "'",
|
||||||
fallbackDataType: 'nvarchar',
|
fallbackDataType: 'nvarchar',
|
||||||
|
allowMultipleValuesInsert: true,
|
||||||
dropColumnDependencies: ['indexes', 'primaryKey', 'uniques'],
|
dropColumnDependencies: ['indexes', 'primaryKey', 'uniques'],
|
||||||
quoteIdentifier(s) {
|
quoteIdentifier(s) {
|
||||||
return `[${s}]`;
|
return `[${s}]`;
|
||||||
|
|||||||
Reference in New Issue
Block a user