From 17e2c18c497279bffc9d8b34e5dbc4116e3b5873 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Tue, 3 Mar 2020 08:01:24 +0100 Subject: [PATCH] engines in create script tab --- packages/engines/default/SqlDumper.js | 4 +- packages/engines/mssql/MsSqlDumper.js | 8 +++- packages/web/src/sqleditor/SqlEditor.js | 44 +++++++++++++++++++ packages/web/src/tabs/TableCreateScriptTab.js | 41 +++-------------- packages/web/src/utility/useConnectionInfo.js | 10 +++++ 5 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 packages/web/src/sqleditor/SqlEditor.js create mode 100644 packages/web/src/utility/useConnectionInfo.js diff --git a/packages/engines/default/SqlDumper.js b/packages/engines/default/SqlDumper.js index 8aec609f..3a9c3196 100644 --- a/packages/engines/default/SqlDumper.js +++ b/packages/engines/default/SqlDumper.js @@ -130,7 +130,7 @@ class SqlDumper { if (column.isPersisted) this.put(" ^persisted"); return; } - this.put("%k", column.dataType); + if (column.dataType) this.put("%k", column.dataType); if (column.autoIncrement) { this.autoIncrement(); } @@ -180,7 +180,7 @@ class SqlDumper { createTable(table) { this.put("^create ^table %f ( &>&n", table); this.putCollection(",&n", table.columns, col => { - this.put("%i", col.columnName); + this.put("%i ", col.columnName); this.columnDefinition(col); }); if (table.primaryKey) { diff --git a/packages/engines/mssql/MsSqlDumper.js b/packages/engines/mssql/MsSqlDumper.js index d44e23cf..c622abe4 100644 --- a/packages/engines/mssql/MsSqlDumper.js +++ b/packages/engines/mssql/MsSqlDumper.js @@ -1,5 +1,9 @@ -const SqlDumper = require('../default/SqlDumper'); +const SqlDumper = require("../default/SqlDumper"); -class MsSqlDumper extends SqlDumper {} +class MsSqlDumper extends SqlDumper { + autoIncrement() { + this.put(" ^identity"); + } +} module.exports = MsSqlDumper; diff --git a/packages/web/src/sqleditor/SqlEditor.js b/packages/web/src/sqleditor/SqlEditor.js new file mode 100644 index 00000000..24a62abc --- /dev/null +++ b/packages/web/src/sqleditor/SqlEditor.js @@ -0,0 +1,44 @@ +import React from 'react'; +import useFetch from '../utility/useFetch'; +import styled from 'styled-components'; +import theme from '../theme'; +import AceEditor from 'react-ace'; +import useDimensions from '../utility/useDimensions'; +import engines from '@dbgate/engines'; +import useTableInfo from '../utility/useTableInfo'; +import useConnectionInfo from '../utility/useConnectionInfo'; + +const Wrapper = styled.div` + position: absolute; + left: 0; + top: 0; + right: 0; + bottom: 0; +`; + +const engineToMode = { + mssql: 'sqlserver', + mysql: 'mysql', + postgre: 'pgsql', +}; + +export default function SqlEditor({ value, engine }) { + const [containerRef, { height, width }] = useDimensions(); + + return ( + + + + ); +} diff --git a/packages/web/src/tabs/TableCreateScriptTab.js b/packages/web/src/tabs/TableCreateScriptTab.js index d5c6215e..2217c31f 100644 --- a/packages/web/src/tabs/TableCreateScriptTab.js +++ b/packages/web/src/tabs/TableCreateScriptTab.js @@ -1,45 +1,18 @@ import React from 'react'; -import useFetch from '../utility/useFetch'; -import styled from 'styled-components'; -import theme from '../theme'; -import AceEditor from 'react-ace'; -import useDimensions from '../utility/useDimensions'; import engines from '@dbgate/engines'; import useTableInfo from '../utility/useTableInfo'; - -const Wrapper = styled.div` - position: absolute; - left: 0; - top: 0; - right: 0; - bottom: 0; -`; +import useConnectionInfo from '../utility/useConnectionInfo'; +import SqlEditor from '../sqleditor/SqlEditor'; export default function TableCreateScriptTab({ conid, database, schemaName, pureName }) { - const [containerRef, { height, width }] = useDimensions(); - const tableInfo = useTableInfo({ conid, database, schemaName, pureName }); + const connnection = useConnectionInfo(conid); + if (!connnection || !tableInfo) return null; + // console.log(tableInfo); - console.log(tableInfo); - - const driver = engines('mssql'); + const driver = engines(connnection.engine); const dumper = driver.createDumper(); if (tableInfo) dumper.createTable(tableInfo); - return ( - - - - ); + return ; } diff --git a/packages/web/src/utility/useConnectionInfo.js b/packages/web/src/utility/useConnectionInfo.js new file mode 100644 index 00000000..369c9814 --- /dev/null +++ b/packages/web/src/utility/useConnectionInfo.js @@ -0,0 +1,10 @@ +import useFetch from './useFetch'; + +export default function useConnectionInfo(conid) { + /** @type {import('@dbgate/types').StoredConnection} */ + const connection = useFetch({ + params: { conid }, + url: 'connections/get', + }); + return connection; +}