Skip to content

Commit 67e17b5

Browse files
authored
Merge pull request #300 from powersync-ja/poc/op-sqlite
[POC] OP SQLite Adapter for PowerSync
2 parents 8047546 + c698c07 commit 67e17b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+22771
-21620
lines changed

.changeset/pink-kids-appear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/op-sqlite': patch
3+
---
4+
5+
Initial Alpha version.

.changeset/stupid-spies-report.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/react-native': minor
3+
---
4+
5+
Make `react-native-quick-sqlite` an optional dependency so that it can be used conditionally.

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
- Vue composables for PowerSync.
2828

29+
- [packages/tanstack-query](./packages/tanstack-query/README.md)
30+
31+
- Tanstack Query integration for React.
32+
2933
- [packages/attachments](./packages/attachments/README.md)
3034

3135
- Attachments helper package for React Native and JavaScript/TypeScript projects.
@@ -34,6 +38,10 @@
3438

3539
- Kysely integration (ORM) for React Native and JavaScript/TypeScript projects.
3640

41+
- [packages/powersync-op-sqlite](./packages/powersync-op-sqlite/README.md)
42+
43+
- OP-SQLite integration for React Native projects.
44+
3745
- [packages/common](./packages/common/README.md)
3846
- Shared package: TypeScript implementation of a PowerSync database connector and streaming sync bucket implementation.
3947

demos/react-native-supabase-todolist/android/app/build.gradle

+30-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ apply plugin: "com.facebook.react"
44

55
def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()
66

7+
static def versionToNumber(major, minor, patch) {
8+
return patch * 100 + minor * 10000 + major * 1000000
9+
}
10+
11+
def getRNVersion() {
12+
def version = providers.exec {
13+
workingDir(projectDir)
14+
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
15+
}.standardOutput.asText.get().trim()
16+
17+
def coreVersion = version.split("-")[0]
18+
def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }
19+
20+
return versionToNumber(
21+
major,
22+
minor,
23+
patch
24+
)
25+
}
26+
def rnVersion = getRNVersion()
27+
728
/**
829
* This is the configuration block to customize your React Native Android app.
930
* By default you don't need to apply any configuration, just uncomment the lines you need.
@@ -57,6 +78,11 @@ react {
5778
//
5879
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
5980
// hermesFlags = ["-O", "-output-source-map"]
81+
82+
if (rnVersion >= versionToNumber(0, 75, 0)) {
83+
/* Autolinking */
84+
autolinkLibrariesWithApp()
85+
}
6086
}
6187

