web-sqlite-js 0.0.5 → 1.0.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 +62 -13
- package/dist/index.js +85 -12452
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<h1 align="center">web-sqlite-js</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://web-sqlite-js.wuchuheng.com" target="_blank">
|
|
5
|
+
<img src="docs/public/web-sqlite-js.gif" width="80%" style="border-radius: 10px;" />
|
|
6
|
+
</a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://github.com/wuchuheng/web-sqlite-js/actions/workflows/test.yml" target="_blank">
|
|
11
|
+
<img src="https://github.com/wuchuheng/web-sqlite-js/actions/workflows/test.yml/badge.svg" alt="Test" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/web-sqlite-js" target="_blank">
|
|
14
|
+
<img src="https://img.shields.io/npm/v/web-sqlite-js.svg" alt="NPM Version" />
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://github.com/wuchuheng/web-sqlite-js/blob/main/LICENSE" target="_blank">
|
|
17
|
+
<img src="https://img.shields.io/github/license/wuchuheng/web-sqlite-js.svg" alt="License" />
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://bundlephobia.com/package/web-sqlite-js" target="_blank">
|
|
20
|
+
<img src="https://img.shields.io/bundlephobia/minzip/web-sqlite-js.svg" alt="Bundle Size" />
|
|
21
|
+
</a>
|
|
22
|
+
<a href="https://github.com/wuchuheng/web-sqlite-js/pulls" target="_blank">
|
|
23
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome" />
|
|
24
|
+
</a>
|
|
3
25
|
</p>
|
|
4
26
|
|
|
5
27
|
`web-sqlite-js` is a friendly, out-of-the-box SQLite database for the web that makes persistent client-side storage simple for every developer.
|
|
6
28
|
|
|
7
29
|
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
30
|
|
|
31
|
+
## Table of contents
|
|
32
|
+
|
|
33
|
+
- [Quick start](#quick-start)
|
|
34
|
+
- [Setup HTTP headers](#setup-http-headers)
|
|
35
|
+
- [Usage](#usage)
|
|
36
|
+
- [Transactions](#transactions)
|
|
37
|
+
|
|
9
38
|
## Features
|
|
10
39
|
|
|
11
40
|
- **Persistent Storage**: Uses OPFS for high-performance, persistent file storage.
|
|
@@ -14,15 +43,42 @@ Designed to be truly effortless, it allows you to get a high-performance relatio
|
|
|
14
43
|
- **Type-Safe**: Written in TypeScript with full type definitions.
|
|
15
44
|
- **Transactions**: Supports atomic transactions with automatic rollback on error.
|
|
16
45
|
|
|
17
|
-
##
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
Pick the path that fits your setup:
|
|
49
|
+
|
|
50
|
+
#### Option A: npm / bundler
|
|
18
51
|
|
|
19
52
|
```bash
|
|
53
|
+
# npm
|
|
20
54
|
npm install web-sqlite-js
|
|
21
55
|
```
|
|
22
56
|
|
|
57
|
+
```typescript
|
|
58
|
+
import openDB from "web-sqlite-js";
|
|
59
|
+
// ...
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Option B: CDN / script tag (no build step)
|
|
63
|
+
|
|
64
|
+
For quick demos or plain HTML pages you can load the prebuilt module directly:
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<script type="module">
|
|
68
|
+
import openDB from "https://cdn.jsdelivr.net/npm/web-sqlite-js@1.0.0/dist/index.js";
|
|
69
|
+
// ...
|
|
70
|
+
</script>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
See [samples/cdn.html](https://web-sqlite-js.wuchuheng.com/examples/cdn.html) for a copy/paste page you can serve .
|
|
74
|
+
|
|
75
|
+
> Heads up: `SharedArrayBuffer` requires COOP/COEP headers; see the section below.
|
|
76
|
+
|
|
23
77
|
## Setup http headers
|
|
24
78
|
|
|
25
|
-
|
|
79
|
+
Pick your stack below to set the headers:
|
|
80
|
+
|
|
81
|
+
This library depends on `SharedArrayBuffer` for high performance, which requires your server to send the following HTTP headers:
|
|
26
82
|
|
|
27
83
|
```http
|
|
28
84
|
Cross-Origin-Opener-Policy: same-origin
|
|
@@ -156,10 +212,8 @@ If you are using an older webpack-based setup (like CRA `react-scripts`), you te
|
|
|
156
212
|
#### Basic Usage
|
|
157
213
|
|
|
158
214
|
```typescript
|
|
159
|
-
import openDB from "web-sqlite-js";
|
|
160
|
-
|
|
161
215
|
// 1. Open the database (creates 'my-database.sqlite3' in OPFS)
|
|
162
|
-
const db = await openDB("
|
|
216
|
+
const db = await openDB("local.sqlite3");
|
|
163
217
|
|
|
164
218
|
// 2. Initialize schema
|
|
165
219
|
await db.exec(`
|
|
@@ -181,13 +235,8 @@ await db.exec("INSERT INTO users (name, email) VALUES ($name, $email)", {
|
|
|
181
235
|
});
|
|
182
236
|
|
|
183
237
|
// 4. Query data
|
|
184
|
-
interface User {
|
|
185
|
-
id: number;
|
|
186
|
-
name: string;
|
|
187
|
-
email: string;
|
|
188
|
-
}
|
|
189
238
|
|
|
190
|
-
const users = await db.query
|
|
239
|
+
const users = await db.query("SELECT * FROM users");
|
|
191
240
|
console.log(users);
|
|
192
241
|
// Output: [{ id: 1, name: 'Alice', ... }, { id: 2, name: 'Bob', ... }]
|
|
193
242
|
|