@petradb/client 1.0.1 → 1.2.0
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 +14 -58
- package/main.js +79786 -0
- package/package.json +11 -15
- package/dist/index.d.ts +0 -25
- package/dist/index.js +0 -51
package/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# @petradb/client
|
|
2
|
+
|
|
3
|
+
Network client for connecting to a PetraDB server from JavaScript and TypeScript. Works in both Node.js and the browser.
|
|
2
4
|
|
|
3
5
|
## Installation
|
|
4
6
|
|
|
@@ -11,70 +13,24 @@ npm install @petradb/client
|
|
|
11
13
|
```javascript
|
|
12
14
|
import { Session } from '@petradb/client';
|
|
13
15
|
|
|
14
|
-
const db = new Session({ host: 'localhost', port:
|
|
15
|
-
|
|
16
|
-
await db.execute(`
|
|
17
|
-
CREATE TABLE users (
|
|
18
|
-
id SERIAL,
|
|
19
|
-
name TEXT NOT NULL,
|
|
20
|
-
email TEXT,
|
|
21
|
-
PRIMARY KEY (id)
|
|
22
|
-
)
|
|
23
|
-
`);
|
|
24
|
-
|
|
25
|
-
await db.execute("INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')");
|
|
26
|
-
|
|
27
|
-
const [{ rows }] = await db.execute('SELECT * FROM users');
|
|
28
|
-
console.log(rows);
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Swapping Embedded and Network
|
|
16
|
+
const db = new Session({ host: 'localhost', port: 5480 });
|
|
32
17
|
|
|
33
|
-
|
|
18
|
+
await db.connect();
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
const results = await db.execute(`
|
|
21
|
+
CREATE TABLE users (id SERIAL, name TEXT);
|
|
22
|
+
INSERT INTO users (name) VALUES ('Alice');
|
|
23
|
+
SELECT * FROM users;
|
|
24
|
+
`);
|
|
39
25
|
|
|
40
|
-
|
|
41
|
-
import { Session } from '@petradb/client';
|
|
42
|
-
const db = new Session({ host: 'localhost', port: 5432 });
|
|
26
|
+
console.log(results);
|
|
43
27
|
|
|
44
|
-
|
|
45
|
-
await db.execute('CREATE TABLE ...');
|
|
46
|
-
const [{ rows }] = await db.execute('SELECT * FROM ...');
|
|
28
|
+
await db.close();
|
|
47
29
|
```
|
|
48
30
|
|
|
49
|
-
##
|
|
50
|
-
|
|
51
|
-
### `new Session(options?)`
|
|
52
|
-
|
|
53
|
-
| Option | Type | Default | Description |
|
|
54
|
-
|--------|------|---------|-------------|
|
|
55
|
-
| `host` | `string` | `'localhost'` | Server hostname |
|
|
56
|
-
| `port` | `number` | `5432` | Server port |
|
|
57
|
-
| `rowMode` | `'object' \| 'array'` | `'object'` | Default row format for SELECT results |
|
|
58
|
-
|
|
59
|
-
### `db.execute(sql, options?)`
|
|
60
|
-
|
|
61
|
-
Sends SQL to the server. Returns a promise that resolves to an array of results.
|
|
62
|
-
|
|
63
|
-
| Option | Type | Default | Description |
|
|
64
|
-
|--------|------|---------|-------------|
|
|
65
|
-
| `rowMode` | `'object' \| 'array'` | constructor default | Row format for this call |
|
|
66
|
-
|
|
67
|
-
### `db.connect()`
|
|
68
|
-
|
|
69
|
-
Creates a server-side session. The session ID is sent automatically with subsequent `execute()` calls via the `X-Session-Id` header.
|
|
70
|
-
|
|
71
|
-
### `db.close()`
|
|
72
|
-
|
|
73
|
-
Closes the server-side session.
|
|
74
|
-
|
|
75
|
-
## No Dependencies
|
|
31
|
+
## Documentation
|
|
76
32
|
|
|
77
|
-
|
|
33
|
+
Full documentation at **[petradb.dev](https://petradb.dev)**.
|
|
78
34
|
|
|
79
35
|
## License
|
|
80
36
|
|