Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] OP SQLite Adapter for PowerSync #300

Merged
merged 69 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
039ae8d
poc: op-sqlite
stevensJourney Aug 5, 2024
62aa5e6
wip: multiple connections
stevensJourney Aug 8, 2024
3619590
Load extension and fix read connection init
mugikhan Sep 10, 2024
be8193b
Removing duplicate file
mugikhan Sep 10, 2024
aa18107
Add file back
mugikhan Sep 10, 2024
36d8c72
Clean up
mugikhan Sep 10, 2024
171ee1f
Reintroduce RNQS and setup more open options
mugikhan Sep 11, 2024
f8183e3
Clean up
mugikhan Sep 11, 2024
7f3373e
Move op-sqlite adapter to its own package
mugikhan Sep 11, 2024
35139df
Export only adapter
mugikhan Sep 11, 2024
1a4aa40
Clean up sqliteoptions
mugikhan Sep 11, 2024
95f5aa8
WIP: Unit tests
mugikhan Sep 12, 2024
44bba63
Append to db filename to prevent caching
mugikhan Sep 12, 2024
8836706
Setup native code and update package name
mugikhan Sep 12, 2024
91d9708
Revert changes to powersync constructor
mugikhan Sep 12, 2024
e14cb9b
Add gitignore
mugikhan Sep 12, 2024
ee860d7
WIP: Native module setup
mugikhan Sep 12, 2024
56a4618
WIP: Setup unit testing for react native
mugikhan Sep 16, 2024
19a8131
WIP: Loading extensions correctly
mugikhan Sep 16, 2024
508289d
Fix whitespace bug
mugikhan Sep 16, 2024
2b60e2a
Upgrade op-sqlite to 8.0.1
mugikhan Sep 20, 2024
e099cc8
WIP: Setup tests
mugikhan Sep 20, 2024
f1ee1dc
WIP: Use turbo module for new package
mugikhan Sep 24, 2024
8a5ef85
WIP: Turbo module setup
mugikhan Sep 24, 2024
59d4396
WIP: Get bundle path
mugikhan Sep 25, 2024
5479e9b
WIP: Testing extension path ios
mugikhan Sep 25, 2024
310f4cb
Remove React Native Quick SQLite as default dependency. Fix loading o…
stevensJourney Sep 26, 2024
4cf1a2d
WIP: Clean up
mugikhan Sep 26, 2024
f68c45a
WIP: Add back RNQS
mugikhan Oct 1, 2024
bc065e3
WIP: RNQS require
mugikhan Oct 1, 2024
d6a5c49
WIP: working on iOS and Android
mugikhan Oct 1, 2024
d0e8e72
WIP: Fix dblocation defaults
mugikhan Oct 2, 2024
c0a5297
WIP: Remove unused packages
mugikhan Oct 2, 2024
65e2317
WIP: Clean up bundle path methods
mugikhan Oct 3, 2024
488646a
Merge branch 'main' into poc/op-sqlite
mugikhan Oct 3, 2024
abbffff
WIP: Improve tsconfig
mugikhan Oct 3, 2024
d135d5b
WIP: Fix build process
mugikhan Oct 3, 2024
274ffcb
WIP: Fix dependencies
mugikhan Oct 3, 2024
3e4dc44
Clean up
mugikhan Oct 3, 2024
57e8fe9
WIP: Remove test script
mugikhan Oct 3, 2024
3234f5d
Clean up
mugikhan Oct 3, 2024
4ed9a7b
Clean up
mugikhan Oct 3, 2024
1b40f38
WIP: Fix compilation for new arch
mugikhan Oct 4, 2024
7ae4111
WIP: Fix dependencies
mugikhan Oct 4, 2024
ad2e65e
WIP: Fix dynamic imports for rollup
mugikhan Oct 7, 2024
28902d5
WIP: Fix rollup config by adding nodePolyfills()
mugikhan Oct 7, 2024
67e7860
WIP: Reorder rollup plugins
mugikhan Oct 8, 2024
84bf31e
WIP: Rollup add back terser
mugikhan Oct 8, 2024
ce91966
WIP: PR feedback and cleanup
mugikhan Oct 8, 2024
3bd9b44
WIP: Update op-sqlite to latest version
mugikhan Oct 8, 2024
6dbdac9
WIP: Update lockfile
mugikhan Oct 8, 2024
f43150e
Merge branch 'main' into poc/op-sqlite
mugikhan Oct 8, 2024
05da697
WIP: PR feedback
mugikhan Oct 9, 2024
785e960
WIP: Consistent getOptional error message
mugikhan Oct 9, 2024
17f5739
WIP: Handle database locked error when executing pragma statements
mugikhan Oct 9, 2024
16f1b6c
WIP: Update to peer dependencies
mugikhan Oct 9, 2024
7348ae4
WIP: Cleanup
mugikhan Oct 10, 2024
a868114
WIP: Remove nodePolyfills plugin
mugikhan Oct 10, 2024
38c2729
Remove private key to prepare for publishing
mugikhan Oct 10, 2024
d1ba0e3
Readme update
mugikhan Oct 10, 2024
c843e4a
Merge branch 'main' into poc/op-sqlite
mugikhan Oct 10, 2024
1ea1a20
Update pnpm lock file
mugikhan Oct 10, 2024
5d135bf
Readme polish
benitav Oct 10, 2024
6675bc5
Merge branch 'poc/op-sqlite' of github.com:powersync-ja/powersync-js …
benitav Oct 10, 2024
d739486
Add root readme entry for tanstack
benitav Oct 10, 2024
f008ab1
Lower version for changeset
mugikhan Oct 10, 2024
9c140b5
Add changesets
mugikhan Oct 10, 2024
a9175a0
Fix FAB icon
mugikhan Oct 10, 2024
c698c07
Update Podfile.lock for default RNQS
mugikhan Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-kids-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/op-sqlite': patch
---

