@sqliteai/sqlite-wasm 3.49.2-sync.0.8.29-vector.0.9.21

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/LICENSE.md ADDED
@@ -0,0 +1,52 @@
1
+ Elastic License 2.0 (modified for open-source use)
2
+
3
+ Copyright Β© 2025 SQLite Cloud, Inc.
4
+
5
+ This software is licensed under the Elastic License 2.0, with the additional
6
+ grant described below.
7
+
8
+ You may not use this file except in compliance with the Elastic License 2.0 and
9
+ the conditions outlined here.
10
+
11
+ You may obtain a copy of the Elastic License 2.0 at:
12
+
13
+ ```
14
+ https://www.elastic.co/licensing/elastic-license
15
+ ```
16
+
17
+ Software distributed under the Elastic License is distributed on an "AS IS"
18
+ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+
20
+ See the Elastic License 2.0 for the specific language governing permissions and
21
+ limitations under the license.
22
+
23
+ ---
24
+
25
+ ## Additional Grant for Open-Source Projects
26
+
27
+ In addition to the permissions granted under the Elastic License 2.0:
28
+
29
+ - **Free Use in Open-Source Projects**: You may use, copy, distribute, and
30
+ prepare derivative works of the software β€” in source or object form, with or
31
+ without modification β€” freely and without fee, provided the software is
32
+ incorporated into or used by an **open-source project** licensed under an
33
+ OSI-approved open-source license.
34
+
35
+ ---
36
+
37
+ ## Conditions
38
+
39
+ 1. For **open-source projects**, the software may be used, copied, modified, and
40
+ distributed without restriction or fee.
41
+
42
+ 2. For **non–open-source or commercial production use**, you may use, copy,
43
+ distribute, and prepare derivative works of the software only with a
44
+ commercial license from SQLite Cloud, Inc.
45
+
46
+ 3. You may not provide the software to third parties as a managed service, such
47
+ as a hosted or cloud-based service, unless you have a license for that use.
48
+
49
+ 4. The software may not be used to circumvent the license grant limitations.
50
+
51
+ 5. Any permitted use is subject to compliance with the Elastic License 2.0, this
52
+ additional grant, and applicable law.
package/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # SQLite WASM
2
+
3
+ SQLite WASM conveniently wrapped as an ES Module. It includes the
4
+ [sqlite-sync](https://github.com/sqliteai/sqlite-sync) and
5
+ [sqlite-vector](https://github.com/sqliteai/sqlite-vector) extensions that are
6
+ automatically loaded at runtime. TypeScript types are from the
7
+ [official sqlite-wasm repository](https://github.com/sqlite/sqlite-wasm).
8
+
9
+ ## Features
10
+
11
+ - πŸš€ SQLite WASM wrapped as an ES Module
12
+ - πŸ”„ Includes sqlite-sync and sqlite-vector extensions
13
+ - πŸ“ Full TypeScript support
14
+ - πŸ’Ύ OPFS (Origin Private File System) support for persistent storage
15
+ - ⚑ Worker thread support for better performance
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @sqliteai/sqlite-wasm
21
+ ```
22
+
23
+ ## Vite Configuration
24
+
25
+ If you are using [Vite](https://vitejs.dev/), you need to add the following
26
+ configuration options to your `vite.config.js`:
27
+
28
+ ```js
29
+ import { defineConfig } from 'vite';
30
+
31
+ export default defineConfig({
32
+ server: {
33
+ headers: {
34
+ 'Cross-Origin-Opener-Policy': 'same-origin',
35
+ 'Cross-Origin-Embedder-Policy': 'require-corp',
36
+ },
37
+ },
38
+ optimizeDeps: {
39
+ exclude: ['@sqliteai/sqlite-wasm'],
40
+ },
41
+ });
42
+ ```
43
+
44
+ πŸ’‘ **Example**: Check out the
45
+ [sport-tracker-app example](https://github.com/sqliteai/sqlite-sync/tree/main/examples/sport-tracker-app)
46
+ to see SQLite WASM in action with a worker thread implementation.
47
+
48
+ ## Usage
49
+
50
+ There are three ways to use SQLite WASM:
51
+
52
+ 1. **[Wrapped Worker](#wrapped-worker-with-opfs-support)** - Uses a wrapped
53
+ worker (recommended)
54
+ 2. **[Direct Worker](#direct-worker-with-opfs-support)** - Uses a direct worker
55
+ implementation
56
+ 3. **[Main Thread](#main-thread-without-opfs)** - Runs in the main thread ⚠️
57
+ _sqlite-sync does not work in the main thread_
58
+
59
+ > πŸ’‘ **Note**: Only the worker versions support the Origin Private File System
60
+ > (OPFS) storage backend for persistent data storage.
61
+
62
+ ### Wrapped Worker (with OPFS Support)
63
+
64
+ > [!Warning]
65
+ >
66
+ > For this to work, you need to set the following headers on your server:
67
+ >
68
+ > `Cross-Origin-Opener-Policy: same-origin`
69
+ >
70
+ > `Cross-Origin-Embedder-Policy: require-corp`
71
+
72
+ ```js
73
+ import { sqlite3Worker1Promiser } from '@sqliteai/sqlite-wasm';
74
+
75
+ const log = console.log;
76
+ const error = console.error;
77
+
78
+ const initializeSQLite = async () => {
79
+ try {
80
+ log('Loading and initializing SQLite3 module...');
81
+
82
+ const promiser = await new Promise((resolve) => {
83
+ const _promiser = sqlite3Worker1Promiser({
84
+ onready: () => resolve(_promiser),
85
+ });
86
+ });
87
+
88
+ log('Done initializing. Running demo...');
89
+
90
+ const configResponse = await promiser('config-get', {});
91
+ log('Running SQLite3 version', configResponse.result.version.libVersion);
92
+
93
+ const openResponse = await promiser('open', {
94
+ filename: 'file:mydb.sqlite3?vfs=opfs',
95
+ });
96
+ const { dbId } = openResponse;
97
+ log(
98
+ 'OPFS is available, created persisted database at',
99
+ openResponse.result.filename.replace(/^file:(.*?)\?vfs=opfs$/, '$1'),
100
+ );
101
+ // Your SQLite code here.
102
+ } catch (err) {
103
+ if (!(err instanceof Error)) {
104
+ err = new Error(err.result.message);
105
+ }
106
+ error(err.name, err.message);
107
+ }
108
+ };
109
+
110
+ initializeSQLite();
111
+ ```
112
+
113
+ > πŸ“š **API Reference**: The `promiser` object implements the
114
+ > [Worker1 API](https://sqlite.org/wasm/doc/trunk/api-worker1.md#worker1-methods).
115
+
116
+ ### Direct Worker (with OPFS Support)
117
+
118
+ > [!Warning]
119
+ >
120
+ > For this to work, you need to set the following headers on your server:
121
+ >
122
+ > `Cross-Origin-Opener-Policy: same-origin`
123
+ >
124
+ > `Cross-Origin-Embedder-Policy: require-corp`
125
+
126
+ **Main thread (`main.js`):**
127
+
128
+ ```js
129
+ const worker = new Worker('worker.js', { type: 'module' });
130
+ ```
131
+
132
+ **Worker thread (`worker.js`):**
133
+
134
+ ```js
135
+ import sqlite3InitModule from '@sqliteai/sqlite-wasm';
136
+
137
+ const log = console.log;
138
+ const error = console.error;
139
+
140
+ const start = (sqlite3) => {
141
+ log('Running SQLite3 version', sqlite3.version.libVersion);
142
+ const db =
143
+ 'opfs' in sqlite3
144
+ ? new sqlite3.oo1.OpfsDb('/mydb.sqlite3')
145
+ : new sqlite3.oo1.DB('/mydb.sqlite3', 'ct');
146
+ log(
147
+ 'opfs' in sqlite3
148
+ ? `OPFS is available, created persisted database at ${db.filename}`
149
+ : `OPFS is not available, created transient database ${db.filename}`,
150
+ );
151
+ // Your SQLite code here.
152
+ };
153
+
154
+ const initializeSQLite = async () => {
155
+ try {
156
+ log('Loading and initializing SQLite3 module...');
157
+ const sqlite3 = await sqlite3InitModule({ print: log, printErr: error });
158
+ log('Done initializing. Running demo...');
159
+ start(sqlite3);
160
+ } catch (err) {
161
+ error('Initialization error:', err.name, err.message);
162
+ }
163
+ };
164
+
165
+ initializeSQLite();
166
+ ```
167
+
168
+ > πŸ“š **API Reference**: The `db` object implements the
169
+ > [Object Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md).
170
+
171
+ ### Main Thread (without OPFS)
172
+
173
+ ```js
174
+ import sqlite3InitModule from '@sqliteai/sqlite-wasm';
175
+
176
+ const log = console.log;
177
+ const error = console.error;
178
+
179
+ const start = (sqlite3) => {
180
+ log('Running SQLite3 version', sqlite3.version.libVersion);
181
+ const db = new sqlite3.oo1.DB('/mydb.sqlite3', 'ct');
182
+ // Your SQLite code here.
183
+ };
184
+
185
+ const initializeSQLite = async () => {
186
+ try {
187
+ log('Loading and initializing SQLite3 module...');
188
+ const sqlite3 = await sqlite3InitModule({
189
+ print: log,
190
+ printErr: error,
191
+ });
192
+ log('Done initializing. Running demo...');
193
+ start(sqlite3);
194
+ } catch (err) {
195
+ error('Initialization error:', err.name, err.message);
196
+ }
197
+ };
198
+
199
+ initializeSQLite();
200
+ ```
201
+
202
+ > πŸ“š **API Reference**: The `db` object implements the
203
+ > [Object Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md).
204
+
205
+ ## Resources
206
+
207
+ - πŸ“– [SQLite WASM Documentation](https://sqlite.org/wasm)
208
+ - πŸ”§ [Worker1 API Reference](https://sqlite.org/wasm/doc/trunk/api-worker1.md)
209
+ - πŸ› οΈ [Object Oriented API #1](https://sqlite.org/wasm/doc/trunk/api-oo1.md)
210
+ - πŸ“¦ [Package on NPM](https://www.npmjs.com/package/@sqliteai/sqlite-wasm)
211
+
212
+ ## License
213
+
214
+ This project is licensed under the [Elastic License 2.0](./LICENSE.md). You can
215
+ use, copy, modify, and distribute it under the terms of the license for
216
+ non-production use. For production or managed service use, please
217
+ [contact SQLite Cloud, Inc](mailto:info@sqlitecloud.io) for a commercial
218
+ license.