@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 CHANGED
@@ -1,4 +1,6 @@
1
- Network client for [petradb-server](https://github.com/edadma/petradb) with the same `Session` API as `@petradb/engine`.
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: 5432 });
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
- Both `@petradb/engine` and `@petradb/client` export `Session` with the same `async execute()` API. Switch between them with a one-line import change:
18
+ await db.connect();
34
19
 
35
- ```javascript
36
- // Embedded (in-process, no server needed)
37
- import { Session } from '@petradb/engine';
38
- const db = new Session();
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
- // Network (talks to petradb-server over HTTP)
41
- import { Session } from '@petradb/client';
42
- const db = new Session({ host: 'localhost', port: 5432 });
26
+ console.log(results);
43
27
 
44
- // Everything below works identically
45
- await db.execute('CREATE TABLE ...');
46
- const [{ rows }] = await db.execute('SELECT * FROM ...');
28
+ await db.close();
47
29
  ```
48
30
 
49
- ## API
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
- Uses the native `fetch` API (Node.js 18+, all modern browsers).
33
+ Full documentation at **[petradb.dev](https://petradb.dev)**.
78
34
 
79
35
  ## License
80
36