Initial Alpha version.
5 changes: 5 additions & 0 deletions .changeset/stupid-spies-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/react-native': minor
---

Make `react-native-quick-sqlite` an optional dependency so that it can be used conditionally.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

- Vue composables for PowerSync.

- [packages/tanstack-query](./packages/tanstack-query/README.md)

- Tanstack Query integration for React.

- [packages/attachments](./packages/attachments/README.md)

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

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

- [packages/powersync-op-sqlite](./packages/powersync-op-sqlite/README.md)

- OP-SQLite integration for React Native projects.

- [packages/common](./packages/common/README.md)
- Shared package: TypeScript implementation of a PowerSync database connector and streaming sync bucket implementation.

Expand Down
32 changes: 30 additions & 2 deletions demos/react-native-supabase-todolist/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ apply plugin: "com.facebook.react"

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

static def versionToNumber(major, minor, patch) {
return patch * 100 + minor * 10000 + major * 1000000
}

def getRNVersion() {
def version = providers.exec {
workingDir(projectDir)
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
}.standardOutput.asText.get().trim()

def coreVersion = version.split("-")[0]
def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }

return versionToNumber(
major,
minor,
patch
)
}
def rnVersion = getRNVersion()

/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
Expand Down Expand Up @@ -57,6 +78,11 @@ react {
//
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
// hermesFlags = ["-O", "-output-source-map"]

if (rnVersion >= versionToNumber(0, 75, 0)) {
/* Autolinking */
autolinkLibrariesWithApp()
}
}

