@capgo/capacitor-fast-sql 8.0.42 → 8.0.44
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,305 +1,319 @@
|
|
|
1
|
-
# @capgo/capacitor-fast-sql
|
|
2
|
-
<a href="https://capgo.app/"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-fast-sql" alt="Capgo - Instant updates for Capacitor" /></a>
|
|
3
|
-
|
|
4
|
-
<div align="center">
|
|
5
|
-
<h2><a href="https://capgo.app/?ref=plugin_fast_sql"> ➡️ Get Instant updates for your App with Capgo</a></h2>
|
|
6
|
-
<h2><a href="https://capgo.app/consulting/?ref=plugin_fast_sql"> Missing a feature? We'll build the plugin for you 💪</a></h2>
|
|
7
|
-
</div>
|
|
8
|
-
|
|
9
|
-
High-performance native SQLite plugin with HTTP server for efficient sync operations and IndexedDB replacement.
|
|
10
|
-
Official Capgo alternative to Ionic Appflow Secure Storage.
|
|
11
|
-
|
|
12
|
-
## Why Fast SQL?
|
|
13
|
-
|
|
14
|
-
Traditional Capacitor plugins serialize data through the JavaScript bridge, which becomes inefficient with large datasets. Fast SQL solves this by establishing a local HTTP server for direct native communication, making it ideal for:
|
|
15
|
-
|
|
16
|
-
- **Local-first sync systems** (CRDTs, operational transforms)
|
|
17
|
-
- **IndexedDB replacement** on platforms with broken/limited implementations
|
|
18
|
-
- **Large dataset operations** requiring high throughput
|
|
19
|
-
- **Batch operations** with thousands of rows
|
|
20
|
-
- **Binary data storage** (BLOBs, files)
|
|
21
|
-
|
|
22
|
-
## Documentation
|
|
23
|
-
|
|
24
|
-
The most complete doc is available here: https://capgo.app/docs/plugins/fast-sql/
|
|
25
|
-
|
|
26
|
-
## Compatibility
|
|
27
|
-
|
|
28
|
-
| Plugin version | Capacitor compatibility | Maintained |
|
|
29
|
-
| -------------- | ----------------------- | ---------- |
|
|
30
|
-
| v8.\*.\* | v8.\*.\* | ✅ |
|
|
31
|
-
| v7.\*.\* | v7.\*.\* | On demand |
|
|
32
|
-
| v6.\*.\* | v6.\*.\* | ❌ |
|
|
33
|
-
| v5.\*.\* | v5.\*.\* | ❌ |
|
|
34
|
-
|
|
35
|
-
> **Note:** The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.
|
|
36
|
-
|
|
37
|
-
## Install
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
##
|
|
72
|
-
|
|
73
|
-
This plugin runs a local HTTP server on `localhost
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
`
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
1
|
+
# @capgo/capacitor-fast-sql
|
|
2
|
+
<a href="https://capgo.app/"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-fast-sql" alt="Capgo - Instant updates for Capacitor" /></a>
|
|
3
|
+
|
|
4
|
+
<div align="center">
|
|
5
|
+
<h2><a href="https://capgo.app/?ref=plugin_fast_sql"> ➡️ Get Instant updates for your App with Capgo</a></h2>
|
|
6
|
+
<h2><a href="https://capgo.app/consulting/?ref=plugin_fast_sql"> Missing a feature? We'll build the plugin for you 💪</a></h2>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
High-performance native SQLite plugin with HTTP server for efficient sync operations and IndexedDB replacement.
|
|
10
|
+
Official Capgo alternative to Ionic Appflow Secure Storage.
|
|
11
|
+
|
|
12
|
+
## Why Fast SQL?
|
|
13
|
+
|
|
14
|
+
Traditional Capacitor plugins serialize data through the JavaScript bridge, which becomes inefficient with large datasets. Fast SQL solves this by establishing a local HTTP server for direct native communication, making it ideal for:
|
|
15
|
+
|
|
16
|
+
- **Local-first sync systems** (CRDTs, operational transforms)
|
|
17
|
+
- **IndexedDB replacement** on platforms with broken/limited implementations
|
|
18
|
+
- **Large dataset operations** requiring high throughput
|
|
19
|
+
- **Batch operations** with thousands of rows
|
|
20
|
+
- **Binary data storage** (BLOBs, files)
|
|
21
|
+
|
|
22
|
+
## Documentation
|
|
23
|
+
|
|
24
|
+
The most complete doc is available here: https://capgo.app/docs/plugins/fast-sql/
|
|
25
|
+
|
|
26
|
+
## Compatibility
|
|
27
|
+
|
|
28
|
+
| Plugin version | Capacitor compatibility | Maintained |
|
|
29
|
+
| -------------- | ----------------------- | ---------- |
|
|
30
|
+
| v8.\*.\* | v8.\*.\* | ✅ |
|
|
31
|
+
| v7.\*.\* | v7.\*.\* | On demand |
|
|
32
|
+
| v6.\*.\* | v6.\*.\* | ❌ |
|
|
33
|
+
| v5.\*.\* | v5.\*.\* | ❌ |
|
|
34
|
+
|
|
35
|
+
> **Note:** The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then use the following prompt:
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-fast-sql` plugin in my project.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install @capgo/capacitor-fast-sql
|
|
55
|
+
npx cap sync
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Overview
|
|
59
|
+
|
|
60
|
+
This plugin provides direct native SQLite database access with a custom communication protocol inspired by [capacitor-blob-writer](https://github.com/diachedelic/capacitor-blob-writer). Instead of using Capacitor's standard bridge (which serializes data inefficiently), it establishes a local HTTP server for optimal performance with large datasets and sync operations.
|
|
61
|
+
|
|
62
|
+
### Key Features
|
|
63
|
+
|
|
64
|
+
- **Custom HTTP Protocol**: Bypasses Capacitor's bridge for up to 25x faster performance with large data
|
|
65
|
+
- **Direct Native SQLite**: Full SQL support with transactions, batch operations, and binary data
|
|
66
|
+
- **Sync-Friendly**: Designed for local sync systems (CRDTs, operational transforms, etc.)
|
|
67
|
+
- **IndexedDB Replacement**: Provides reliable alternative to broken/limited IndexedDB implementations
|
|
68
|
+
- **Cross-Platform**: iOS, Android, and Web (using sql.js + IndexedDB for persistence)
|
|
69
|
+
- **Optional RAG VectorStore**: Persist many named vector stores for retrieval-augmented generation without adding a native dependency
|
|
70
|
+
|
|
71
|
+
## iOS Configuration
|
|
72
|
+
|
|
73
|
+
This plugin runs a local HTTP server on `localhost`. iOS App Transport Security (ATS) blocks cleartext HTTP by default, so you **must** allow local networking in your `Info.plist`:
|
|
74
|
+
|
|
75
|
+
```xml
|
|
76
|
+
<key>NSAppTransportSecurity</key>
|
|
77
|
+
<dict>
|
|
78
|
+
<key>NSAllowsLocalNetworking</key>
|
|
79
|
+
<true/>
|
|
80
|
+
</dict>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This only permits cleartext to loopback addresses (`localhost` / `127.0.0.1`) — it does not weaken ATS for external connections.
|
|
84
|
+
|
|
85
|
+
## Android Configuration
|
|
86
|
+
|
|
87
|
+
This plugin runs a local HTTP server on `localhost` to bypass Capacitor's bridge for performance. Android 9+ blocks cleartext (non-HTTPS) traffic by default, so you **must** allow it for `localhost`.
|
|
88
|
+
|
|
89
|
+
**Option A — Scoped to localhost only (recommended):**
|
|
90
|
+
|
|
91
|
+
Create `android/app/src/main/res/xml/network_security_config.xml`:
|
|
92
|
+
|
|
93
|
+
```xml
|
|
94
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
95
|
+
<network-security-config>
|
|
96
|
+
<domain-config cleartextTrafficPermitted="true">
|
|
97
|
+
<domain includeSubdomains="false">localhost</domain>
|
|
98
|
+
<domain includeSubdomains="false">127.0.0.1</domain>
|
|
99
|
+
</domain-config>
|
|
100
|
+
</network-security-config>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Then reference it in your `AndroidManifest.xml`:
|
|
104
|
+
|
|
105
|
+
```xml
|
|
106
|
+
<application
|
|
107
|
+
android:networkSecurityConfig="@xml/network_security_config">
|
|
108
|
+
...
|
|
109
|
+
</application>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Option B — Allow all cleartext (simpler but less secure):**
|
|
113
|
+
|
|
114
|
+
```xml
|
|
115
|
+
<application
|
|
116
|
+
android:usesCleartextTraffic="true">
|
|
117
|
+
...
|
|
118
|
+
</application>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Encryption
|
|
122
|
+
|
|
123
|
+
### Android
|
|
124
|
+
|
|
125
|
+
Encryption uses [SQLCipher](https://www.zetetic.net/sqlcipher/) and is opt-in. Add the SQLCipher dependency to your **app-level** `build.gradle`:
|
|
126
|
+
|
|
127
|
+
```gradle
|
|
128
|
+
dependencies {
|
|
129
|
+
implementation 'net.zetetic:sqlcipher-android:4.13.0'
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Then connect with encryption enabled:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const db = await FastSQL.connect({
|
|
137
|
+
database: 'secure',
|
|
138
|
+
encrypted: true,
|
|
139
|
+
encryptionKey: 'my-secret-key',
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
If SQLCipher is not installed and `encrypted: true` is passed, the plugin returns a clear error message instead of crashing.
|
|
144
|
+
|
|
145
|
+
### iOS
|
|
146
|
+
|
|
147
|
+
SQLCipher is optional on iOS. The plugin builds without it; encryption calls will return `Encryption is not available in this build` unless SQLCipher is installed.
|
|
148
|
+
|
|
149
|
+
To enable encryption via CocoaPods, update your `ios/App/Podfile` after `capacitor install`/`cap sync` to use the SQLCipher subspec:
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
pod 'CapgoCapacitorFastSql/SQLCipher', :path => '../../node_modules/@capgo/capacitor-fast-sql'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Then run `pod install` in the `ios/App` directory. If you skip this subspec, keep `encrypted: false`.
|
|
156
|
+
|
|
157
|
+
## Web Platform
|
|
158
|
+
|
|
159
|
+
On the web, this plugin uses [sql.js](https://sql.js.org/) (SQLite compiled to WebAssembly) with IndexedDB for persistence.
|
|
160
|
+
|
|
161
|
+
By default, the plugin loads `sql-wasm.js` and `sql-wasm.wasm` from the cdnjs CDN. If you want to bundle these files with your web application (to avoid a CDN dependency), call `configureWeb()` once at startup **before** the first `connect()`:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { CapgoCapacitorFastSql, FastSQL } from '@capgo/capacitor-fast-sql';
|
|
165
|
+
|
|
166
|
+
// Point to your locally bundled sql.js files
|
|
167
|
+
await CapgoCapacitorFastSql.configureWeb({
|
|
168
|
+
sqlJsUrl: '/assets/sql-wasm.js',
|
|
169
|
+
wasmUrl: '/assets/sql-wasm.wasm',
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const db = await FastSQL.connect({ database: 'myapp' });
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`configureWeb()` is a no-op on iOS and Android — it is safe to call unconditionally.
|
|
176
|
+
|
|
177
|
+
## Usage
|
|
178
|
+
|
|
179
|
+
### Basic Example
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { FastSQL } from '@capgo/capacitor-fast-sql';
|
|
183
|
+
|
|
184
|
+
// Connect to database
|
|
185
|
+
const db = await FastSQL.connect({ database: 'myapp' });
|
|
186
|
+
|
|
187
|
+
// Create table
|
|
188
|
+
await db.execute(`
|
|
189
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
190
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
191
|
+
name TEXT NOT NULL,
|
|
192
|
+
email TEXT UNIQUE
|
|
193
|
+
)
|
|
194
|
+
`);
|
|
195
|
+
|
|
196
|
+
// Insert data
|
|
197
|
+
const result = await db.run(
|
|
198
|
+
'INSERT INTO users (name, email) VALUES (?, ?)',
|
|
199
|
+
['John Doe', 'john@example.com']
|
|
200
|
+
);
|
|
201
|
+
console.log('Inserted row ID:', result.insertId);
|
|
202
|
+
|
|
203
|
+
// Query data
|
|
204
|
+
const users = await db.query('SELECT * FROM users WHERE name LIKE ?', ['John%']);
|
|
205
|
+
console.log('Users:', users);
|
|
206
|
+
|
|
207
|
+
// Close connection
|
|
208
|
+
await FastSQL.disconnect('myapp');
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Transaction Example
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
const db = await FastSQL.connect({ database: 'myapp' });
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
await db.transaction(async (tx) => {
|
|
218
|
+
await tx.run('INSERT INTO accounts (name, balance) VALUES (?, ?)', ['Alice', 1000]);
|
|
219
|
+
await tx.run('INSERT INTO accounts (name, balance) VALUES (?, ?)', ['Bob', 500]);
|
|
220
|
+
await tx.run('UPDATE accounts SET balance = balance - 100 WHERE name = ?', ['Alice']);
|
|
221
|
+
await tx.run('UPDATE accounts SET balance = balance + 100 WHERE name = ?', ['Bob']);
|
|
222
|
+
});
|
|
223
|
+
console.log('Transaction successful!');
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.error('Transaction failed:', error);
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Batch Operations
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
const db = await FastSQL.connect({ database: 'myapp' });
|
|
233
|
+
|
|
234
|
+
const results = await db.executeBatch([
|
|
235
|
+
{ statement: 'INSERT INTO logs (message) VALUES (?)', params: ['Log 1'] },
|
|
236
|
+
{ statement: 'INSERT INTO logs (message) VALUES (?)', params: ['Log 2'] },
|
|
237
|
+
{ statement: 'INSERT INTO logs (message) VALUES (?)', params: ['Log 3'] },
|
|
238
|
+
]);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Key-Value Storage (Mobile-focused)
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
import { KeyValueStore } from '@capgo/capacitor-fast-sql';
|
|
245
|
+
|
|
246
|
+
const kv = await KeyValueStore.open({
|
|
247
|
+
database: 'myapp',
|
|
248
|
+
encrypted: true,
|
|
249
|
+
encryptionKey: 'super-secret-key',
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
await kv.set('session', { token: 'abc123', expiresAt: 1710000000 });
|
|
253
|
+
const session = await kv.get('session');
|
|
254
|
+
await kv.remove('session');
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### RAG Vector Stores (Optional)
|
|
258
|
+
|
|
259
|
+
`FastSQLVectorStore` provides a dependency-free VectorStore-compatible helper inspired by `@react-native-rag/op-sqlite`. It stores embeddings in SQLite as binary Float32 vectors and computes cosine similarity in TypeScript, so it works anywhere this plugin works.
|
|
260
|
+
|
|
261
|
+
Each store is namespaced by the `store` option, so one database can hold as many independent vector stores as you need:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { FastSQLVectorStore } from '@capgo/capacitor-fast-sql';
|
|
265
|
+
|
|
266
|
+
const docs = await FastSQLVectorStore.open({
|
|
267
|
+
database: 'rag',
|
|
268
|
+
store: 'docs',
|
|
269
|
+
embeddings,
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const tickets = await FastSQLVectorStore.open({
|
|
273
|
+
database: 'rag',
|
|
274
|
+
store: 'tickets',
|
|
275
|
+
embeddings,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
await docs.add({
|
|
279
|
+
document: 'Capgo ships instant updates for Capacitor apps.',
|
|
280
|
+
metadata: { source: 'docs' },
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const results = await docs.query({
|
|
284
|
+
queryText: 'How do instant updates work?',
|
|
285
|
+
nResults: 3,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
await docs.close();
|
|
289
|
+
await tickets.close();
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
You can also use precomputed embeddings without an embeddings provider:
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
const store = await FastSQLVectorStore.open({
|
|
296
|
+
database: 'rag',
|
|
297
|
+
store: 'offline-embeddings',
|
|
298
|
+
embeddingDimension: 384,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
await store.add({
|
|
302
|
+
id: 'intro',
|
|
303
|
+
document: 'Local RAG entry',
|
|
304
|
+
embedding: [0.12, 0.08, 0.31 /* ...384 values */],
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const matches = await store.query({
|
|
308
|
+
queryEmbedding: [0.11, 0.09, 0.29 /* ...384 values */],
|
|
309
|
+
nResults: 5,
|
|
310
|
+
});
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
> Note: Web support is intended for minimal testing only. The primary focus is iOS/Android.
|
|
314
|
+
|
|
315
|
+
## API
|
|
316
|
+
|
|
303
317
|
<docgen-index>
|
|
304
318
|
|
|
305
319
|
* [`connect(...)`](#connect)
|
|
@@ -315,8 +329,8 @@ const matches = await store.query({
|
|
|
315
329
|
* [Type Aliases](#type-aliases)
|
|
316
330
|
* [Enums](#enums)
|
|
317
331
|
|
|
318
|
-
</docgen-index>
|
|
319
|
-
|
|
332
|
+
</docgen-index>
|
|
333
|
+
|
|
320
334
|
<docgen-api>
|
|
321
335
|
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
322
336
|
|
|
@@ -632,4 +646,4 @@ SQL value types supported by the plugin
|
|
|
632
646
|
| **`RepeatableRead`** | <code>'REPEATABLE READ'</code> |
|
|
633
647
|
| **`Serializable`** | <code>'SERIALIZABLE'</code> |
|
|
634
648
|
|
|
635
|
-
</docgen-api>
|
|
649
|
+
</docgen-api>
|
|
@@ -19,7 +19,7 @@ import java.util.Map;
|
|
|
19
19
|
@CapacitorPlugin(name = "CapgoCapacitorFastSql")
|
|
20
20
|
public class CapgoCapacitorFastSqlPlugin extends Plugin {
|
|
21
21
|
|
|
22
|
-
private final String pluginVersion = "8.0.
|
|
22
|
+
private final String pluginVersion = "8.0.44";
|
|
23
23
|
|
|
24
24
|
private Map<String, DatabaseConnection> databases = new HashMap<>();
|
|
25
25
|
private SQLHTTPServer server;
|
|
@@ -10,7 +10,7 @@ import SQLite3
|
|
|
10
10
|
*/
|
|
11
11
|
@objc(CapgoCapacitorFastSqlPlugin)
|
|
12
12
|
public class CapgoCapacitorFastSqlPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
13
|
-
private let pluginVersion: String = "8.0.
|
|
13
|
+
private let pluginVersion: String = "8.0.44"
|
|
14
14
|
public let identifier = "CapgoCapacitorFastSqlPlugin"
|
|
15
15
|
public let jsName = "CapgoCapacitorFastSql"
|
|
16
16
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-fast-sql",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.44",
|
|
4
4
|
"description": "High-performance native SQLite plugin with custom protocol for efficient sync operations and IndexedDB replacement",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|