mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
sqlite WIP
This commit is contained in:
parent
3c089a5b81
commit
caa2d22dbd
@ -51,7 +51,7 @@
|
||||
async function handleSubmit(e) {
|
||||
axiosInstance.post('connections/save', {
|
||||
...e.detail,
|
||||
singleDatabase: e.detail.defaultDatabase ? e.detail.singleDatabase : false,
|
||||
singleDatabase: driver?.isFileDatabase || (e.detail.defaultDatabase ? e.detail.singleDatabase : false),
|
||||
});
|
||||
closeCurrentModal();
|
||||
}
|
||||
|
@ -6,10 +6,11 @@
|
||||
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
|
||||
|
||||
$: conid = _.get($currentDatabase, 'connection._id');
|
||||
$: singleDatabase = _.get($currentDatabase, 'connection.singleDatabase');
|
||||
$: database = _.get($currentDatabase, 'name');
|
||||
</script>
|
||||
|
||||
{#if conid && database}
|
||||
{#if conid && (database || singleDatabase)}
|
||||
<SqlObjectList {conid} {database} />
|
||||
{:else}
|
||||
<WidgetsInnerContainer>
|
||||
|
@ -8,14 +8,11 @@ class Analyser extends DatabaseAnalyser {
|
||||
async _runAnalysis() {
|
||||
const collections = await this.pool.__getDatabase().listCollections().toArray();
|
||||
|
||||
const res = this.mergeAnalyseResult(
|
||||
{
|
||||
collections: collections.map((x) => ({
|
||||
pureName: x.name,
|
||||
})),
|
||||
},
|
||||
(x) => x.pureName
|
||||
);
|
||||
const res = this.mergeAnalyseResult({
|
||||
collections: collections.map((x) => ({
|
||||
pureName: x.name,
|
||||
})),
|
||||
});
|
||||
// console.log('MERGED', res);
|
||||
return res;
|
||||
}
|
||||
|
@ -4,6 +4,23 @@ class Analyser extends DatabaseAnalyser {
|
||||
constructor(pool, driver) {
|
||||
super(pool, driver);
|
||||
}
|
||||
|
||||
async _runAnalysis() {
|
||||
const tables = await this.driver.query(this.pool, "select * from sqlite_master where type='table'");
|
||||
console.log('tables', tables);
|
||||
|
||||
const res = this.mergeAnalyseResult(
|
||||
{
|
||||
tables: tables.rows.map((x) => ({
|
||||
pureName: x.name,
|
||||
objectId: x.name,
|
||||
})),
|
||||
},
|
||||
(x) => x.pureName
|
||||
);
|
||||
// console.log('MERGED', res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Analyser;
|
||||
|
@ -3,28 +3,28 @@ const stream = require('stream');
|
||||
const driverBase = require('../frontend/driver');
|
||||
const Analyser = require('./Analyser');
|
||||
|
||||
let sqlite3;
|
||||
let Database;
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
const driver = {
|
||||
...driverBase,
|
||||
analyserClass: Analyser,
|
||||
async connect({ server, port, user, password, database }) {
|
||||
const pool = new NativePool({
|
||||
server,
|
||||
port,
|
||||
user,
|
||||
password,
|
||||
database,
|
||||
});
|
||||
await pool.connect();
|
||||
async connect({ databaseFile }) {
|
||||
const pool = new Database(databaseFile);
|
||||
return pool;
|
||||
},
|
||||
// @ts-ignore
|
||||
async query(pool, sql) {
|
||||
const stmt = pool.prepare(sql);
|
||||
// stmt.raw();
|
||||
const columns = stmt.columns();
|
||||
const rows = stmt.all();
|
||||
return {
|
||||
rows: [],
|
||||
columns: [],
|
||||
rows,
|
||||
columns: columns.map((col) => ({
|
||||
columnName: col.name,
|
||||
dataType: col.type,
|
||||
})),
|
||||
};
|
||||
},
|
||||
async stream(pool, sql, options) {
|
||||
@ -47,16 +47,13 @@ const driver = {
|
||||
return createBulkInsertStreamBase(this, stream, pool, name, options);
|
||||
},
|
||||
async getVersion(pool) {
|
||||
return { version: '1.0.0' };
|
||||
},
|
||||
async listDatabases(pool) {
|
||||
return [{ name: 'db1' }, { name: 'db2' }];
|
||||
return { version: 'SQLite 3' };
|
||||
},
|
||||
};
|
||||
|
||||
driver.initialize = (dbgateEnv) => {
|
||||
if (dbgateEnv.nativeModules && dbgateEnv.nativeModules['better-sqlite3']) {
|
||||
sqlite3 = dbgateEnv.nativeModules['better-sqlite3']();
|
||||
Database = dbgateEnv.nativeModules['better-sqlite3']();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -3,4 +3,7 @@ const driver = require('./driver');
|
||||
module.exports = {
|
||||
packageName: 'dbgate-plugin-sqlite',
|
||||
driver,
|
||||
initialize(dbgateEnv) {
|
||||
driver.initialize(dbgateEnv);
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user