mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 06:46:00 +00:00
redis connection
This commit is contained in:
9
plugins/dbgate-plugin-redis/src/backend/Analyser.js
Normal file
9
plugins/dbgate-plugin-redis/src/backend/Analyser.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const { DatabaseAnalyser } = require('dbgate-tools');
|
||||
|
||||
class Analyser extends DatabaseAnalyser {
|
||||
constructor(pool, driver) {
|
||||
super(pool, driver);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Analyser;
|
||||
67
plugins/dbgate-plugin-redis/src/backend/driver.js
Normal file
67
plugins/dbgate-plugin-redis/src/backend/driver.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const _ = require('lodash');
|
||||
const stream = require('stream');
|
||||
const driverBase = require('../frontend/driver');
|
||||
const Analyser = require('./Analyser');
|
||||
const Redis = require('ioredis');
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
const driver = {
|
||||
...driverBase,
|
||||
analyserClass: Analyser,
|
||||
async connect({ server, port, password, database }) {
|
||||
const pool = new Redis({
|
||||
host: server,
|
||||
port,
|
||||
password,
|
||||
db: 0,
|
||||
});
|
||||
return pool;
|
||||
},
|
||||
// @ts-ignore
|
||||
async query(pool, sql) {
|
||||
return {
|
||||
rows: [],
|
||||
columns: [],
|
||||
};
|
||||
},
|
||||
async stream(pool, sql, options) {
|
||||
return null;
|
||||
},
|
||||
async readQuery(pool, sql, structure) {
|
||||
const pass = new stream.PassThrough({
|
||||
objectMode: true,
|
||||
highWaterMark: 100,
|
||||
});
|
||||
|
||||
// pass.write(structure)
|
||||
// pass.write(row1)
|
||||
// pass.write(row2)
|
||||
// pass.end()
|
||||
|
||||
return pass;
|
||||
},
|
||||
async writeTable(pool, name, options) {
|
||||
return createBulkInsertStreamBase(this, stream, pool, name, options);
|
||||
},
|
||||
async info(pool) {
|
||||
const info = await pool.info();
|
||||
return _.fromPairs(
|
||||
info
|
||||
.split('\n')
|
||||
.filter((x) => x.trim() && !x.trim().startsWith('#'))
|
||||
.map((x) => x.split(':'))
|
||||
);
|
||||
},
|
||||
async getVersion(pool) {
|
||||
const info = await this.info(pool);
|
||||
|
||||
return { version: info.redis_version };
|
||||
},
|
||||
async listDatabases(pool) {
|
||||
const info = await this.info(pool);
|
||||
|
||||
return _.range(16).map((index) => ({ name: `db${index}`, extInfo: info[`db${index}`], sortOrder: index }));
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = driver;
|
||||
6
plugins/dbgate-plugin-redis/src/backend/index.js
Normal file
6
plugins/dbgate-plugin-redis/src/backend/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const driver = require('./driver');
|
||||
|
||||
module.exports = {
|
||||
packageName: 'dbgate-plugin-redis',
|
||||
drivers: [driver],
|
||||
};
|
||||
6
plugins/dbgate-plugin-redis/src/frontend/Dumper.js
Normal file
6
plugins/dbgate-plugin-redis/src/frontend/Dumper.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const { SqlDumper } = require('dbgate-tools');
|
||||
|
||||
class Dumper extends SqlDumper {
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
30
plugins/dbgate-plugin-redis/src/frontend/driver.js
Normal file
30
plugins/dbgate-plugin-redis/src/frontend/driver.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const { driverBase } = global.DBGATE_TOOLS;
|
||||
const Dumper = require('./Dumper');
|
||||
|
||||
/** @type {import('dbgate-types').SqlDialect} */
|
||||
const dialect = {
|
||||
limitSelect: true,
|
||||
rangeSelect: true,
|
||||
offsetFetchRangeSyntax: true,
|
||||
stringEscapeChar: "'",
|
||||
fallbackDataType: 'nvarchar(max)',
|
||||
quoteIdentifier(s) {
|
||||
return `[${s}]`;
|
||||
},
|
||||
};
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
const driver = {
|
||||
...driverBase,
|
||||
dumperClass: Dumper,
|
||||
dialect,
|
||||
engine: 'redis@dbgate-plugin-redis',
|
||||
title: 'Redis',
|
||||
defaultPort: 6379,
|
||||
|
||||
showConnectionField: (field, values) => {
|
||||
return ['server', 'port', 'password'].includes(field);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = driver;
|
||||
6
plugins/dbgate-plugin-redis/src/frontend/index.js
Normal file
6
plugins/dbgate-plugin-redis/src/frontend/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import driver from './driver';
|
||||
|
||||
export default {
|
||||
packageName: 'dbgate-plugin-redis',
|
||||
drivers: [driver],
|
||||
};
|
||||
Reference in New Issue
Block a user