mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 22:43:58 +00:00
documentation
This commit is contained in:
131
packages/api/README.md
Normal file
131
packages/api/README.md
Normal file
@@ -0,0 +1,131 @@
|
||||
# dbgate-api
|
||||
|
||||
Allows run DbGate data-manipulation scripts.
|
||||
|
||||
## Installation
|
||||
|
||||
yarn add dbgate-api
|
||||
|
||||
## Usage
|
||||
|
||||
This example exports table Customer info CSV file.
|
||||
|
||||
```javascript
|
||||
|
||||
const dbgateApi = require('dbgate-api');
|
||||
async function run() {
|
||||
const reader = await dbgateApi.tableReader({
|
||||
connection: { server: 'localhost', engine: 'mssql', user: 'sa', password: 'xxxx', database: 'Chinook' },
|
||||
schemaName: 'dbo',
|
||||
pureName: 'Customer',
|
||||
});
|
||||
const writer = await dbgateApi.csvWriter({ fileName: 'Customer.csv' });
|
||||
await dbgateApi.copyStream(reader, writer);
|
||||
|
||||
console.log('Finished job script');
|
||||
}
|
||||
dbgateApi.runScript(run);
|
||||
|
||||
```
|
||||
|
||||
## dbgateApi functions
|
||||
|
||||
### dbgateApi.copyStream
|
||||
Copies data from reader into writer. Reader and writer should be created from functions listed below.
|
||||
```js
|
||||
await dbgateApi.copyStream(reader, writer);
|
||||
```
|
||||
|
||||
### dbgateApi.tableReader
|
||||
Reads table or view.
|
||||
```js
|
||||
const reader = await dbgateApi.tableReader({
|
||||
connection: { server: 'localhost', engine: 'mssql' | 'postgres' | 'mysql', user: 'root', password: 'xxxx', database: 'DB_NAME' },
|
||||
schemaName: 'dbo',
|
||||
pureName: 'Customer',
|
||||
});
|
||||
```
|
||||
|
||||
### dbgateApi.queryReader
|
||||
Executes query and reads its result.
|
||||
```js
|
||||
const reader = await dbgateApi.tableReader({
|
||||
connection: { server: 'localhost', engine: 'mssql' | 'postgres' | 'mysql', user: 'root', password: 'xxxx', database: 'DB_NAME' },
|
||||
sql: 'SELECT * FROM Album',
|
||||
});
|
||||
```
|
||||
|
||||
### dbgateApi.tableWriter
|
||||
Imports data into table. Options are optional, default values are false.
|
||||
- dropIfExists - if table already exists, it is dropped before import
|
||||
- truncate - delete table content before import
|
||||
- createIfNotExists - create table, if not exists
|
||||
```js
|
||||
const reader = await dbgateApi.tableWriter({
|
||||
connection: { server: 'localhost', engine: 'mssql' | 'postgres' | 'mysql', user: 'root', password: 'xxxx', database: 'DB_NAME' },
|
||||
schemaName: 'dbo',
|
||||
pureName: 'Customer',
|
||||
options: {
|
||||
dropIfExists: false,
|
||||
truncate: false,
|
||||
createIfNotExists: false,
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### dbgateApi.csvReader
|
||||
Reads CSV file
|
||||
```js
|
||||
const reader = await dbgateApi.csvReader({
|
||||
fileName: '/home/root/test.csv',
|
||||
encoding: 'utf-8',
|
||||
header: true,
|
||||
delimiter: ',',
|
||||
quoted: false,
|
||||
limitRows: null
|
||||
});
|
||||
```
|
||||
|
||||
### dbgateApi.csvWriter
|
||||
Writes CSV file
|
||||
```js
|
||||
const reader = await dbgateApi.csvWriter({
|
||||
fileName: '/home/root/test.csv',
|
||||
encoding: 'utf-8',
|
||||
header: true,
|
||||
delimiter: ',',
|
||||
quoted: false
|
||||
});
|
||||
```
|
||||
|
||||
### dbgateApi.jsonLinesReader
|
||||
Reads JSON lines data file. On first line could be structure. Every line contains one row as JSON serialized object.
|
||||
```js
|
||||
const reader = await dbgateApi.jsonLinesReader({
|
||||
fileName: '/home/root/test.jsonl',
|
||||
encoding: 'utf-8',
|
||||
header: true,
|
||||
limitRows: null
|
||||
});
|
||||
```
|
||||
|
||||
### dbgateApi.jsonLinesWriter
|
||||
Writes JSON lines data file. On first line could be structure. Every line contains one row as JSON serialized object.
|
||||
```js
|
||||
const reader = await dbgateApi.jsonLinesWriter({
|
||||
fileName: '/home/root/test.jsonl',
|
||||
encoding: 'utf-8',
|
||||
header: true
|
||||
});
|
||||
```
|
||||
|
||||
### dbgateApi.excelSheetReader
|
||||
Reads tabular data from one sheet in MS Excel file.
|
||||
```js
|
||||
const reader = await dbgateApi.excelSheetReader({
|
||||
fileName: '/home/root/test.xlsx',
|
||||
sheetName: 'Album',
|
||||
limitRows: null
|
||||
});
|
||||
```
|
||||
|
||||
@@ -2,7 +2,16 @@
|
||||
"name": "dbgate-api",
|
||||
"main": "src/index.js",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
|
||||
"homepage": "https://dbgate.org/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dbshell/dbgate.git"
|
||||
},
|
||||
"funding": "https://www.paypal.com/paypalme/JanProchazkaCz/30eur",
|
||||
"author": "Jan Prochazka",
|
||||
"license": "GPL",
|
||||
|
||||
"dependencies": {
|
||||
"dbgate-engines": "^1.0.0",
|
||||
"dbgate-sqltree": "^1.0.0",
|
||||
|
||||
@@ -152,3 +152,4 @@ module.exports = {
|
||||
return promise;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,52 @@
|
||||
# dbgate-engines
|
||||
|
||||
JavaScript library implementing MySQL, MS SQL and PostgreSQL operations
|
||||
JavaScript library implementing MySQL, MS SQL and PostgreSQL operations. Server as abstraction layer for other DbGate packages, which could be database-engine independend. It can be used both on frontent (in browser) and on backend (in nodejs), but connection to real database is allowed only on backend.
|
||||
|
||||
## Installation
|
||||
|
||||
yarn add dbgate-engines
|
||||
|
||||
## Usage
|
||||
```javascript
|
||||
const engines = require('dbgate-engines');
|
||||
// driver supports operations of EngineDriver listed belowe
|
||||
const driver = engine('mysql');
|
||||
```
|
||||
|
||||
In most cases, you don't use driver methods directly, but you pass driver instance into other dbgate packages.
|
||||
|
||||
## Driver definition
|
||||
|
||||
|
||||
```typescript
|
||||
export interface EngineDriver {
|
||||
// works on both frontend and backend
|
||||
engine: string;
|
||||
dialect: SqlDialect;
|
||||
createDumper(): SqlDumper;
|
||||
|
||||
// works only on backend
|
||||
connect(nativeModules, { server, port, user, password, database }): any;
|
||||
query(pool: any, sql: string): Promise<QueryResult>;
|
||||
stream(pool: any, sql: string, options: StreamOptions);
|
||||
readQuery(pool: any, sql: string, structure?: TableInfo): Promise<stream.Readable>;
|
||||
writeTable(pool: any, name: NamedObjectInfo, options: WriteTableOptions): Promise<stream.Writeable>;
|
||||
analyseSingleObject(
|
||||
pool: any,
|
||||
name: NamedObjectInfo,
|
||||
objectTypeField: keyof DatabaseInfo
|
||||
): Promise<TableInfo | ViewInfo | ProcedureInfo | FunctionInfo | TriggerInfo>;
|
||||
analyseSingleTable(pool: any, name: NamedObjectInfo): Promise<TableInfo>;
|
||||
getVersion(pool: any): Promise<{ version: string }>;
|
||||
listDatabases(
|
||||
pool: any
|
||||
): Promise<
|
||||
{
|
||||
name: string;
|
||||
}[]
|
||||
>;
|
||||
analyseFull(pool: any): Promise<DatabaseInfo>;
|
||||
analyseIncremental(pool: any, structure: DatabaseInfo): Promise<DatabaseInfo>;
|
||||
}
|
||||
|
||||
```
|
||||
7
packages/tools/README.md
Normal file
7
packages/tools/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# dbgate-tools
|
||||
|
||||
Auxiliary tools for other DbGate packages.
|
||||
|
||||
## Installation
|
||||
|
||||
yarn add dbgate-tools
|
||||
@@ -3,6 +3,16 @@
|
||||
"name": "dbgate-tools",
|
||||
"main": "lib/index.js",
|
||||
"typings": "lib/index.d.ts",
|
||||
|
||||
"homepage": "https://dbgate.org/",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dbshell/dbgate.git"
|
||||
},
|
||||
"funding": "https://www.paypal.com/paypalme/JanProchazkaCz/30eur",
|
||||
"author": "Jan Prochazka",
|
||||
"license": "GPL",
|
||||
|
||||
"scripts": {
|
||||
"prepare": "yarn build",
|
||||
"build": "tsc",
|
||||
|
||||
Reference in New Issue
Block a user