web-sqlite-js 0.0.2-beta → 0.0.3

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 (2) hide show
  1. package/README.md +9 -47
  2. package/package.json +14 -8
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # web-sqlite-js
1
+ <h1 align="center">web-sqlite-js</h1>
2
+ <p align="center"> <img src="docs/public/web-sqlite-js.gif" width="400px" />
3
+ </p>
2
4
 
3
- Enables direct use of SQLite in the web browser with reliable local data persistence via OPFS (Origin Private File System).
5
+ `web-sqlite-js` gives web developers an out-of-the-box way to run SQLite directly in the browser and keep data persisted on the client via OPFS (Origin Private File System).
4
6
 
5
- It runs SQLite in a Web Worker to avoid blocking the main thread and handles all synchronization automatically, providing a simple, Promise-based API.
7
+ Developers only need to install and configure the http request header to use it directly, which is quite friendly.
6
8
 
7
9
  ## Features
8
10
 
@@ -18,19 +20,15 @@ It runs SQLite in a Web Worker to avoid blocking the main thread and handles all
18
20
  npm install web-sqlite-js
19
21
  ```
20
22
 
21
- ## ⚠️ Critical Configuration: COOP & COEP
23
+ ## Setup http headers
22
24
 
23
- To use `SharedArrayBuffer` (required by the SQLite WASM build), your server **must** serve the application with the following HTTP headers:
25
+ This library high-performance dependencies `SharedArrayBuffer`, which requires your server to send the following HTTP headers:
24
26
 
25
27
  ```http
26
28
  Cross-Origin-Opener-Policy: same-origin
27
29
  Cross-Origin-Embedder-Policy: require-corp
28
30
  ```
29
31
 
30
- If these headers are missing, the database **will not start**.
31
-
32
- ### Configuration Guides
33
-
34
32
  <details>
35
33
  <summary><strong>Vite</strong></summary>
36
34
 
@@ -155,7 +153,7 @@ If you are using an older webpack-based setup (like CRA `react-scripts`), you te
155
153
 
156
154
  ## Usage
157
155
 
158
- ### Basic Query
156
+ #### Basic Usage
159
157
 
160
158
  ```typescript
161
159
  import openDB from "web-sqlite-js";
@@ -197,7 +195,7 @@ console.log(users);
197
195
  await db.close();
198
196
  ```
199
197
 
200
- ### Transactions
198
+ #### Transactions
201
199
 
202
200
  Transactions are atomic. If any command inside the callback fails, the entire transaction is rolled back.
203
201
 
@@ -212,39 +210,3 @@ await db.transaction(async (tx) => {
212
210
  // throw new Error('Something went wrong');
213
211
  });
214
212
  ```
215
-
216
- ### Multiple Connections
217
-
218
- You can open multiple connections to the same file. They will automatically synchronize access.
219
-
220
- ```typescript
221
- const db1 = await openDB("shared-db");
222
- const db2 = await openDB("shared-db");
223
-
224
- await db1.exec("INSERT INTO items (name) VALUES (?)", ["Item 1"]);
225
-
226
- // db2 sees the change immediately after db1 finishes
227
- const items = await db2.query("SELECT * FROM items");
228
- ```
229
-
230
- ## API
231
-
232
- ### `openDB(filename: string, options?: { debug?: boolean })`
233
-
234
- Opens a database connection. Returns a `DBInterface`.
235
-
236
- ### `db.exec(sql: string, params?: any[] | Record<string, any>)`
237
-
238
- Executes a SQL statement (INSERT, UPDATE, DELETE, CREATE). Returns `{ changes, lastInsertRowid }`.
239
-
240
- ### `db.query<T>(sql: string, params?: any[] | Record<string, any>)`
241
-
242
- Executes a SELECT statement. Returns an array of rows `T[]`.
243
-
244
- ### `db.transaction<T>(callback: (tx: DBInterface) => Promise<T>)`
245
-
246
- Runs the callback inside a transaction (`BEGIN` ... `COMMIT`/`ROLLBACK`). The `tx` object provided to the callback has the same `exec` and `query` methods.
247
-
248
- ### `db.close()`
249
-
250
- Closes the connection and terminates the worker.
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "web-sqlite-js",
3
- "version": "0.0.2-beta",
4
- "description": "Enables direct use of SQLite in the web browser with reliable local data persistence via OPFS.",
3
+ "version": "0.0.3",
4
+ "description": "web-sqlite-js gives web developers an out-of-the-box way to run SQLite directly in the browser and keep data persisted on the client via OPFS (Origin Private File System).",
5
+ "workspaces": [
6
+ "docs"
7
+ ],
5
8
  "type": "module",
6
9
  "main": "./dist/index.js",
7
10
  "types": "./dist/index.d.ts",
@@ -25,7 +28,7 @@
25
28
  "scripts": {
26
29
  "test": "npm run build && npm run lint && npm run test:unit && npm run test:e2e ",
27
30
  "test:unit": "vitest run --config vitest.unit.config.ts --coverage",
28
- "http": "tsx scripts/http-service.ts ./ --port 8399",
31
+ "http": "tsx scripts/http-service.ts ./docs/.vitepress/dist --port 8399",
29
32
  "test:e2e": "vitest run --config vitest.e2e.config.ts",
30
33
  "test:debug": "vitest run --config vitest.e2e.config.ts --no-file-parallelism",
31
34
  "build": "vite build",
@@ -35,12 +38,15 @@
35
38
  "typecheck": "tsc --noEmit",
36
39
  "format": "prettier --ignore-path .gitignore --write .",
37
40
  "package:compress": "npm pack",
38
- "package:publish": "npm run test && npm run build && npm publish --access public"
41
+ "package:publish": "npm run test && npm run build && npm publish --access public",
42
+ "docs:dev": "npm run dev --workspace=@web-sqlite-js/docs",
43
+ "docs:build": "npm run build --workspace=@web-sqlite-js/docs",
44
+ "docs:preview": "npm run preview --workspace=@web-sqlite-js/docs",
45
+ "docs:icons": "npm run icons --workspace=@web-sqlite-js/docs",
46
+ "docs:deploy": "cd docs && ./deploy.sh"
39
47
  },
40
48
  "files": [
41
- "dist",
42
- "LICENSE",
43
- "README.md"
49
+ "dist"
44
50
  ],
45
51
  "devDependencies": {
46
52
  "@eslint/css": "^0.14.1",
@@ -73,4 +79,4 @@
73
79
  "url": "https://github.com/wuchuheng/web-sqlite-js/issues"
74
80
  },
75
81
  "homepage": "https://github.com/wuchuheng/web-sqlite-js#readme"
76
- }
82
+ }