mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 13:46:00 +00:00
feat: firebird use attachOrCreate on connect, add dbFileExtension and locaiton on server to tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const _ = require('lodash');
|
||||
const stream = require('stream');
|
||||
const driverBase = require('../frontend/driver');
|
||||
const Analyser = require('./Analyser');
|
||||
const Firebird = require('node-firebird');
|
||||
@@ -22,7 +23,7 @@ const driver = {
|
||||
|
||||
/**@type {Firebird.Database} */
|
||||
const db = await new Promise((resolve, reject) => {
|
||||
Firebird.attach(options, (err, db) => {
|
||||
Firebird.attachOrCreate(options, (err, db) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
@@ -47,18 +48,14 @@ const driver = {
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
const columns = res[0] ? Object.keys(res[0]).map(i => ({ columnName: i })) : [];
|
||||
const columns = res?.[0] ? Object.keys(res[0]).map(i => ({ columnName: i })) : [];
|
||||
|
||||
return {
|
||||
rows: res,
|
||||
rows: res ?? [],
|
||||
columns,
|
||||
};
|
||||
},
|
||||
|
||||
async script(dbhan, sql) {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
|
||||
async stream(dbhan, sql, options) {
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
@@ -101,7 +98,36 @@ const driver = {
|
||||
},
|
||||
|
||||
async readQuery(dbhan, sql, structure) {
|
||||
throw new Error('Not implemented');
|
||||
console.log('readQuery from SQL:', sql);
|
||||
const pass = new stream.PassThrough({
|
||||
objectMode: true,
|
||||
highWaterMark: 100,
|
||||
});
|
||||
let hasSentColumns = false;
|
||||
|
||||
dbhan.client.sequentially(
|
||||
sql,
|
||||
[],
|
||||
(row, index) => {
|
||||
if (!hasSentColumns) {
|
||||
hasSentColumns = true;
|
||||
|
||||
const columns = Object.keys(row).map(i => ({ columnName: i }));
|
||||
|
||||
pass.write({
|
||||
__isStreamHeader: true,
|
||||
...(structure || { columns }),
|
||||
});
|
||||
}
|
||||
|
||||
pass.write(row);
|
||||
},
|
||||
err => {
|
||||
pass.end();
|
||||
}
|
||||
);
|
||||
|
||||
return pass;
|
||||
},
|
||||
|
||||
async writeTable(dbhan, name, options) {
|
||||
@@ -126,10 +152,6 @@ const driver = {
|
||||
];
|
||||
},
|
||||
|
||||
async createDatabase(dbhan, name) {},
|
||||
|
||||
async dropDatabase(dbhan, name) {},
|
||||
|
||||
async close(dbhan) {
|
||||
return new Promise((resolve, reject) => {
|
||||
dbhan.client.detach(err => {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
const { SqlDumper } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||
|
||||
class Dumper extends SqlDumper {}
|
||||
class Dumper extends SqlDumper {
|
||||
autoIncrement() {
|
||||
this.put(' ^generated ^by ^default ^as ^identity');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
|
||||
@@ -17,6 +17,8 @@ const dialect = {
|
||||
return `"${s}"`;
|
||||
},
|
||||
|
||||
dbFileExtension: '.fdb',
|
||||
|
||||
createColumn: true,
|
||||
dropColumn: true,
|
||||
changeColumn: true,
|
||||
|
||||
Reference in New Issue
Block a user