Skip to content

Commit f878609

Browse files
authored
Merge pull request #636 from powersync-ja/fix-rnqs-sync
Fix new sync client with RNQS
2 parents 9ced54d + 450b2c9 commit f878609

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

.changeset/weak-chairs-complain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/react-native': patch
3+
---
4+
5+
Fix issues forwarding array buffers to Rust sync client.

demos/react-native-supabase-todolist/library/powersync/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import '@azure/core-asynciterator-polyfill';
22

3-
import { createBaseLogger, LogLevel, PowerSyncDatabase } from '@powersync/react-native';
3+
import { createBaseLogger, LogLevel, PowerSyncDatabase, SyncClientImplementation } from '@powersync/react-native';
44
import React from 'react';
55
import { SupabaseStorageAdapter } from '../storage/SupabaseStorageAdapter';
66

@@ -68,7 +68,7 @@ export class System {
6868

6969
async init() {
7070
await this.powersync.init();
71-
await this.powersync.connect(this.supabaseConnector);
71+
await this.powersync.connect(this.supabaseConnector, { clientImplementation: SyncClientImplementation.RUST });
7272

7373
if (this.attachmentQueue) {
7474
await this.attachmentQueue.init();

packages/react-native/src/db/PowerSyncDatabase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import {
55
DBAdapter,
66
PowerSyncBackendConnector,
77
PowerSyncDatabaseOptionsWithSettings,
8-
type RequiredAdditionalConnectionOptions,
9-
SqliteBucketStorage
8+
type RequiredAdditionalConnectionOptions
109
} from '@powersync/common';
1110
import { ReactNativeRemote } from '../sync/stream/ReactNativeRemote';
1211
import { ReactNativeStreamingSyncImplementation } from '../sync/stream/ReactNativeStreamingSyncImplementation';
1312
import { ReactNativeQuickSqliteOpenFactory } from './adapters/react-native-quick-sqlite/ReactNativeQuickSQLiteOpenFactory';
13+
import { ReactNativeBucketStorageAdapter } from './../sync/bucket/ReactNativeBucketStorageAdapter';
1414

1515
/**
1616
* A PowerSync database which provides SQLite functionality
@@ -39,7 +39,7 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
3939
}
4040

4141
protected generateBucketStorageAdapter(): BucketStorageAdapter {
42-
return new SqliteBucketStorage(this.database, AbstractPowerSyncDatabase.transactionMutex);
42+
return new ReactNativeBucketStorageAdapter(this.database, AbstractPowerSyncDatabase.transactionMutex);
4343
}
4444

4545
protected generateSyncStreamImplementation(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { PowerSyncControlCommand, SqliteBucketStorage } from '@powersync/common';
2+
3+
export class ReactNativeBucketStorageAdapter extends SqliteBucketStorage {
4+
control(op: PowerSyncControlCommand, payload: string | ArrayBuffer | null): Promise<string> {
5+
if (payload != null && typeof payload != 'string') {
6+
// For some reason, we need to copy array buffers for RNQS to recognize them. We're doing that here because we
7+
// don't want to pay the cost of a copy on platforms where it's not necessary.
8+
payload = new Uint8Array(payload).buffer;
9+
}
10+
11+
return super.control(op, payload);
12+
}
13+
}

0 commit comments

Comments
 (0)