monetdb 1.3.4 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.github/workflows/Linux.yml +3 -3
  2. package/.github/workflows/docs.yml +79 -0
  3. package/.github/workflows/macos.yml +3 -3
  4. package/.github/workflows/monetdb-versions.yml +43 -0
  5. package/README.md +44 -514
  6. package/docs/components/alert.tsx +10 -0
  7. package/docs/components/info.tsx +6 -0
  8. package/docs/next.config.js +24 -0
  9. package/docs/package-lock.json +5069 -0
  10. package/docs/package.json +22 -0
  11. package/docs/pages/_app.js +9 -0
  12. package/docs/pages/_meta.json +18 -0
  13. package/docs/pages/apis/_meta.json +4 -0
  14. package/docs/pages/apis/connection.mdx +60 -0
  15. package/docs/pages/apis/result.mdx +39 -0
  16. package/docs/pages/filetransfer.mdx +43 -0
  17. package/docs/pages/index.mdx +27 -0
  18. package/docs/pages/prepstmt.mdx +13 -0
  19. package/docs/pages/result.mdx +41 -0
  20. package/docs/theme.config.js +35 -0
  21. package/docs/v1/README.md +532 -0
  22. package/package.json +16 -20
  23. package/src/PrepareStatement.ts +37 -0
  24. package/src/connection.ts +125 -0
  25. package/src/defaults.ts +11 -0
  26. package/src/file-transfer.ts +173 -0
  27. package/src/index.ts +3 -0
  28. package/src/mapi.ts +1016 -0
  29. package/src/monetize.ts +67 -0
  30. package/test/connection.ts +43 -0
  31. package/test/exec-queries.ts +112 -0
  32. package/test/filetransfer.ts +94 -0
  33. package/test/prepare-statement.ts +27 -0
  34. package/test/query-stream.ts +41 -0
  35. package/test/tmp/.gitignore +4 -0
  36. package/tsconfig.json +24 -0
  37. package/.travis.yml +0 -11
  38. package/dist/mapi.d.ts +0 -58
  39. package/dist/mapi.js +0 -250
  40. package/dist/mapi.js.map +0 -1
  41. package/dist/tsconfig.tsbuildinfo +0 -1
  42. package/foo.js +0 -16
  43. package/index.js +0 -5
  44. package/src/mapi-connection.js +0 -784
  45. package/src/monetdb-connection.js +0 -385
  46. package/src/utils.js +0 -27
  47. package/test/common.js +0 -45
  48. package/test/install-monetdb.sh +0 -11
  49. package/test/monetdb_stream.js +0 -106
  50. package/test/start-monetdb.sh +0 -38
  51. package/test/test.js +0 -908
  52. package/test/test_connection.js +0 -290
  53. /package/docs/{README.v0.md → v0/README.v0.md} +0 -0
  54. /package/docs/{MapiConnection.md → v1/MapiConnection.md} +0 -0
  55. /package/docs/{v1-notes.md → v1/v1-notes.md} +0 -0
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "docs",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "next.config.js",
6
+ "scripts": {
7
+ "start": "next dev",
8
+ "build": "next build"
9
+ },
10
+ "keywords": [],
11
+ "author": {
12
+ "name": "Svetlin Stalinov",
13
+ "email": "svetlin.stalinov@monetdbsolutions.com"
14
+ },
15
+ "dependencies": {
16
+ "next": "^14.0.1",
17
+ "nextra": "^2.13.2",
18
+ "nextra-theme-docs": "^2.13.2",
19
+ "react": "^18.2.0",
20
+ "react-dom": "^18.2.0"
21
+ }
22
+ }
@@ -0,0 +1,9 @@
1
+ import 'nextra-theme-docs/style.css'
2
+
3
+ export default function Nextra({ Component, pageProps }) {
4
+ return (
5
+ <>
6
+ <Component {...pageProps} />
7
+ </>
8
+ )
9
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "index": "Getting Started",
3
+ "filetransfer": "File Transfer",
4
+ "result": "Query result",
5
+ "prepstmt": "Prepare Statement",
6
+ "apis": "API",
7
+ "versions": {
8
+ "title": "archive",
9
+ "type": "menu",
10
+ "items": {
11
+ "v0": {
12
+ "title": "v0",
13
+ "href": "https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/v0"},
14
+ "v1": {
15
+ "title": "v1",
16
+ "href": "https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/v1"}}
17
+ }
18
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "connection": "Connecting",
3
+ "result": "QueryResult"
4
+ }
@@ -0,0 +1,60 @@
1
+ ## Connecting
2
+ ```ts
3
+ const conn = new Connection(config: MapiConfig | string);
4
+ ```
5
+ , all the optional fields get default values if not specified.
6
+ ### Using configuration options
7
+ ```ts
8
+ interface MapiConfig {
9
+ database: string;
10
+ username?: string;
11
+ password?: string;
12
+ language?: MAPI_LANGUAGE; // sql
13
+ host?: string;
14
+ port?: number;
15
+ timeout?: number;
16
+ autoCommit?: boolean;
17
+ replySize?: number;
18
+ }
19
+
20
+ const defaults = {
21
+ host: process.env.MAPI_HOST || 'localhost',
22
+ port: process.env.MAPI_PORT || 50000,
23
+ username: process.env.MAPI_USER || 'monetdb',
24
+ password: process.env.MAPI_PASSWORD || 'monetdb',
25
+ database: process.env.MAPI_DATABASE,
26
+ autoCommit: false,
27
+ replySize: -1,
28
+ };
29
+
30
+ const config: MapiConfig = {
31
+ ...defaults
32
+ database: 'test',
33
+ }
34
+ const conn = new Connection(config);
35
+ ```
36
+ ### Using URL
37
+ ```ts
38
+ const conn = new Connection('mapi:monetdb://<username>:<password>@<hostname>:<port>/<database>');
39
+ ```
40
+ ### Connection object
41
+ ```ts
42
+ declare class Connection extends EventEmitter {
43
+ autoCommit?: boolean;
44
+ replySize?: number;
45
+ sizeHeader?: boolean;
46
+ mapi: MapiConnection;
47
+ constructor(params: MapiConfig | MAPI_URI);
48
+ connect(callback?: ConnectCallback): Promise<boolean>;
49
+ close(): Promise<boolean>;
50
+ commit(): Promise<any>;
51
+ private command;
52
+ execute(sql: string, stream?: boolean): Promise<QueryResult|QueryStream>;
53
+ prepare(sql: string): Promise<PrepareStatement>;
54
+ setAutocommit(v: boolean): Promise<boolean>;
55
+ setReplySize(v: number): Promise<number>;
56
+ setSizeHeader(v: boolean): Promise<boolean>;
57
+ setTimezone(sec: number): Promise<any>;
58
+ rollback(): Promise<any>;
59
+ }
60
+ ```
@@ -0,0 +1,39 @@
1
+ ## Query Result
2
+ The result object returned from sucessful query execution.
3
+ ```ts
4
+ type QueryResult = {
5
+ id?: number;
6
+ type?: string;
7
+ queryId?: number;
8
+ rowCnt?: number;
9
+ affectedRows?: number;
10
+ columnCnt?: number;
11
+ queryTime?: number;
12
+ sqlOptimizerTime?: number;
13
+ malOptimizerTime?: number;
14
+ columns?: Column[];
15
+ headers?: ResponseHeaders;
16
+ data?: any[];
17
+ };
18
+ import { Connection } from 'monetdb';
19
+ const conn = new Connection({database: 'test'});
20
+ const ready = await conn.connect();
21
+ const res: QueryResult = await conn.execute('select 1 as one, 2 as two');
22
+ console.log(res);
23
+ // {
24
+ // type: '&1',
25
+ // id: 1,
26
+ // rowCnt: 1,
27
+ // columnCnt: 2,
28
+ // queryId: 37,
29
+ // queryTime: 311,
30
+ // malOptimizerTime: 129,
31
+ // sqlOptimizerTime: 22,
32
+ // columns: [
33
+ // { table: '.', name: 'one', type: 'tinyint', index: 0 },
34
+ // { table: '.', name: 'two', type: 'tinyint', index: 1 }
35
+ // ],
36
+ // data: [ [ 1, 2 ] ]
37
+ // }
38
+
39
+ ```
@@ -0,0 +1,43 @@
1
+ ## File Transfer
2
+ MonetDB supports the non-standard `COPY INTO` statement to load a CSV-like
3
+ text file into a table or to dump a table into a text file. This statement has an
4
+ optional modifier `ON CLIENT` to indicate that the server should not
5
+ try to open the file on the server side but instead ask the client to open it
6
+ on its behalf.
7
+
8
+ For example::
9
+ ```sql
10
+ COPY INTO mytable FROM 'data.csv' ON CLIENT
11
+ USING DELIMITERS ',', E'\n', '"';
12
+ ```
13
+ For security reason `monetdb-nodejs` enforces files to be realtive to the current
14
+ working directory of the Node.js process.
15
+ ## Skip rows and early cancellation
16
+ MonetDB's `COPY INTO` statement allows you to skip, for example, the first
17
+ line in a file using the modifier `OFFSET 2`, and load `n` records from the file using
18
+ `RECORDS` modifier.
19
+ ```sql
20
+ COPY 100 RECORDS OFFSET 2 INTO mytable FROM 'data.csv' ON CLIENT
21
+ ```
22
+ , for detailed documentation on `COPY INTO` statement please vist [MonetDB documentation](https://www.monetdb.org/documentation-Jun2023/user-guide/sql-manual/data-loading/)
23
+ ## Example
24
+ Assume `data.csv` with the following content
25
+ ```bash
26
+ cat<<EOF>data.csv
27
+ 1|one
28
+ 2|two
29
+ 3|three
30
+ EOF
31
+ ```
32
+ , then load that into MonetDB
33
+ ```ts
34
+ import {Connection} from 'monetdb';
35
+
36
+ const conn = new Connection({database: 'test'});
37
+ const ready = await conn.connect();
38
+ await conn.execute('create table foo(i int, a varchar(10))');
39
+ let res = await conn.execute(`copy into foo from \'data.csv\' on client`);
40
+ res = await conn.execute('select * from foo order by i');
41
+ console.log(res.data);
42
+ // [[1, 'one'], [2, 'two'], [3, 'three']]
43
+ ```
@@ -0,0 +1,27 @@
1
+ ---
2
+ title: Getting Started
3
+ slug: /
4
+ ---
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ $ npm install monetdb
10
+ ```
11
+
12
+ ## Usage
13
+ The simplest way to connect is to use default connection options and pass only the database name.
14
+
15
+ ```js
16
+ import { Connection} from 'monetdb'
17
+
18
+ const opt = {database: 'test'}
19
+
20
+ const conn = new Connection(opt)
21
+ const ready = await conn.connect();
22
+ const res = conn.exec('select 42');
23
+ console.log(res.data)
24
+ await conn.close();
25
+ ```
26
+ , see [connection api](/apis/connection) for more details.
27
+
@@ -0,0 +1,13 @@
1
+ ## Prepare Statement
2
+ The PREPARE statement compiles an SQL statement into its execution plan on the server. This is useful for statements which need to be executed many times but with different values each time, such as an INSERT or UPDATE or SELECT query.
3
+ ```ts
4
+ const ready = await conn.connect();
5
+ let res = await conn.execute('create table foo(a int, b boolean, c string, d date, f decimal)');
6
+ const prepStmt = await conn.prepare('insert into foo values (?, ?, ?, ?, ?)');
7
+ res = await prepStmt.execute(1, true, 'first', '2022-12-12', 1.11);
8
+ res = await prepStmt.execute(2, false, 'second', '2022-12-12', 2.22);
9
+ res = await prepStmt.execute(3, true, 'third', '2022-12-12', 3.33);
10
+ await prepStmt.release();
11
+ ```
12
+ For more information on prepare statement please visit [MonetDB documentation](https://www.monetdb.org/documentation-Jun2023/user-guide/sql-manual/data-manipulation/prepare-statement/).
13
+
@@ -0,0 +1,41 @@
1
+ ## Query result size
2
+ Query result size can be set with `replySize` `Connection` option. It defines the number of data rows returned in the initial response.
3
+ By default this options is set to `-1`, which means fetch all the data. If `replySize` is set to any positive number, only that many
4
+ data rows will be fetched, while the rest will stay cached at the server. The `replySize` can be set initially when connection is created, or by invoking `setReplySize` method on the `Connection` object.
5
+ ```ts
6
+ // set replySize to 100
7
+ const conn = new Connection({database: 'test', replySize: 100});
8
+ await conn.connect();
9
+ let res = await conn.execute("select * from generate_series(1, 1001)");
10
+ console.log(res.data.length);
11
+ // 100
12
+ await conn.setReplySize(-1); // back to default
13
+ res = await conn.execute("select * from generate_series(1, 1001)");
14
+ console.log(res.data.length);
15
+ // 1000
16
+ ```
17
+ ## Streaming query result
18
+ When query result is quite large it's often useful to start process the data chunks as soon as they are available
19
+ on the client. This can be achieved by invoking `execute` method on the `Connection` object with `stream=true`.
20
+ ```ts
21
+ // execute(sql: string, stream?: boolean): Promise<any>;
22
+ const ready = await conn.connect();
23
+ const stream: QueryStream = await conn.execute('select * from generate_series(1, 10000)', true);
24
+ const colInfo = [];
25
+ const data = [];
26
+ stream.on('header', (cols: any[]) => {
27
+ // do something with col info
28
+ });
29
+
30
+ stream.on('data', (tuples: any[]) => {
31
+ for (let t of tuples) {
32
+ data.push(t);
33
+ }
34
+ });
35
+
36
+ stream.on('end', () => {
37
+ // do something on end of streaming
38
+ });
39
+
40
+ await conn.close();
41
+ ```
@@ -0,0 +1,35 @@
1
+ // theme.config.js
2
+ export default {
3
+ project: {
4
+ link: 'https://github.com/MonetDB/monetdb-nodejs',
5
+ },
6
+ docsRepositoryBase: 'https://github.com/MonetDB/monetdb-nodejs/blob/master/docs', // base URL for the docs repository
7
+ darkMode: true,
8
+ footer: true,
9
+ navigation: {
10
+ prev: true,
11
+ next: true,
12
+ },
13
+ footer: {
14
+ text: `Mozilla Public License, v.2.0 ${new Date().getFullYear()}`,
15
+ },
16
+ editLink: {
17
+ text: 'Edit this page on GitHub',
18
+ },
19
+ logo: (
20
+ <>
21
+ <span>monetdb-nodejs</span>
22
+ </>
23
+ ),
24
+ head: (
25
+ <>
26
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
27
+ <meta
28
+ name="description"
29
+ content="MonetDB Node.js connector"
30
+ />
31
+ <meta name="og:title" content="monetdb-nodejs" />
32
+ <meta name="og:description" content="MonetDB Node.js driver" />
33
+ </>
34
+ ),
35
+ }