mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 22:03:58 +00:00
save changes to DB
This commit is contained in:
@@ -74,4 +74,12 @@ module.exports = {
|
|||||||
const res = await this.sendRequest(opened, { msgtype: 'queryData', sql });
|
const res = await this.sendRequest(opened, { msgtype: 'queryData', sql });
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// runCommand_meta: 'post',
|
||||||
|
// async runCommand({ conid, database, sql }) {
|
||||||
|
// console.log(`Running SQL command , conid=${conid}, database=${database}, sql=${sql}`);
|
||||||
|
// const opened = await this.ensureOpened(conid, database);
|
||||||
|
// const res = await this.sendRequest(opened, { msgtype: 'queryData', sql });
|
||||||
|
// return res;
|
||||||
|
// },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,22 +33,23 @@ function waitConnected() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleQueryData({ msgid, sql }) {
|
async function handleQueryData({ msgid, sql }) {
|
||||||
// const select = new Select();
|
|
||||||
// if (driver.dialect.limitSelect) select.topRecords = 100;
|
|
||||||
// if (driver.dialect.rangeSelect) select.range = { offset: 0, limit: 100 };
|
|
||||||
// select.from = { schemaName, pureName };
|
|
||||||
// select.selectAll = true;
|
|
||||||
// const sql = select.toSql(driver);
|
|
||||||
|
|
||||||
await waitConnected();
|
await waitConnected();
|
||||||
const driver = engines(storedConnection);
|
const driver = engines(storedConnection);
|
||||||
const res = await driver.query(systemConnection, sql);
|
const res = await driver.query(systemConnection, sql);
|
||||||
process.send({ msgtype: 'response', msgid, ...res });
|
process.send({ msgtype: 'response', msgid, ...res });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async function handleRunCommand({ msgid, sql }) {
|
||||||
|
// await waitConnected();
|
||||||
|
// const driver = engines(storedConnection);
|
||||||
|
// const res = await driver.query(systemConnection, sql);
|
||||||
|
// process.send({ msgtype: 'response', msgid, ...res });
|
||||||
|
// }
|
||||||
|
|
||||||
const messageHandlers = {
|
const messageHandlers = {
|
||||||
connect: handleConnect,
|
connect: handleConnect,
|
||||||
queryData: handleQueryData,
|
queryData: handleQueryData,
|
||||||
|
// runCommand: handleRunCommand,
|
||||||
};
|
};
|
||||||
|
|
||||||
async function handleMessage({ msgtype, ...other }) {
|
async function handleMessage({ msgtype, ...other }) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const _ = require("lodash");
|
const _ = require('lodash');
|
||||||
const MsSqlAnalyser = require("./MsSqlAnalyser");
|
const MsSqlAnalyser = require('./MsSqlAnalyser');
|
||||||
const MsSqlDumper = require("./MsSqlDumper");
|
const MsSqlDumper = require('./MsSqlDumper');
|
||||||
|
|
||||||
/** @type {import('@dbgate/types').SqlDialect} */
|
/** @type {import('@dbgate/types').SqlDialect} */
|
||||||
const dialect = {
|
const dialect = {
|
||||||
@@ -10,7 +10,7 @@ const dialect = {
|
|||||||
stringEscapeChar: "'",
|
stringEscapeChar: "'",
|
||||||
quoteIdentifier(s) {
|
quoteIdentifier(s) {
|
||||||
return `[${s}]`;
|
return `[${s}]`;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {import('@dbgate/types').EngineDriver} */
|
/** @type {import('@dbgate/types').EngineDriver} */
|
||||||
@@ -23,8 +23,8 @@ const driver = {
|
|||||||
password,
|
password,
|
||||||
database,
|
database,
|
||||||
options: {
|
options: {
|
||||||
enableArithAbort: true
|
enableArithAbort: true,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
pool._nativeModules = nativeModules;
|
pool._nativeModules = nativeModules;
|
||||||
return pool;
|
return pool;
|
||||||
@@ -32,20 +32,24 @@ const driver = {
|
|||||||
async query(pool, sql) {
|
async query(pool, sql) {
|
||||||
const resp = await pool.request().query(sql);
|
const resp = await pool.request().query(sql);
|
||||||
// console.log(Object.keys(resp.recordset));
|
// console.log(Object.keys(resp.recordset));
|
||||||
const columns = _.sortBy(_.values(resp.recordset.columns), "index");
|
// console.log(resp);
|
||||||
return { rows: resp.recordset, columns };
|
const res = {};
|
||||||
|
|
||||||
|
if (resp.recordset) {
|
||||||
|
res.columns = _.sortBy(_.values(resp.recordset.columns), 'index');
|
||||||
|
res.rows = resp.recordset;
|
||||||
|
}
|
||||||
|
if (resp.rowsAffected) {
|
||||||
|
res.rowsAffected = _.sum(resp.rowsAffected);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
},
|
},
|
||||||
async getVersion(pool) {
|
async getVersion(pool) {
|
||||||
const { version } = (
|
const { version } = (await this.query(pool, 'SELECT @@VERSION AS version')).rows[0];
|
||||||
await this.query(pool, "SELECT @@VERSION AS version")
|
|
||||||
).rows[0];
|
|
||||||
return { version };
|
return { version };
|
||||||
},
|
},
|
||||||
async listDatabases(pool) {
|
async listDatabases(pool) {
|
||||||
const { rows } = await this.query(
|
const { rows } = await this.query(pool, 'SELECT name FROM sys.databases order by name');
|
||||||
pool,
|
|
||||||
"SELECT name FROM sys.databases order by name"
|
|
||||||
);
|
|
||||||
return rows;
|
return rows;
|
||||||
},
|
},
|
||||||
async analyseFull(pool) {
|
async analyseFull(pool) {
|
||||||
|
|||||||
5
packages/types/query.d.ts
vendored
5
packages/types/query.d.ts
vendored
@@ -8,6 +8,7 @@ export interface QueryResultColumn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface QueryResult {
|
export interface QueryResult {
|
||||||
rows: any[];
|
rows?: any[];
|
||||||
columns: QueryResultColumn[];
|
columns?: QueryResultColumn[];
|
||||||
|
rowsAffected?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import DataGridRow from './DataGridRow';
|
|||||||
import { countColumnSizes, countVisibleRealColumns } from './gridutil';
|
import { countColumnSizes, countVisibleRealColumns } from './gridutil';
|
||||||
import useModalState from '../modals/useModalState';
|
import useModalState from '../modals/useModalState';
|
||||||
import ConfirmSqlModal from '../modals/ConfirmSqlModal';
|
import ConfirmSqlModal from '../modals/ConfirmSqlModal';
|
||||||
import { changeSetToSql } from '@dbgate/datalib';
|
import { changeSetToSql, createChangeSet } from '@dbgate/datalib';
|
||||||
import { scriptToSql } from '@dbgate/sqltree';
|
import { scriptToSql } from '@dbgate/sqltree';
|
||||||
|
|
||||||
const GridContainer = styled.div`
|
const GridContainer = styled.div`
|
||||||
@@ -118,7 +118,7 @@ export default function DataGridCore(props) {
|
|||||||
|
|
||||||
const sql = display.getPageQuery(loadedRows.length, 100);
|
const sql = display.getPageQuery(loadedRows.length, 100);
|
||||||
|
|
||||||
let response = await axios.request({
|
const response = await axios.request({
|
||||||
url: 'database-connections/query-data',
|
url: 'database-connections/query-data',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
params: {
|
params: {
|
||||||
@@ -312,6 +312,22 @@ export default function DataGridCore(props) {
|
|||||||
confirmSqlModalState.open();
|
confirmSqlModalState.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleConfirmSql() {
|
||||||
|
const response = await axios.request({
|
||||||
|
url: 'database-connections/query-data',
|
||||||
|
method: 'post',
|
||||||
|
params: {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
},
|
||||||
|
data: { sql: confirmSql },
|
||||||
|
});
|
||||||
|
|
||||||
|
setChangeSet(createChangeSet());
|
||||||
|
setConfirmSql(null);
|
||||||
|
display.reload();
|
||||||
|
}
|
||||||
|
|
||||||
function handleGridKeyDown(event) {
|
function handleGridKeyDown(event) {
|
||||||
if (
|
if (
|
||||||
!event.ctrlKey &&
|
!event.ctrlKey &&
|
||||||
@@ -576,7 +592,7 @@ export default function DataGridCore(props) {
|
|||||||
onScroll={handleRowScroll}
|
onScroll={handleRowScroll}
|
||||||
viewportRatio={visibleRowCountUpperBound / rowCountNewIncluded}
|
viewportRatio={visibleRowCountUpperBound / rowCountNewIncluded}
|
||||||
/>
|
/>
|
||||||
<ConfirmSqlModal modalState={confirmSqlModalState} sql={confirmSql} engine={display.engine} />
|
<ConfirmSqlModal modalState={confirmSqlModalState} sql={confirmSql} engine={display.engine} onConfirm={handleConfirmSql} />
|
||||||
</GridContainer>
|
</GridContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const SqlWrapper = styled.div`
|
|||||||
width: 40vw;
|
width: 40vw;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function ConfirmSqlModal({ modalState, sql, engine }) {
|
export default function ConfirmSqlModal({ modalState, sql, engine, onConfirm }) {
|
||||||
return (
|
return (
|
||||||
<ModalBase modalState={modalState}>
|
<ModalBase modalState={modalState}>
|
||||||
<h2>Save changes</h2>
|
<h2>Save changes</h2>
|
||||||
@@ -23,7 +23,14 @@ export default function ConfirmSqlModal({ modalState, sql, engine }) {
|
|||||||
</SqlWrapper>
|
</SqlWrapper>
|
||||||
|
|
||||||
<FormRow>
|
<FormRow>
|
||||||
<input type="button" value="OK" onClick={modalState.close} />
|
<input
|
||||||
|
type="button"
|
||||||
|
value="OK"
|
||||||
|
onClick={() => {
|
||||||
|
modalState.close();
|
||||||
|
onConfirm();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<input type="button" value="Close" onClick={modalState.close} />
|
<input type="button" value="Close" onClick={modalState.close} />
|
||||||
</FormRow>
|
</FormRow>
|
||||||
</ModalBase>
|
</ModalBase>
|
||||||
|
|||||||
Reference in New Issue
Block a user