monetdb 2.0.0 → 2.0.2
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.
- package/README.md +5 -4
- package/dist/PrepareStatement.d.ts +12 -0
- package/dist/PrepareStatement.js +29 -0
- package/dist/PrepareStatement.js.map +1 -0
- package/dist/QueryStream.d.ts +7 -0
- package/dist/QueryStream.js +13 -0
- package/dist/QueryStream.js.map +1 -0
- package/dist/connection.d.ts +25 -0
- package/dist/connection.js +104 -0
- package/dist/connection.js.map +1 -0
- package/dist/connections.d.ts +1 -0
- package/dist/connections.js +49 -0
- package/dist/connections.js.map +1 -0
- package/dist/defaults.d.ts +10 -0
- package/dist/defaults.js +13 -0
- package/dist/defaults.js.map +1 -0
- package/dist/file-transfer.d.ts +34 -0
- package/dist/file-transfer.js +194 -0
- package/dist/file-transfer.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mapi.d.ts +148 -0
- package/dist/mapi.js +851 -0
- package/dist/mapi.js.map +1 -0
- package/dist/monetize.d.ts +2 -0
- package/dist/monetize.js +57 -0
- package/dist/monetize.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +7 -2
- package/src/defaults.ts +7 -9
- package/src/mapi.ts +1 -1
- package/.github/workflows/Linux.yml +0 -45
- package/.github/workflows/docs.yml +0 -79
- package/.github/workflows/macos.yml +0 -43
- package/.github/workflows/monetdb-versions.yml +0 -43
- package/docs/components/alert.tsx +0 -10
- package/docs/components/info.tsx +0 -6
- package/docs/next.config.js +0 -24
- package/docs/package-lock.json +0 -5069
- package/docs/package.json +0 -22
- package/docs/pages/_app.js +0 -9
- package/docs/pages/_meta.json +0 -16
- package/docs/pages/apis/_meta.json +0 -4
- package/docs/pages/apis/connection.mdx +0 -60
- package/docs/pages/apis/result.mdx +0 -39
- package/docs/pages/index.mdx +0 -27
- package/docs/theme.config.js +0 -35
- package/docs/v0/README.v0.md +0 -138
- package/docs/v1/MapiConnection.md +0 -53
- package/docs/v1/README.md +0 -532
- package/docs/v1/v1-notes.md +0 -173
- package/test/connection.ts +0 -43
- package/test/exec-queries.ts +0 -100
- package/test/filetransfer.ts +0 -94
- package/test/prepare-statement.ts +0 -27
- package/test/query-stream.ts +0 -41
- package/test/tmp/.gitignore +0 -4
- package/tsconfig.json +0 -24
package/docs/v1/v1-notes.md
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
# Major changes since v0.\*
|
2
|
-
|
3
|
-
[](https://travis-ci.org/MonetDB/monetdb-nodejs)
|
4
|
-
[](https://coveralls.io/github/MonetDB/monetdb-nodejs?branch=master)
|
5
|
-
[](https://badge.fury.io/js/monetdb)
|
6
|
-
[](https://david-dm.org/MonetDB/monetdb-nodejs)
|
7
|
-
|
8
|
-
|
9
|
-
### Our interface is now promise based
|
10
|
-
In version 0.\*, all asynchronous methods were callback based.
|
11
|
-
We did provide a wrapper for Q fans, but the focus was not on promises.
|
12
|
-
This has changed.
|
13
|
-
Our interface is now fully promise based, meaning all asynchronous methods return promises.
|
14
|
-
For backwards compatibility, we provide a [callback based wrapper](#callbackwrapper], that adheres as much as possible to the old API.
|
15
|
-
|
16
|
-
|
17
|
-
### Global and local options
|
18
|
-
In version 0.\*, you could provide one options object when creating a new connection. Now you can provide
|
19
|
-
options to the result of the require('monetdb') call, which are considered to be the global options applied to all
|
20
|
-
connections you make. Then, on creating a connection you can again pass options specific to this connection.
|
21
|
-
And there are some options that you can change after you created a connection.
|
22
|
-
See [the options section](https://github.com/MonetDB/monetdb-nodejs/#options) for all possible options.
|
23
|
-
|
24
|
-
|
25
|
-
### Reconnect logic has been added
|
26
|
-
A connection from version 0.\* failed on a socket error or a socket close, leaving it up to the caller to create
|
27
|
-
a new connection. This is integrated into v1.\*, allowing you to specify how many times we should try to reconnect
|
28
|
-
and with what timeout intervals.
|
29
|
-
See [the reconnect section](https://github.com/MonetDB/monetdb-nodejs/#reconnect) for more details.
|
30
|
-
|
31
|
-
|
32
|
-
### Prettified result objects can be returned
|
33
|
-
In version 0.\*, an array of arrays is returned as the result set of a SELECT query.
|
34
|
-
This is still the default behavior, but upon request you can now receive an array of objects, where the column names
|
35
|
-
are used as the object keys.
|
36
|
-
See [the pretty result section](https://github.com/MonetDB/monetdb-nodejs/#pretty) for more info.
|
37
|
-
|
38
|
-
|
39
|
-
### No internal information is exposed anymore
|
40
|
-
Version 0.\* allowed access to all internal variables, like the socket and the connection state.
|
41
|
-
Fiddling with these variables could cause unexpected behavior, and therfore we removed this possibility.
|
42
|
-
For normal usage, a [MonetDBConnection object](https://github.com/MonetDB/monetdb-nodejs/#mdbconnection) should offer plenty of possibilities.
|
43
|
-
For advanced usage, like firing raw queries against the database, you can directly access the
|
44
|
-
[MapiConnection object](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/MapiConnection.md)
|
45
|
-
from a [MonetDBConnection object](https://github.com/MonetDB/monetdb-nodejs/#mdbconnection).
|
46
|
-
|
47
|
-
<a name="raw"></a>
|
48
|
-
### Raw queries are not directly possible anymore
|
49
|
-
Version 0.\* allowed the execution of raw queries by adding the boolean value 'true' to a query call.
|
50
|
-
**This now has another effect**.
|
51
|
-
Providing a boolean value to a query call influences whether or not the query result will be prettified or not.
|
52
|
-
See [the section on pretty results](https://github.com/MonetDB/monetdb-nodejs/#pretty) for more information.
|
53
|
-
If you want to execute raw queries, you need to do a request to the
|
54
|
-
[MapiConnection object](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/MapiConnection.md) object that is
|
55
|
-
contained within every MonetDBConnection object:
|
56
|
-
|
57
|
-
```javascript
|
58
|
-
var MDB = require('monetdb')();
|
59
|
-
|
60
|
-
var conn = new MDB(options);
|
61
|
-
conn.connect();
|
62
|
-
conn.mapiConnection.request('Xreply_size -1')
|
63
|
-
```
|
64
|
-
|
65
|
-
Note: if you do not know what raw queries (like the above example) are, you will probably not need them. You can stick to
|
66
|
-
using normal SQL queries.
|
67
|
-
|
68
|
-
### Timezone is set automatically
|
69
|
-
From version 1.\*, the timezone of every connection will be set automatically to the timezone of the system on which the
|
70
|
-
MonetDB NodeJS module is run. This behavior can be overwritten by providing the right options. See
|
71
|
-
[the timezone section](https://github.com/MonetDB/monetdb-nodejs/#timezone) for more information.
|
72
|
-
|
73
|
-
<a name="env"></a>
|
74
|
-
### Connection environment is not loaded automatically anymore
|
75
|
-
Version 0.\* automatically loaded the connection environment (result of query 'SELECT * FROM sys.env()') into every
|
76
|
-
connection object. In version 1.\* this does not happen anymore. If you want to easily access it, use the
|
77
|
-
[MonetDBConnection.env method](https://github.com/MonetDB/monetdb-nodejs/#mdbconnection_env)
|
78
|
-
|
79
|
-
### Null values now map directly from database to Javascript
|
80
|
-
Version 0.\* mapped NULL values in query results to the Javascript keyword undefined. Version 1.\* maps NULL values
|
81
|
-
directly to Javascript null keywords.
|
82
|
-
|
83
|
-
### Continuous integration has been set up
|
84
|
-
To guarantee continuity, we now use Travis-CI to automatically test all of the code.
|
85
|
-
When the tests pass, we compute the coverage and upload this to Coveralls.
|
86
|
-
To show the current build status and testing coverage, we added appropriate badges to the top of the documentation pages.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
<a name="callbackwrapper"></a>
|
93
|
-
# Backward compatibility
|
94
|
-
All asynchronous methods of the [MonetDBConnection object](https://github.com/MonetDB/monetdb-nodejs/#mdbconnection) return promises.
|
95
|
-
To provide backward compatibility with version 0.\*, where asynchronous methods were callback based (and chainable),
|
96
|
-
we created a wrapper that mimics the behavior of v0.\*. Example:
|
97
|
-
|
98
|
-
```javascript
|
99
|
-
var MDB = require('monetdb')();
|
100
|
-
|
101
|
-
// Instantiate connection object and get its wrapper
|
102
|
-
var conn = new MDB({dbname: 'mydb'}).getCallbackWrapper();
|
103
|
-
|
104
|
-
conn.connect(function(err) {
|
105
|
-
if(err) {
|
106
|
-
console.log('Connection error: ' + err);
|
107
|
-
return;
|
108
|
-
}
|
109
|
-
console.log('Connection succeeded!');
|
110
|
-
});
|
111
|
-
|
112
|
-
// Chain queries (not possible with promise based API)
|
113
|
-
conn.query('SELECT something FROM sometable', function(err, result) {
|
114
|
-
if(err) {
|
115
|
-
// something went wrong, handle query error here
|
116
|
-
return;
|
117
|
-
}
|
118
|
-
// do something with query result
|
119
|
-
|
120
|
-
}).query('SELECT something_else FROM sometable', function(err, result) {
|
121
|
-
if(err) {
|
122
|
-
// something went wrong, handle query error here
|
123
|
-
return;
|
124
|
-
}
|
125
|
-
// do something with query result
|
126
|
-
});
|
127
|
-
```
|
128
|
-
|
129
|
-
Note that you could also use the promise based API and the callback based API interchangeably for the same connection:
|
130
|
-
|
131
|
-
```javascript
|
132
|
-
var MDB = require('monetdb')();
|
133
|
-
|
134
|
-
// Instantiate connection object
|
135
|
-
var conn = new MDB({dbname: 'mydb'});
|
136
|
-
|
137
|
-
// Store its wrapper in another variable
|
138
|
-
var connWrapped = conn.getCallbackWrapper();
|
139
|
-
|
140
|
-
// Connect using promises
|
141
|
-
conn.connect().then(function() {
|
142
|
-
console.log('Connection succeeded!')
|
143
|
-
});
|
144
|
-
|
145
|
-
// Query using callbacks
|
146
|
-
connWrapped.query('SELECT * FROM foo', function(err, result) {
|
147
|
-
...
|
148
|
-
});
|
149
|
-
```
|
150
|
-
|
151
|
-
You can however safely throw away the promise based object. All methods described for the [MonetDBConnection object](https://github.com/MonetDB/monetdb-nodejs/#mdbconnection)
|
152
|
-
are also available on the wrapper. All promise returning functions become callback based, and all others are exactly the same.
|
153
|
-
|
154
|
-
|
155
|
-
# Upgrade instructions
|
156
|
-
Upgrading from v0.\* to v1.\* should be easy. For minimal work, here are some hints:
|
157
|
-
|
158
|
-
1. Replace *var mdb = require('monetdb')* with *var MDB = require('monetdb')()*
|
159
|
-
If you want, you can even pass default options: *var MDB = require('monetdb')(options)*
|
160
|
-
2. Look for usages of .connect() in your code
|
161
|
-
- If you used callback functions, replace *conn = mdb.connect()* with
|
162
|
-
*conn = new MDB(options).getCallbackWrapper(); conn.connect();*.
|
163
|
-
You can then keep on using callback based functionality and query chaining as you did.
|
164
|
-
- If you already used the promise wrapper, you can replace *conn = mdb.connect()* with
|
165
|
-
*conn = new MDB(options); conn.connect();*
|
166
|
-
3. If you used the promise wrapper, remove the trailing Q from the calls to functions
|
167
|
-
connectQ, requestQ, queryQ, prepareQ, closeQ, and disconnectQ.
|
168
|
-
4. Check all your calls to the query and request methods and see if you ever provide the boolean
|
169
|
-
value 'true' as a last argument. Those calls execute a raw query. See [here](#raw) for how to do
|
170
|
-
raw queries in v1.\*.
|
171
|
-
5. See if you use [attributes from the connection environment](#env) in your code.
|
172
|
-
If you do, fetch them using the
|
173
|
-
[MonetDBConnection.env](https://github.com/MonetDB/monetdb-nodejs#mdbconnection_env) method instead.
|
package/test/connection.ts
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
import assert from "assert";
|
2
|
-
import Connection from "../src/connection";
|
3
|
-
|
4
|
-
describe("Connection", function () {
|
5
|
-
let conn: Connection;
|
6
|
-
|
7
|
-
it("should connect with default opt", async function () {
|
8
|
-
conn = new Connection({ database: "test" });
|
9
|
-
const ready = await conn.connect();
|
10
|
-
assert(ready, new Error("failed to connect"));
|
11
|
-
const closed = await conn.close();
|
12
|
-
assert(closed);
|
13
|
-
});
|
14
|
-
|
15
|
-
it("should build Connection from mapi uri default username and password", function () {
|
16
|
-
conn = new Connection("mapi:monetdb://foo.com:55555/test");
|
17
|
-
assert.strictEqual(conn.mapi.host, "foo.com");
|
18
|
-
assert.strictEqual(conn.mapi.port, 55555);
|
19
|
-
assert.strictEqual(conn.mapi.username, "monetdb");
|
20
|
-
assert.strictEqual(conn.mapi.password, "monetdb");
|
21
|
-
assert.strictEqual(conn.mapi.database, "test");
|
22
|
-
});
|
23
|
-
|
24
|
-
it("should build Connection from mapi uri with auth component", function () {
|
25
|
-
conn = new Connection(
|
26
|
-
"mapi:monetdb://barname:barpassword@foo.com:55555/test"
|
27
|
-
);
|
28
|
-
assert.strictEqual(conn.mapi.host, "foo.com");
|
29
|
-
assert.strictEqual(conn.mapi.port, 55555);
|
30
|
-
assert.strictEqual(conn.mapi.username, "barname");
|
31
|
-
assert.strictEqual(conn.mapi.password, "barpassword");
|
32
|
-
assert.strictEqual(conn.mapi.database, "test");
|
33
|
-
});
|
34
|
-
|
35
|
-
it("should build Connection from mapi uri no port", function () {
|
36
|
-
conn = new Connection("mapi:monetdb://foo.com/test");
|
37
|
-
assert.strictEqual(conn.mapi.host, "foo.com");
|
38
|
-
assert.strictEqual(conn.mapi.port, 50000);
|
39
|
-
assert.strictEqual(conn.mapi.username, "monetdb");
|
40
|
-
assert.strictEqual(conn.mapi.password, "monetdb");
|
41
|
-
assert.strictEqual(conn.mapi.database, "test");
|
42
|
-
});
|
43
|
-
});
|
package/test/exec-queries.ts
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
import assert from "assert";
|
2
|
-
import Connection from "../src/connection";
|
3
|
-
|
4
|
-
describe("Exec queres", function () {
|
5
|
-
let conn: Connection;
|
6
|
-
beforeEach(function () {
|
7
|
-
conn = new Connection({ database: "test" });
|
8
|
-
});
|
9
|
-
|
10
|
-
afterEach(async function () {
|
11
|
-
const closed = await conn.close();
|
12
|
-
assert(closed);
|
13
|
-
});
|
14
|
-
|
15
|
-
it("should handle single select query", async function () {
|
16
|
-
const ready = await conn.connect();
|
17
|
-
assert(ready, new Error("failed to connect"));
|
18
|
-
const res = await conn.execute("select * from generate_series(1, 10)");
|
19
|
-
assert.equal(res.rowCnt, 9);
|
20
|
-
assert.equal(res.data.length, 9);
|
21
|
-
});
|
22
|
-
|
23
|
-
it("should handle many queres", async function () {
|
24
|
-
const ready = await conn.connect();
|
25
|
-
assert(ready, new Error("failed to connect"));
|
26
|
-
const [res1, res2, res3] = await Promise.all([
|
27
|
-
conn.execute("select * from generate_series(1, 11)"),
|
28
|
-
conn.execute("select * from generate_series(11, 21)"),
|
29
|
-
conn.execute("select * from generate_series(21, 31)"),
|
30
|
-
]);
|
31
|
-
assert.deepStrictEqual(res1.data, [
|
32
|
-
[1],
|
33
|
-
[2],
|
34
|
-
[3],
|
35
|
-
[4],
|
36
|
-
[5],
|
37
|
-
[6],
|
38
|
-
[7],
|
39
|
-
[8],
|
40
|
-
[9],
|
41
|
-
[10],
|
42
|
-
]);
|
43
|
-
assert.deepStrictEqual(res2.data, [
|
44
|
-
[11],
|
45
|
-
[12],
|
46
|
-
[13],
|
47
|
-
[14],
|
48
|
-
[15],
|
49
|
-
[16],
|
50
|
-
[17],
|
51
|
-
[18],
|
52
|
-
[19],
|
53
|
-
[20],
|
54
|
-
]);
|
55
|
-
assert.deepStrictEqual(res3.data, [
|
56
|
-
[21],
|
57
|
-
[22],
|
58
|
-
[23],
|
59
|
-
[24],
|
60
|
-
[25],
|
61
|
-
[26],
|
62
|
-
[27],
|
63
|
-
[28],
|
64
|
-
[29],
|
65
|
-
[30],
|
66
|
-
]);
|
67
|
-
});
|
68
|
-
|
69
|
-
it("should handle insert statements", async function () {
|
70
|
-
const ready = await conn.connect();
|
71
|
-
assert(ready, new Error("failed to connect"));
|
72
|
-
let res = await conn.execute("create schema test");
|
73
|
-
res = await conn.execute("create table foo(a string)");
|
74
|
-
res = await conn.execute("insert into foo values ('foo'), ('bar')");
|
75
|
-
res = await conn.execute("select * from foo");
|
76
|
-
assert.deepStrictEqual(res.data, [["foo"], ["bar"]]);
|
77
|
-
});
|
78
|
-
|
79
|
-
it("should rollback", async function () {
|
80
|
-
const ready = await conn.connect();
|
81
|
-
assert(ready, new Error("failed to connect"));
|
82
|
-
let res = await conn.execute("create table foo(a string)");
|
83
|
-
res = await conn.execute("select name from tables where name='foo'");
|
84
|
-
assert.strictEqual(res.rowCnt, 1);
|
85
|
-
res = await conn.rollback();
|
86
|
-
res = await conn.execute("select name from tables where name='foo'");
|
87
|
-
assert.strictEqual(res.rowCnt, 0);
|
88
|
-
});
|
89
|
-
|
90
|
-
it("should handle 2 byte characters exceeding mapi block", async () => {
|
91
|
-
let s = "éééééééééééééééééééééééééééé";
|
92
|
-
let string = "";
|
93
|
-
for (let i = 0; i < 1000; i++) string += s;
|
94
|
-
const qry = `select \'${string}\'`;
|
95
|
-
const ready = await conn.connect();
|
96
|
-
assert(ready, new Error("failed to connect"));
|
97
|
-
const res = await conn.execute(qry);
|
98
|
-
assert.strictEqual(res.rowCnt, 1);
|
99
|
-
});
|
100
|
-
});
|
package/test/filetransfer.ts
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
import assert from 'assert';
|
2
|
-
import Connection from '../src/connection';
|
3
|
-
import fs from 'node:fs/promises';
|
4
|
-
|
5
|
-
describe('File Transfer', function() {
|
6
|
-
let conn: Connection;
|
7
|
-
let fooFile = 'test/tmp/foo'
|
8
|
-
beforeEach(function() {
|
9
|
-
conn = new Connection({database: 'test'});
|
10
|
-
});
|
11
|
-
|
12
|
-
afterEach(async function() {
|
13
|
-
const closed = await conn.close();
|
14
|
-
assert(closed);
|
15
|
-
});
|
16
|
-
|
17
|
-
it('should upload binary file', async function() {
|
18
|
-
const ready = await conn.connect();
|
19
|
-
assert(ready, new Error('failed to connect'));
|
20
|
-
await conn.execute('create table foo(i int)');
|
21
|
-
const f = await fs.open(fooFile, 'w');
|
22
|
-
const buff = Buffer.alloc(12);
|
23
|
-
buff.writeInt32LE(1, 0);
|
24
|
-
buff.writeInt32LE(2, 4);
|
25
|
-
buff.writeInt32LE(3, 8);
|
26
|
-
f.write(buff);
|
27
|
-
await f.close();
|
28
|
-
let res = await conn.execute(`copy binary into foo from \'${fooFile}\' on client`);
|
29
|
-
res = await conn.execute('select * from foo');
|
30
|
-
assert.deepStrictEqual(res.data, [[1], [2], [3]]);
|
31
|
-
});
|
32
|
-
|
33
|
-
it('should upload text file', async function() {
|
34
|
-
const ready = await conn.connect();
|
35
|
-
assert(ready, new Error('failed to connect'));
|
36
|
-
await conn.execute('create table foo(i int, a varchar(10))');
|
37
|
-
const f = await fs.open(fooFile, 'w');
|
38
|
-
for (let word of ['1|one', '2|two', '3|three']) {
|
39
|
-
f.write(word + '\n');
|
40
|
-
}
|
41
|
-
await f.close();
|
42
|
-
let res = await conn.execute(`copy into foo from \'${fooFile}\' on client`);
|
43
|
-
res = await conn.execute('select * from foo order by i');
|
44
|
-
assert.deepStrictEqual(res.data, [[1, 'one'], [2, 'two'], [3, 'three']]);
|
45
|
-
});
|
46
|
-
|
47
|
-
it('should cancel upload on fewer rows', async function() {
|
48
|
-
const ready = await conn.connect();
|
49
|
-
assert(ready, new Error('failed to connect'));
|
50
|
-
await conn.execute('create table foo(i int, a varchar(10))');
|
51
|
-
const f = await fs.open(fooFile, 'w');
|
52
|
-
for (let word of ['1|one', '2|two', '3|three', '4|four', '5|five', '6|six']) {
|
53
|
-
f.write(word + '\n');
|
54
|
-
}
|
55
|
-
await f.close();
|
56
|
-
let res = await conn.execute(`copy 3 records into foo from \'${fooFile}\' on client`);
|
57
|
-
res = await conn.execute('select * from foo order by i');
|
58
|
-
assert.deepStrictEqual(res.rowCnt, 3);
|
59
|
-
// TODO for some reason fails on MacOSX
|
60
|
-
//assert.deepStrictEqual(res.data, [[1, 'one'], [2, 'two'], [3, 'three']]);
|
61
|
-
});
|
62
|
-
|
63
|
-
it('should upload text file skip 2', async function() {
|
64
|
-
const ready = await conn.connect();
|
65
|
-
assert(ready, new Error('failed to connect'));
|
66
|
-
await conn.execute('create table foo(i int, a varchar(10))');
|
67
|
-
const f = await fs.open(fooFile, 'w');
|
68
|
-
for (let word of ['1|one', '2|two', '3|three', '4|four', '5|five', '6|six']) {
|
69
|
-
f.write(word + '\n');
|
70
|
-
}
|
71
|
-
await f.close();
|
72
|
-
let res = await conn.execute(`copy offset 3 into foo from \'${fooFile}\' on client`);
|
73
|
-
res = await conn.execute('select * from foo order by i');
|
74
|
-
assert.deepStrictEqual(res.rowCnt, 4);
|
75
|
-
// TODO for some reason fails on MacOSX
|
76
|
-
//assert.deepStrictEqual(res.data, [[3, "three"], [4, "four"], [5, "five"], [6, "six"]]);
|
77
|
-
});
|
78
|
-
|
79
|
-
|
80
|
-
it('should download text file', async function() {
|
81
|
-
const ready = await conn.connect();
|
82
|
-
assert(ready, new Error('failed to connect'));
|
83
|
-
let res = await conn.execute('copy (select * from sys.generate_series(1,1001)) into \'test/tmp/foo\' on client');
|
84
|
-
assert.strictEqual(res.affectedRows, 1000);
|
85
|
-
});
|
86
|
-
|
87
|
-
it('should fail on forbidden path', async function() {
|
88
|
-
const ready = await conn.connect();
|
89
|
-
assert(ready, new Error('failed to connect'));
|
90
|
-
await conn.execute('create table foo(i varchar(10))');
|
91
|
-
await assert.rejects(conn.execute(`copy into foo from \'../../foo\' on client`), Error);
|
92
|
-
});
|
93
|
-
|
94
|
-
});
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import assert from 'assert';
|
2
|
-
import Connection from '../src/connection';
|
3
|
-
|
4
|
-
describe('Prepare Statement', function() {
|
5
|
-
let conn: Connection;
|
6
|
-
beforeEach(function() {
|
7
|
-
conn = new Connection({database: 'test'});
|
8
|
-
});
|
9
|
-
|
10
|
-
afterEach(async function(){
|
11
|
-
const closed = await conn.close();
|
12
|
-
assert(closed);
|
13
|
-
});
|
14
|
-
|
15
|
-
it("should prepare inserts", async function() {
|
16
|
-
const ready = await conn.connect();
|
17
|
-
assert(ready, new Error('failed to connect'));
|
18
|
-
let res = await conn.execute('create table foo(a int, b boolean, c string, d date, f decimal)');
|
19
|
-
const prepStmt = await conn.prepare('insert into foo values (?, ?, ?, ?, ?)');
|
20
|
-
res = await prepStmt.execute(1, true, 'first', '2022-12-12', 1.11);
|
21
|
-
res = await prepStmt.execute(2, false, 'second', '2022-12-12', 2.22);
|
22
|
-
res = await prepStmt.execute(3, true, 'third', '2022-12-12', 3.33);
|
23
|
-
await prepStmt.release();
|
24
|
-
res = await conn.execute('select count(*) from foo');
|
25
|
-
assert.strictEqual(res.data[0][0], 3);
|
26
|
-
});
|
27
|
-
});
|
package/test/query-stream.ts
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
import assert from 'assert';
|
2
|
-
import Connection from '../src/connection';
|
3
|
-
|
4
|
-
describe('Query Stream', function() {
|
5
|
-
let conn: Connection;
|
6
|
-
beforeEach(function() {
|
7
|
-
conn = new Connection({database: 'test'});
|
8
|
-
});
|
9
|
-
|
10
|
-
afterEach(async function(){
|
11
|
-
const closed = await conn.close();
|
12
|
-
assert(closed);
|
13
|
-
});
|
14
|
-
|
15
|
-
it('should stream response', async function() {
|
16
|
-
const ready = await conn.connect();
|
17
|
-
assert(ready, new Error('failed to connect'));
|
18
|
-
const stream = await conn.execute('select * from generate_series(1, 10000)', true);
|
19
|
-
const colInfo = [];
|
20
|
-
const data = [];
|
21
|
-
return new Promise((resolve, reject) => {
|
22
|
-
stream.on('header', (cols: any[]) => {
|
23
|
-
for (let col of cols)
|
24
|
-
colInfo.push(col);
|
25
|
-
});
|
26
|
-
stream.on('data', (tuples: any[]) => {
|
27
|
-
for (let t of tuples) {
|
28
|
-
data.push(t);
|
29
|
-
}
|
30
|
-
});
|
31
|
-
stream.on('error', (err: Error) => {
|
32
|
-
reject(err);
|
33
|
-
})
|
34
|
-
stream.on('end', () => {
|
35
|
-
assert.strictEqual(colInfo.length, 1);
|
36
|
-
assert.strictEqual(data.length, 9999);
|
37
|
-
resolve();
|
38
|
-
});
|
39
|
-
})
|
40
|
-
});
|
41
|
-
});
|
package/test/tmp/.gitignore
DELETED
package/tsconfig.json
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"module": "commonjs",
|
4
|
-
"esModuleInterop": true,
|
5
|
-
"allowSyntheticDefaultImports": true,
|
6
|
-
"strict": false,
|
7
|
-
"target": "es6",
|
8
|
-
"noImplicitAny": false,
|
9
|
-
"moduleResolution": "node",
|
10
|
-
"sourceMap": true,
|
11
|
-
"pretty": true,
|
12
|
-
"outDir": "dist",
|
13
|
-
"incremental": true,
|
14
|
-
"baseUrl": ".",
|
15
|
-
"declaration": true,
|
16
|
-
"types": [
|
17
|
-
"node",
|
18
|
-
"mocha"
|
19
|
-
]
|
20
|
-
},
|
21
|
-
"include": [
|
22
|
-
"src/**/*.ts"
|
23
|
-
]
|
24
|
-
}
|