Skip to content

Commit 607d494

Browse files
update code
1 parent b09aa1b commit 607d494

File tree

20 files changed

+512
-221
lines changed

20 files changed

+512
-221
lines changed

demos/example-capacitor/android/app/capacitor.build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ android {
99

1010
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
1111
dependencies {
12+
implementation project(':capacitor-community-sqlite')
1213
implementation project(':capacitor-splash-screen')
1314
implementation project(':powersync-capacitor')
1415

demos/example-capacitor/android/capacitor.settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
include ':capacitor-android'
33
project(':capacitor-android').projectDir = new File('../../../node_modules/@capacitor/android/capacitor')
44

5+
include ':capacitor-community-sqlite'
6+
project(':capacitor-community-sqlite').projectDir = new File('../../../node_modules/@capacitor-community/sqlite/android')
7+
58
include ':capacitor-splash-screen'
69
project(':capacitor-splash-screen').projectDir = new File('../../../node_modules/@capacitor/splash-screen/android')
710

demos/example-capacitor/ios/App/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ install! 'cocoapods', :disable_input_output_paths => true
1111
def capacitor_pods
1212
pod 'Capacitor', :path => '../../../../node_modules/@capacitor/ios'
1313
pod 'CapacitorCordova', :path => '../../../../node_modules/@capacitor/ios'
14+
pod 'CapacitorCommunitySqlite', :path => '../../../../node_modules/@capacitor-community/sqlite'
1415
pod 'CapacitorSplashScreen', :path => '../../../../node_modules/@capacitor/splash-screen'
1516
pod 'PowersyncCapacitor', :path => '../../../../packages/capacitor'
1617
end

demos/example-capacitor/ios/App/Podfile.lock

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
PODS:
22
- Capacitor (7.4.3):
33
- CapacitorCordova
4+
- CapacitorCommunitySqlite (7.0.1):
5+
- Capacitor
6+
- SQLCipher
7+
- ZIPFoundation
48
- CapacitorCordova (7.4.3)
59
- CapacitorSplashScreen (7.0.2):
610
- Capacitor
@@ -14,9 +18,11 @@ PODS:
1418
- SQLCipher/common (4.10.0)
1519
- SQLCipher/standard (4.10.0):
1620
- SQLCipher/common
21+
- ZIPFoundation (0.9.19)
1722

1823
DEPENDENCIES:
1924
- "Capacitor (from `../../../../node_modules/@capacitor/ios`)"
25+
- "CapacitorCommunitySqlite (from `../../../../node_modules/@capacitor-community/sqlite`)"
2026
- "CapacitorCordova (from `../../../../node_modules/@capacitor/ios`)"
2127
- "CapacitorSplashScreen (from `../../../../node_modules/@capacitor/splash-screen`)"
2228
- PowersyncCapacitor (from `../../../../packages/capacitor`)
@@ -25,10 +31,13 @@ SPEC REPOS:
2531
trunk:
2632
- powersync-sqlite-core
2733
- SQLCipher
34+
- ZIPFoundation
2835

2936
EXTERNAL SOURCES:
3037
Capacitor:
3138
:path: "../../../../node_modules/@capacitor/ios"
39+
CapacitorCommunitySqlite:
40+
:path: "../../../../node_modules/@capacitor-community/sqlite"
3241
CapacitorCordova:
3342
:path: "../../../../node_modules/@capacitor/ios"
3443
CapacitorSplashScreen:
@@ -38,12 +47,14 @@ EXTERNAL SOURCES:
3847

3948
SPEC CHECKSUMS:
4049
Capacitor: b4741ca7affb32c1b70debd03df92cbf522d8a80
50+
CapacitorCommunitySqlite: 3f60098baa077322ce32a678614a5fa0029ab519
4151
CapacitorCordova: 435121e81a2df4d0034f0fb11fcefab5104cfdb5
4252
CapacitorSplashScreen: 8d6c8cb0542a8e81585c593815db8785ed8ce454
4353
powersync-sqlite-core: 6f32860379009d2a37cadc9e9427a431bdbd83c8
4454
PowersyncCapacitor: 91411eaf8f7a773df9da4b76b19f576275b5a40a
4555
SQLCipher: eb79c64049cb002b4e9fcb30edb7979bf4706dfc
56+
ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c
4657

47-
PODFILE CHECKSUM: e802d16d4c452b75fb43b31bf198bbe0b7916693
58+
PODFILE CHECKSUM: 1c728e00549cebade63eaffb81de205fd020c4ea
4859

4960
COCOAPODS: 1.16.2

demos/example-capacitor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"preview": "vite preview"
2020
},
2121
"dependencies": {
22+
"@capacitor-community/sqlite": "^7.0.1",
2223
"@capacitor/android": "^7.4.3",
2324
"@capacitor/core": "latest",
2425
"@capacitor/ios": "^7.4.3",
2526
"@capacitor/splash-screen": "latest",
2627
"@journeyapps/wa-sqlite": "^1.3.1",
28+
"@powersync/capacitor": "workspace:*",
2729
"@powersync/react": "workspace:*",
2830
"@powersync/web": "workspace:*",
29-
"@powersync/capacitor": "workspace:*",
3031
"react": "^18.2.0",
3132
"react-dom": "^18.2.0",
3233
"react-router-dom": "^6.23.0"

demos/example-capacitor/src/components/providers/SystemProvider.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { PowerSyncContext } from '@powersync/react';
2-
import { PowerSyncDatabase, createBaseLogger, LogLevel } from '@powersync/web';
1+
import { Capacitor } from '@capacitor/core';
32
import { CircularProgress } from '@mui/material';
3+
import { CapacitorSQLiteAdapter } from '@powersync/capacitor';
4+
import { PowerSyncContext } from '@powersync/react';
5+
import { createBaseLogger, LogLevel, PowerSyncDatabase } from '@powersync/web';
46
import React, { Suspense } from 'react';
57
import { AppSchema } from '../../library/powersync/AppSchema.js';
68
import { BackendConnector } from '../../library/powersync/BackendConnector.js';
7-
import { Capacitor } from '@capacitor/core';
89

910
const logger = createBaseLogger();
1011
logger.useDefaults();
@@ -16,7 +17,10 @@ const isIOs = platform === 'ios';
1617
const useWebWorker = !isIOs;
1718

1819
const powerSync = new PowerSyncDatabase({
19-
database: { dbFilename: 'powersync2.db' },
20+
// We should probably rather have a separate Capacitor PowerSync client
21+
database: new CapacitorSQLiteAdapter({
22+
dbFilename: 'test.sqlite'
23+
}),
2024
schema: AppSchema,
2125
flags: {
2226
enableMultiTabs: false,

packages/capacitor/README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,30 @@ npx cap sync
1313

1414
<docgen-index>
1515

16-
* [`echo(...)`](#echo)
16+
* [`registerCore()`](#registercore)
17+
* [Type Aliases](#type-aliases)
1718

1819
</docgen-index>
1920

2021
<docgen-api>
2122
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
2223

23-
### echo(...)
24+
### registerCore()
2425

2526
```typescript
26-
echo(options: { value: string; }) => Promise<{ value: string; }>
27+
registerCore() => Promise<RegistrationResponse>
2728
```
2829

29-
| Param | Type |
30-
| ------------- | ------------------------------- |
31-
| **`options`** | <code>{ value: string; }</code> |
32-
33-
**Returns:** <code>Promise&lt;{ value: string; }&gt;</code>
30+
**Returns:** <code>Promise&lt;<a href="#registrationresponse">RegistrationResponse</a>&gt;</code>
3431

3532
--------------------
3633

34+
35+
### Type Aliases
36+
37+
38+
#### RegistrationResponse
39+
40+
<code>{ responseCode: number; }</code>
41+
3742
</docgen-api>
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef CMyPackage_h
22
#define CMyPackage_h
33

4-
#include <stdio.h>
5-
64
int register_powersync();
75

86
#endif /* CMyPackage_h */
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import Foundation
22

33
@objc public class PowerSync: NSObject {
4-
@objc public func registerCore() throws -> String {
5-
let result = register_powersync()
6-
if result != 0 {
7-
throw NSError(domain: "PowerSyncError", code: Int(result), userInfo: [
8-
NSLocalizedDescriptionKey: "PowerSync registration failed with code \(result)"
9-
])
10-
}
11-
return "Success"
4+
@objc public func registerCore() -> Int32 {
5+
return register_powersync()
126
}
137
}

packages/capacitor/ios/Sources/PowerSyncPlugin/PowerSyncPlugin.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ public class PowerSyncPlugin: CAPPlugin, CAPBridgedPlugin {
1414
]
1515
private let implementation = PowerSync()
1616

17-
@objc func registerCore(_ call: CAPPluginCall) throws -> String {
18-
let result = register_powersync()
19-
if result != 0 {
20-
throw NSError(domain: "PowerSyncError", code: Int(result), userInfo: [
21-
NSLocalizedDescriptionKey: "PowerSync registration failed with code \(result)"
22-
])
23-
}
24-
return "Success"
17+
@objc func registerCore(_ call: CAPPluginCall) {
18+
call.resolve([
19+
"responseCode": implementation.registerCore()
20+
])
2521
}
2622
}

0 commit comments

Comments
 (0)