/**
Expand Down Expand Up @@ -169,5 +195,7 @@ dependencies {
}
}

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");
applyNativeModulesAppBuildGradle(project)
if (rnVersion < versionToNumber(0, 75, 0)) {
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");
applyNativeModulesAppBuildGradle(project)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://u.expo.dev/foo"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://u.expo.dev/"/>
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.9.24"
id("java-gradle-plugin")
}

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
create("reactSettingsPlugin") {
id = "com.facebook.react.settings"
implementationClass = "expo.plugins.ReactSettingsPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package expo.plugins

import org.gradle.api.Plugin
import org.gradle.api.initialization.Settings

class ReactSettingsPlugin : Plugin<Settings> {
override fun apply(settings: Settings) {
// Do nothing, just register the plugin.
}
}
52 changes: 50 additions & 2 deletions demos/react-native-supabase-todolist/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
pluginManagement {
def version = providers.exec {
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
}.standardOutput.asText.get().trim()
def (_, reactNativeMinor, reactNativePatch) = version.split("-")[0].tokenize('.').collect { it.toInteger() }

includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json')"].execute(null, rootDir).text.trim()).getParentFile().toString())
if(reactNativeMinor == 74 && reactNativePatch <= 3){
includeBuild("react-settings-plugin")
}
}

plugins { id("com.facebook.react.settings") }

def getRNMinorVersion() {
def version = providers.exec {
commandLine("node", "-e", "console.log(require('react-native/package.json').version);")
}.standardOutput.asText.get().trim()

def coreVersion = version.split("-")[0]
def (major, minor, patch) = coreVersion.tokenize('.').collect { it.toInteger() }

return minor
}

if (getRNMinorVersion() >= 75) {
extensions.configure(com.facebook.react.ReactSettingsExtension) { ex ->
if (System.getenv('EXPO_UNSTABLE_CORE_AUTOLINKING') == '1') {
println('\u001B[32mUsing expo-modules-autolinking as core autolinking source\u001B[0m')
def command = [
'node',
'--no-warnings',
'--eval',
'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
'react-native-config',
'--json',
'--platform',
'android'
].toList()
ex.autolinkLibrariesFromCommand(command)
} else {
ex.autolinkLibrariesFromCommand()
}
}
}

rootProject.name = 'powersync-example'

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

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");
applyNativeModulesSettingsGradle(settings)
if (getRNMinorVersion() < 75) {
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");
applyNativeModulesSettingsGradle(settings)
}

include ':app'
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())
2 changes: 0 additions & 2 deletions demos/react-native-supabase-todolist/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ const config: ExpoConfig = {
{
ios: {
deploymentTarget: '13.4',
// TODO: New architecture is currently not yet supported by @journeyapps/react-native-quick-sqlite
newArchEnabled: false
},
android: {
minSdkVersion: 23,
compileSdkVersion: 34,
targetSdkVersion: 34,
buildToolsVersion: '34.0.0',
// TODO: New architecture is currently not yet supported by @journeyapps/react-native-quick-sqlite
newArchEnabled: false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ const TodoView: React.FC = () => {
};

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

await system.powersync.execute(`UPDATE ${TODO_TABLE} SET photo_id = ? WHERE id = ?`, [photoId, id]);
await system.powersync.execute(`UPDATE ${TODO_TABLE} SET photo_id = ? WHERE id = ?`, [photoId, id]);
}
};

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

const deleteTodo = async (id: string, photoRecord?: AttachmentRecord) => {
await system.powersync.writeTransaction(async (tx) => {
if (photoRecord != null) {
if (system.attachmentQueue && photoRecord != null) {
await system.attachmentQueue.delete(photoRecord, tx);
}
await tx.execute(`DELETE FROM ${TODO_TABLE} WHERE id = ?`, [id]);
Expand Down
21 changes: 21 additions & 0 deletions demos/react-native-supabase-todolist/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties
ENV['RCT_NEW_ARCH_ENABLED'] = podfile_properties['newArchEnabled'] == 'true' ? '1' : '0'
ENV['EX_DEV_CLIENT_NETWORK_INSPECTOR'] = podfile_properties['EX_DEV_CLIENT_NETWORK_INSPECTOR']

use_autolinking_method_symbol = ('use' + '_native' + '_modules!').to_sym
origin_autolinking_method = self.method(use_autolinking_method_symbol)
self.define_singleton_method(use_autolinking_method_symbol) do |*args|
if ENV['EXPO_UNSTABLE_CORE_AUTOLINKING'] == '1'
Pod::UI.puts('Using expo-modules-autolinking as core autolinking source'.green)
config_command = [
'node',
'--no-warnings',
'--eval',
'require(require.resolve(\'expo-modules-autolinking\', { paths: [require.resolve(\'expo/package.json\')] }))(process.argv.slice(1))',
'react-native-config',
'--json',
'--platform',
'ios'
]
origin_autolinking_method.call(config_command)
else
origin_autolinking_method.call()
end
end

platform :ios, podfile_properties['ios.deploymentTarget'] || '13.4'
install! 'cocoapods',
:deterministic_uuids => false
Expand Down
Loading
Loading