6288
/**
@@ -169,5 +195,7 @@ dependencies {
169195
}
170196
}
171197

172-
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
173-
applyNativeModulesAppBuildGradle(project)
198+
if (rnVersion < versionToNumber(0, 75, 0)) {
199+
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
200+
applyNativeModulesAppBuildGradle(project)
201+
}

demos/react-native-supabase-todolist/android/app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
1818
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
1919
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
20-
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://u.expo.dev/foo"/>
20+
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://u.expo.dev/"/>
2121
<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
2222
<intent-filter>
2323
<action android:name="android.intent.action.MAIN"/>
Binary file not shown.

demos/react-native-supabase-todolist/android/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
kotlin("jvm") version "1.9.24"
5+
id("java-gradle-plugin")
6+
}
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
gradlePlugin {
13+
plugins {
14+
create("reactSettingsPlugin") {
15+
id = "com.facebook.react.settings"
16+
implementationClass = "expo.plugins.ReactSettingsPlugin"
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package expo.plugins
2+
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.initialization.Settings
5+
6+
class ReactSettingsPlugin : Plugin<Settings> {
7+
override fun apply(settings: Settings) {
8+
// Do nothing, just register the plugin.
9+
}
10+
}

demos/react-native-supabase-todolist/android/settings.gradle

+50-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,49 @@
1+
pluginManagement {
2+
def version = providers.exec {
3+
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
4+
}.standardOutput.asText.get().trim()
5+
def (_, reactNativeMinor, reactNativePatch) = version.split("-")[0].tokenize('.').collect { it.toInteger() }
6+
7+
includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json')"].execute(null, rootDir).text.trim()).getParentFile().toString())
8+
if(reactNativeMinor == 74 && reactNativePatch <= 3){
9+
includeBuild("react-settings-plugin")
10+
}
11+
}
12+
13+
plugins { id("com.facebook.react.settings") }
14+
15+
def getRNMinorVersion() {
16+
def version = providers.exec {
17+
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
18+
}.standardOutput.asText.get().trim()
19+
20+
def coreVersion = version.split("-")[0]
21+
def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }
22+
23+
return minor
24+
}
25+
26+
if (getRNMinorVersion() >= 75) {
27+
extensions.configure(com.facebook.react.ReactSettingsExtension) { ex ->
28+
if (System.getenv('EXPO_UNSTABLE_CORE_AUTOLINKING') == '1') {
29+
println('\u001B[32mUsing expo-modules-autolinking as core autolinking source\u001B[0m')
30+
def command = [
31+
'node',
32+
'--no-warnings',
33+
'--eval',
34+
'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
35+
'react-native-config',
36+
'--json',
37+
'--platform',
38+
'android'
39+
].toList()
40+
ex.autolinkLibrariesFromCommand(command)
41+
} else {
42+
ex.autolinkLibrariesFromCommand()
43+
}
44+
}
45+
}
46+
147
rootProject.name = 'powersync-example'
248

349
dependencyResolutionManagement {
@@ -11,8 +57,10 @@ dependencyResolutionManagement {
1157
apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute(null, rootDir).text.trim(), "../scripts/autolinking.gradle");
1258
useExpoModules()
1359

14-
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
15-
applyNativeModulesSettingsGradle(settings)
60+
if (getRNMinorVersion() < 75) {
61+
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
62+
applyNativeModulesSettingsGradle(settings)
63+
}
1664

1765
include ':app'
1866
includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim()).getParentFile())

demos/react-native-supabase-todolist/app.config.ts

-2
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,13 @@ const config: ExpoConfig = {
5959
{
6060
ios: {
6161
deploymentTarget: '13.4',
62-
// TODO: New architecture is currently not yet supported by @journeyapps/react-native-quick-sqlite
6362
newArchEnabled: false
6463
},
6564
android: {
6665
minSdkVersion: 23,
6766
compileSdkVersion: 34,
6867
targetSdkVersion: 34,
6968
buildToolsVersion: '34.0.0',
70-
// TODO: New architecture is currently not yet supported by @journeyapps/react-native-quick-sqlite
7169
newArchEnabled: false
7270
}
7371
}

demos/react-native-supabase-todolist/app/views/todos/edit/[id].tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ const TodoView: React.FC = () => {
7777
};
7878

7979
const savePhoto = async (id: string, data: CameraCapturedPicture) => {
80-
// We are sure the base64 is not null, as we are using the base64 option in the CameraWidget
81-
const { id: photoId } = await system.attachmentQueue.savePhoto(data.base64!);
80+
if (system.attachmentQueue) {
81+
// We are sure the base64 is not null, as we are using the base64 option in the CameraWidget
82+
const { id: photoId } = await system.attachmentQueue.savePhoto(data.base64!);
8283

83-
await system.powersync.execute(`UPDATE ${TODO_TABLE} SET photo_id = ? WHERE id = ?`, [photoId, id]);
84+
await system.powersync.execute(`UPDATE ${TODO_TABLE} SET photo_id = ? WHERE id = ?`, [photoId, id]);
85+
}
8486
};
8587

8688
const createNewTodo = async (description: string) => {
@@ -98,7 +100,7 @@ const TodoView: React.FC = () => {
98100

99101
const deleteTodo = async (id: string, photoRecord?: AttachmentRecord) => {
100102
await system.powersync.writeTransaction(async (tx) => {
101-
if (photoRecord != null) {
103+
if (system.attachmentQueue && photoRecord != null) {
102104
await system.attachmentQueue.delete(photoRecord, tx);
103105
}
104106
await tx.execute(`DELETE FROM ${TODO_TABLE} WHERE id = ?`, [id]);

demos/react-native-supabase-todolist/ios/Podfile

+21
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties
77
ENV['RCT_NEW_ARCH_ENABLED'] = podfile_properties['newArchEnabled'] == 'true' ? '1' : '0'
88
ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] = podfile_properties['EX_DEV_CLIENT_NETWORK_INSPECTOR']
99

10+
use_autolinking_method_symbol = ('use' + '_native' + '_modules!').to_sym
11+
origin_autolinking_method = self.method(use_autolinking_method_symbol)
12+
self.define_singleton_method(use_autolinking_method_symbol) do |*args|
13+
if ENV['EXPO_UNSTABLE_CORE_AUTOLINKING'] == '1'
14+
Pod::UI.puts('Using expo-modules-autolinking as core autolinking source'.green)
15+
config_command = [
16+
'node',
17+
'--no-warnings',
18+
'--eval',
19+
'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
20+
'react-native-config',
21+
'--json',
22+
'--platform',
23+
'ios'
24+
]
25+
origin_autolinking_method.call(config_command)
26+
else
27+
origin_autolinking_method.call()
28+
end
29+
end
30+
1031
platform :ios, podfile_properties['ios.deploymentTarget'] || '13.4'
1132
install! 'cocoapods',
1233
:deterministic_uuids => false

0 commit comments

Comments
 (0)