web-sqlite-js 0.0.5 → 0.0.7

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 (3) hide show
  1. package/README.md +38 -11
  2. package/dist/index.js +85 -12452
  3. package/package.json +4 -3
package/README.md CHANGED
@@ -6,6 +6,13 @@
6
6
 
7
7
  Designed to be truly effortless, it allows you to get a high-performance relational database running in the browser in seconds. Just install, set your HTTP headers, and start querying—no complex infrastructure required.
8
8
 
9
+ ## Table of contents
10
+
11
+ - [Quick start](#quick-start)
12
+ - [Setup HTTP headers](#setup-http-headers)
13
+ - [Usage](#usage)
14
+ - [Transactions](#transactions)
15
+
9
16
  ## Features
10
17
 
11
18
  - **Persistent Storage**: Uses OPFS for high-performance, persistent file storage.
@@ -14,15 +21,42 @@ Designed to be truly effortless, it allows you to get a high-performance relatio
14
21
  - **Type-Safe**: Written in TypeScript with full type definitions.
15
22
  - **Transactions**: Supports atomic transactions with automatic rollback on error.
16
23
 
17
- ## Installation
24
+ ## Quick start
25
+
26
+ Pick the path that fits your setup:
27
+
28
+ #### Option A: npm / bundler
18
29
 
19
30
  ```bash
31
+ # npm
20
32
  npm install web-sqlite-js
21
33
  ```
22
34
 
35
+ ```typescript
36
+ import openDB from "web-sqlite-js";
37
+ // ...
38
+ ```
39
+
40
+ #### Option B: CDN / script tag (no build step)
41
+
42
+ For quick demos or plain HTML pages you can load the prebuilt module directly:
43
+
44
+ ```html
45
+ <script type="module">
46
+ import openDB from "https://cdn.jsdelivr.net/npm/web-sqlite-js@0.0.7/dist/index.js";
47
+ // ...
48
+ </script>
49
+ ```
50
+
51
+ See [samples/cdn.html](https://web-sqlite-js.wuchuheng.com/examples/cdn.html) for a copy/paste page you can serve .
52
+
53
+ > Heads up: `SharedArrayBuffer` requires COOP/COEP headers; see the section below.
54
+
23
55
  ## Setup http headers
24
56
 
25
- This library high-performance dependencies `SharedArrayBuffer`, which requires your server to send the following HTTP headers:
57
+ Pick your stack below to set the headers:
58
+
59
+ This library depends on `SharedArrayBuffer` for high performance, which requires your server to send the following HTTP headers:
26
60
 
27
61
  ```http
28
62
  Cross-Origin-Opener-Policy: same-origin
@@ -156,10 +190,8 @@ If you are using an older webpack-based setup (like CRA `react-scripts`), you te
156
190
  #### Basic Usage
157
191
 
158
192
  ```typescript
159
- import openDB from "web-sqlite-js";
160
-
161
193
  // 1. Open the database (creates 'my-database.sqlite3' in OPFS)
162
- const db = await openDB("my-database");
194
+ const db = await openDB("local.sqlite3");
163
195
 
164
196
  // 2. Initialize schema
165
197
  await db.exec(`
@@ -181,13 +213,8 @@ await db.exec("INSERT INTO users (name, email) VALUES ($name, $email)", {
181
213
  });
182
214
 
183
215
  // 4. Query data
184
- interface User {
185
- id: number;
186
- name: string;
187
- email: string;
188
- }
189
216
 
190
- const users = await db.query<User>("SELECT * FROM users");
217
+ const users = await db.query("SELECT * FROM users");
191
218
  console.log(users);
192
219
  // Output: [{ id: 1, name: 'Alice', ... }, { id: 2, name: 'Bob', ... }]
193
220