@capawesome/capacitor-libsql 0.2.2 → 0.2.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.
- package/Package.swift +1 -5
- package/README.md +106 -1
- package/package.json +16 -10
package/Package.swift
CHANGED
|
@@ -21,10 +21,6 @@ let package = Package(
|
|
|
21
21
|
.product(name: "Cordova", package: "capacitor-swift-pm"),
|
|
22
22
|
.product(name: "Libsql", package: "libsql-swift")
|
|
23
23
|
],
|
|
24
|
-
path: "ios/Plugin")
|
|
25
|
-
.testTarget(
|
|
26
|
-
name: "LibsqlPluginTests",
|
|
27
|
-
dependencies: ["LibsqlPlugin"],
|
|
28
|
-
path: "ios/PluginTests")
|
|
24
|
+
path: "ios/Plugin")
|
|
29
25
|
]
|
|
30
26
|
)
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Capacitor libSQL Plugin
|
|
2
2
|
|
|
3
3
|
Capacitor plugin for [libSQL](https://docs.turso.tech/libsql) databases.[^1]
|
|
4
4
|
|
|
@@ -8,6 +8,15 @@ Capacitor plugin for [libSQL](https://docs.turso.tech/libsql) databases.[^1]
|
|
|
8
8
|
</a>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
+
## Use Cases
|
|
12
|
+
|
|
13
|
+
The libSQL plugin is typically used whenever an app needs a SQL database, for example:
|
|
14
|
+
|
|
15
|
+
- **Offline-first apps**: Store data in a local database file on the device and synchronize it with a remote server using the `sync(...)` method.
|
|
16
|
+
- **Remote databases**: Connect directly to a remote libSQL database, such as one hosted on Turso, using a URL and authentication token.
|
|
17
|
+
- **Structured local storage**: Create tables and insert, update, delete, and query data with SQL statements and bound values.
|
|
18
|
+
- **Atomic operations**: Group multiple statements into a transaction that can be committed or rolled back as a whole.
|
|
19
|
+
|
|
11
20
|
## Compatibility
|
|
12
21
|
|
|
13
22
|
| Plugin Version | Capacitor Version | Status |
|
|
@@ -17,6 +26,21 @@ Capacitor plugin for [libSQL](https://docs.turso.tech/libsql) databases.[^1]
|
|
|
17
26
|
|
|
18
27
|
## Installation
|
|
19
28
|
|
|
29
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
30
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then use the following prompt:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-libsql` plugin in my project.
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
43
|
+
|
|
20
44
|
```bash
|
|
21
45
|
npm install @capawesome/capacitor-libsql
|
|
22
46
|
npx cap sync
|
|
@@ -34,6 +58,12 @@ This can be useful if you encounter dependency conflicts with other plugins in y
|
|
|
34
58
|
|
|
35
59
|
## Usage
|
|
36
60
|
|
|
61
|
+
The following examples show how to connect to local and remote databases, query data, execute insert, update, and delete statements, run statements inside a transaction, and synchronize with a remote server.
|
|
62
|
+
|
|
63
|
+
### Connect to a local database
|
|
64
|
+
|
|
65
|
+
Connect to a local database file on the device. If no file exists at the specified path, a new file is created. If neither a path nor a URL is provided, the plugin creates a new in-memory database. This method must be called before any other methods that interact with the database:
|
|
66
|
+
|
|
37
67
|
```typescript
|
|
38
68
|
import { Libsql } from '@capawesome/capacitor-libsql';
|
|
39
69
|
|
|
@@ -43,6 +73,14 @@ const connectToLocalDatabase = async () => {
|
|
|
43
73
|
});
|
|
44
74
|
console.log('Connected to database with ID:', connectionId);
|
|
45
75
|
};
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Connect to a remote database
|
|
79
|
+
|
|
80
|
+
Connect to a remote libSQL database using its URL and an authentication token:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { Libsql } from '@capawesome/capacitor-libsql';
|
|
46
84
|
|
|
47
85
|
const connectToRemoteDatabase = async () => {
|
|
48
86
|
const { connectionId } = await Libsql.connect({
|
|
@@ -51,6 +89,14 @@ const connectToRemoteDatabase = async () => {
|
|
|
51
89
|
});
|
|
52
90
|
console.log('Connected to remote database with ID:', connectionId);
|
|
53
91
|
};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Query data
|
|
95
|
+
|
|
96
|
+
Execute a `SELECT` statement and retrieve the result set:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { Libsql } from '@capawesome/capacitor-libsql';
|
|
54
100
|
|
|
55
101
|
const query = async () => {
|
|
56
102
|
const result = await Libsql.query({
|
|
@@ -59,6 +105,14 @@ const query = async () => {
|
|
|
59
105
|
});
|
|
60
106
|
console.log('Query result:', result.rows);
|
|
61
107
|
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Insert, update, and delete data
|
|
111
|
+
|
|
112
|
+
Execute any SQL statement, including `INSERT`, `UPDATE`, `DELETE`, and `CREATE TABLE`, optionally with bound values:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { Libsql } from '@capawesome/capacitor-libsql';
|
|
62
116
|
|
|
63
117
|
const execute = async () => {
|
|
64
118
|
await Libsql.execute({
|
|
@@ -68,6 +122,14 @@ const execute = async () => {
|
|
|
68
122
|
});
|
|
69
123
|
console.log('Insert executed successfully');
|
|
70
124
|
};
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Run multiple statements in a transaction
|
|
128
|
+
|
|
129
|
+
Begin a transaction, execute statements as part of it, and either commit or roll back all changes. Transactions are only available on Android:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { Libsql } from '@capawesome/capacitor-libsql';
|
|
71
133
|
|
|
72
134
|
const performTransaction = async () => {
|
|
73
135
|
const { transactionId } = await Libsql.beginTransaction({
|
|
@@ -93,6 +155,14 @@ const performTransaction = async () => {
|
|
|
93
155
|
console.error('Transaction rolled back due to error:', error);
|
|
94
156
|
}
|
|
95
157
|
};
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Synchronize with a remote server
|
|
161
|
+
|
|
162
|
+
Synchronize the database with the remote server:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { Libsql } from '@capawesome/capacitor-libsql';
|
|
96
166
|
|
|
97
167
|
const sync = async () => {
|
|
98
168
|
await Libsql.sync({
|
|
@@ -385,4 +455,39 @@ Available on iOS and Android.
|
|
|
385
455
|
|
|
386
456
|
</docgen-api>
|
|
387
457
|
|
|
458
|
+
## FAQ
|
|
459
|
+
|
|
460
|
+
### Can I use this plugin with Turso?
|
|
461
|
+
|
|
462
|
+
Yes, you can connect to a remote libSQL database hosted on [Turso](https://docs.turso.tech/libsql) by passing the database URL and an authentication token to the `connect(...)` method, as shown in the [usage example](#connect-to-a-remote-database) above.
|
|
463
|
+
|
|
464
|
+
### Do I need a remote database to use this plugin?
|
|
465
|
+
|
|
466
|
+
No, the plugin also works with purely local databases. If you pass a `path` to the `connect(...)` method, the plugin uses a database file on the device and creates it if it does not exist. If you provide neither a path nor a URL, the plugin creates a new in-memory database.
|
|
467
|
+
|
|
468
|
+
### Are transactions supported?
|
|
469
|
+
|
|
470
|
+
Yes, you can use the `beginTransaction(...)`, `commitTransaction(...)` and `rollbackTransaction(...)` methods to group multiple statements into a transaction. Note that transactions are only available on Android.
|
|
471
|
+
|
|
472
|
+
### What is the difference between the `query` and `execute` methods?
|
|
473
|
+
|
|
474
|
+
The `query(...)` method is used to execute `SELECT` statements and retrieve the result set. The `execute(...)` method is used for any other SQL statement, including `INSERT`, `UPDATE`, `DELETE`, and `CREATE TABLE`, and does not return a result set. Both methods support binding values to the statement.
|
|
475
|
+
|
|
476
|
+
### How do I keep a local database in sync with a remote server?
|
|
477
|
+
|
|
478
|
+
Call the `sync(...)` method with the ID of the connection you want to synchronize. This synchronizes the database with the remote server and is available on Android and iOS.
|
|
479
|
+
|
|
480
|
+
### Can I use this plugin with Ionic, React, Vue or Angular?
|
|
481
|
+
|
|
482
|
+
Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
|
|
483
|
+
|
|
484
|
+
## Related Plugins
|
|
485
|
+
|
|
486
|
+
- [Secure Preferences](https://capawesome.io/docs/sdks/capacitor/secure-preferences/): Securely store key/value pairs such as passwords or tokens.
|
|
487
|
+
- [SQLite](https://capawesome.io/docs/sdks/capacitor/sqlite/): Access SQLite databases with support for encryption, transactions, and schema migrations.
|
|
488
|
+
|
|
489
|
+
## Newsletter
|
|
490
|
+
|
|
491
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
492
|
+
|
|
388
493
|
[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by CHISELSTRIKE INC. or any of their affiliates or subsidiaries.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-libsql",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Capacitor plugin for libSQL databases.",
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "Capacitor plugin for libSQL databases on Android and iOS.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -32,11 +32,20 @@
|
|
|
32
32
|
"url": "https://opencollective.com/capawesome"
|
|
33
33
|
}
|
|
34
34
|
],
|
|
35
|
-
"homepage": "https://capawesome.io/
|
|
35
|
+
"homepage": "https://capawesome.io/docs/sdks/capacitor/libsql/",
|
|
36
36
|
"keywords": [
|
|
37
37
|
"capacitor",
|
|
38
38
|
"plugin",
|
|
39
|
-
"native"
|
|
39
|
+
"native",
|
|
40
|
+
"capacitor-plugin",
|
|
41
|
+
"libsql",
|
|
42
|
+
"turso",
|
|
43
|
+
"sqlite",
|
|
44
|
+
"sql database",
|
|
45
|
+
"local database",
|
|
46
|
+
"remote database",
|
|
47
|
+
"database sync",
|
|
48
|
+
"offline-first"
|
|
40
49
|
],
|
|
41
50
|
"scripts": {
|
|
42
51
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
@@ -57,24 +66,21 @@
|
|
|
57
66
|
},
|
|
58
67
|
"devDependencies": {
|
|
59
68
|
"@capacitor/android": "8.0.0",
|
|
60
|
-
"@capacitor/cli": "8.
|
|
69
|
+
"@capacitor/cli": "8.4.2",
|
|
61
70
|
"@capacitor/core": "8.0.0",
|
|
62
71
|
"@capacitor/docgen": "0.3.1",
|
|
63
72
|
"@capacitor/ios": "8.0.0",
|
|
64
73
|
"@ionic/eslint-config": "0.4.0",
|
|
65
|
-
"@ionic/swiftlint-config": "2.0.0",
|
|
66
74
|
"eslint": "8.57.0",
|
|
67
|
-
"prettier": "
|
|
68
|
-
"prettier-plugin-java": "2.6.7",
|
|
75
|
+
"prettier-plugin-java": "2.9.7",
|
|
69
76
|
"rimraf": "6.1.2",
|
|
70
|
-
"rollup": "4.
|
|
77
|
+
"rollup": "4.62.3",
|
|
71
78
|
"swiftlint": "2.0.0",
|
|
72
79
|
"typescript": "5.9.3"
|
|
73
80
|
},
|
|
74
81
|
"peerDependencies": {
|
|
75
82
|
"@capacitor/core": ">=8.0.0"
|
|
76
83
|
},
|
|
77
|
-
"swiftlint": "@ionic/swiftlint-config",
|
|
78
84
|
"eslintConfig": {
|
|
79
85
|
"extends": "@ionic/eslint-config/recommended"
|
|
80
86
|
},
|