@capawesome/capacitor-libsql 0.1.0 → 0.1.1

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,6 +1,12 @@
1
1
  # @capawesome/capacitor-libsql
2
2
 
3
- Capacitor plugin for libSQL databases.
3
+ Capacitor plugin for [libSQL](https://docs.turso.tech/libsql) databases.[^1]
4
+
5
+ <div class="capawesome-z29o10a">
6
+ <a href="https://cloud.capawesome.io/" target="_blank">
7
+ <img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
8
+ </a>
9
+ </div>
4
10
 
5
11
  ## Installation
6
12
 
@@ -14,8 +20,68 @@ npx cap sync
14
20
  ```typescript
15
21
  import { Libsql } from '@capawesome/capacitor-libsql';
16
22
 
17
- const echo = async () => {
18
- await Libsql.echo();
23
+ const connectToLocalDatabase = async () => {
24
+ const { connectionId } = await Libsql.connect({
25
+ path: 'database.db',
26
+ });
27
+ console.log('Connected to database with ID:', connectionId);
28
+ };
29
+
30
+ const connectToRemoteDatabase = async () => {
31
+ const { connectionId } = await Libsql.connect({
32
+ url: 'libsql://your-database-url.turso.io',
33
+ authToken: 'your-auth-token',
34
+ });
35
+ console.log('Connected to remote database with ID:', connectionId);
36
+ };
37
+
38
+ const query = async () => {
39
+ const result = await Libsql.query({
40
+ connectionId: 'my-connection-id',
41
+ statement: 'SELECT * FROM my_table',
42
+ });
43
+ console.log('Query result:', result.rows);
44
+ };
45
+
46
+ const execute = async () => {
47
+ await Libsql.execute({
48
+ connectionId: 'my-connection-id',
49
+ statement: 'INSERT INTO my_table (column1, column2) VALUES (?, ?)',
50
+ values: ['value1', 'value2'],
51
+ });
52
+ console.log('Insert executed successfully');
53
+ };
54
+
55
+ const performTransaction = async () => {
56
+ const { transactionId } = await Libsql.beginTransaction({
57
+ connectionId: 'my-connection-id',
58
+ });
59
+ try {
60
+ await Libsql.execute({
61
+ connectionId: 'my-connection-id',
62
+ statement: 'UPDATE my_table SET column1 = ? WHERE column2 = ?',
63
+ values: ['new_value', 'value2'],
64
+ transactionId,
65
+ });
66
+ await Libsql.commitTransaction({
67
+ connectionId: 'my-connection-id',
68
+ transactionId,
69
+ });
70
+ console.log('Transaction committed successfully');
71
+ } catch (error) {
72
+ await Libsql.rollbackTransaction({
73
+ connectionId: 'my-connection-id',
74
+ transactionId,
75
+ });
76
+ console.error('Transaction rolled back due to error:', error);
77
+ }
78
+ };
79
+
80
+ const sync = async () => {
81
+ await Libsql.sync({
82
+ connectionId: 'my-connection-id',
83
+ });
84
+ console.log('Database synchronized successfully');
19
85
  };
20
86
  ```
21
87
 
@@ -299,3 +365,5 @@ Only available on iOS.
299
365
  <code>string | number | null</code>
300
366
 
301
367
  </docgen-api>
368
+
369
+ [^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by CHISELSTRIKE INC. or any of their affiliates or subsidiaries.
@@ -54,7 +54,11 @@ import Libsql
54
54
  }
55
55
 
56
56
  if let values = options.values, !values.isEmpty {
57
- try connection.execute(options.statement, values as! [ValueRepresentable])
57
+ guard let valueRepresentables = values as? [ValueRepresentable] else {
58
+ completion(LibsqlError.invalidValues)
59
+ return
60
+ }
61
+ try connection.execute(options.statement, valueRepresentables)
58
62
  } else {
59
63
  try connection.execute(options.statement)
60
64
  }
@@ -76,7 +80,11 @@ import Libsql
76
80
  let values = options.values?[safe: index]
77
81
 
78
82
  if let values = values, !values.isEmpty {
79
- try connection.execute(statement, values as! [ValueRepresentable])
83
+ guard let valueRepresentables = values as? [ValueRepresentable] else {
84
+ completion(LibsqlError.invalidValues)
85
+ return
86
+ }
87
+ try connection.execute(statement, valueRepresentables)
80
88
  } else {
81
89
  try connection.execute(statement)
82
90
  }
@@ -113,7 +121,11 @@ import Libsql
113
121
  }
114
122
 
115
123
  if let values = options.values, !values.isEmpty {
116
- rows = try connection.query(options.statement, values as! [ValueRepresentable])
124
+ guard let valueRepresentables = values as? [ValueRepresentable] else {
125
+ completion(nil, LibsqlError.invalidValues)
126
+ return
127
+ }
128
+ rows = try connection.query(options.statement, valueRepresentables)
117
129
  } else {
118
130
  rows = try connection.query(options.statement)
119
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-libsql",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Capacitor plugin for libSQL databases.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",