mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
redis: execute commands
This commit is contained in:
@@ -29,6 +29,7 @@ const driver = {
|
||||
dialect,
|
||||
engine: 'mongo@dbgate-plugin-mongo',
|
||||
title: 'MongoDB',
|
||||
editorMode: 'javascript',
|
||||
defaultPort: 27017,
|
||||
supportsDatabaseUrl: true,
|
||||
databaseUrlPlaceholder: 'e.g. mongodb://username:password@mongodb.mydomain.net/dbname',
|
||||
|
||||
@@ -34,10 +34,9 @@
|
||||
"dbgate-tools": "^4.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
"webpack": "^4.42.0",
|
||||
"webpack-cli": "^3.3.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"webpack-cli": "^3.3.11",
|
||||
"async": "^3.2.3",
|
||||
"ioredis": "^4.28.5"
|
||||
"ioredis": "^4.28.5",
|
||||
"node-redis-dump2": "^0.5.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,77 @@ const stream = require('stream');
|
||||
const driverBase = require('../frontend/driver');
|
||||
const Analyser = require('./Analyser');
|
||||
const Redis = require('ioredis');
|
||||
const RedisDump = require('node-redis-dump2');
|
||||
|
||||
function splitCommandLine(str) {
|
||||
let results = [];
|
||||
let word = '';
|
||||
let validWord;
|
||||
for (let i = 0; i < str.length; ) {
|
||||
if (/\s/.test(str[i])) {
|
||||
//Skips spaces.
|
||||
while (i < str.length && /\s/.test(str[i])) {
|
||||
i++;
|
||||
}
|
||||
results.push(word);
|
||||
word = '';
|
||||
validWord = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str[i] === '"') {
|
||||
i++;
|
||||
while (i < str.length) {
|
||||
if (str[i] === '"') {
|
||||
validWord = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (str[i] === '\\') {
|
||||
i++;
|
||||
word += str[i++];
|
||||
continue;
|
||||
}
|
||||
|
||||
word += str[i++];
|
||||
}
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str[i] === "'") {
|
||||
i++;
|
||||
while (i < str.length) {
|
||||
if (str[i] === "'") {
|
||||
validWord = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (str[i] === '\\') {
|
||||
i++;
|
||||
word += str[i++];
|
||||
continue;
|
||||
}
|
||||
|
||||
word += str[i++];
|
||||
}
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str[i] === '\\') {
|
||||
i++;
|
||||
word += str[i++];
|
||||
continue;
|
||||
}
|
||||
validWord = true;
|
||||
word += str[i++];
|
||||
}
|
||||
if (validWord) {
|
||||
results.push(word);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
const driver = {
|
||||
@@ -29,7 +100,22 @@ const driver = {
|
||||
};
|
||||
},
|
||||
async stream(pool, sql, options) {
|
||||
return null;
|
||||
const parts = splitCommandLine(sql);
|
||||
if (parts.length < 1) {
|
||||
options.done();
|
||||
return;
|
||||
}
|
||||
const command = parts[0].toLowerCase();
|
||||
const args = parts.slice(1);
|
||||
const res = await pool.call(command, ...args);
|
||||
|
||||
options.info({
|
||||
message: JSON.stringify(res),
|
||||
time: new Date(),
|
||||
severity: 'info',
|
||||
});
|
||||
|
||||
options.done();
|
||||
},
|
||||
async readQuery(pool, sql, structure) {
|
||||
const pass = new stream.PassThrough({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const { driverBase } = global.DBGATE_TOOLS;
|
||||
const { redisSplitterOptions } = require('dbgate-query-splitter/lib/options');
|
||||
const Dumper = require('./Dumper');
|
||||
|
||||
/** @type {import('dbgate-types').SqlDialect} */
|
||||
@@ -21,7 +22,9 @@ const driver = {
|
||||
engine: 'redis@dbgate-plugin-redis',
|
||||
title: 'Redis (experimental)',
|
||||
defaultPort: 6379,
|
||||
editorMode: 'text',
|
||||
databaseEngineTypes: ['keyvalue'],
|
||||
getQuerySplitterOptions: () => redisSplitterOptions,
|
||||
supportedKeyTypes: [
|
||||
{
|
||||
name: 'string',
|
||||
|
||||
Reference in New Issue
Block a user