Skip to content

Commit c635e6b

Browse files
committed
raw tables in schema
1 parent b1dbad1 commit c635e6b

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

packages/powersync_core/lib/src/database/native/native_powersync_database.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class PowerSyncDatabaseImpl
247247
options,
248248
crudMutex.shared,
249249
syncMutex.shared,
250+
schema,
250251
),
251252
debugName: 'Sync ${database.openFactory.path}',
252253
onError: receiveUnhandledErrors.sendPort,
@@ -290,13 +291,15 @@ class _PowerSyncDatabaseIsolateArgs {
290291
final ResolvedSyncOptions options;
291292
final SerializedMutex crudMutex;
292293
final SerializedMutex syncMutex;
294+
final Schema schema;
293295

294296
_PowerSyncDatabaseIsolateArgs(
295297
this.sPort,
296298
this.dbRef,
297299
this.options,
298300
this.crudMutex,
299301
this.syncMutex,
302+
this.schema,
300303
);
301304
}
302305

@@ -392,6 +395,7 @@ Future<void> _syncIsolate(_PowerSyncDatabaseIsolateArgs args) async {
392395
final storage = BucketStorage(connection);
393396
final sync = StreamingSyncImplementation(
394397
adapter: storage,
398+
schema: args.schema,
395399
connector: InternalConnector(
396400
getCredentialsCached: getCredentialsCached,
397401
prefetchCredentials: prefetchCredentials,

packages/powersync_core/lib/src/database/web/web_powersync_database.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class PowerSyncDatabaseImpl
141141

142142
sync = StreamingSyncImplementation(
143143
adapter: storage,
144+
schema: schema,
144145
connector: InternalConnector.wrap(connector, this),
145146
crudUpdateTriggerStream: crudStream,
146147
options: options,

packages/powersync_core/lib/src/schema.dart

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import 'schema_logic.dart';
88
class Schema {
99
/// List of tables in the schema.
1010
final List<Table> tables;
11+
final List<RawTable> rawTables;
1112

12-
const Schema(this.tables);
13+
const Schema(this.tables, {this.rawTables = const []});
1314

14-
Map<String, dynamic> toJson() => {'tables': tables};
15+
Map<String, dynamic> toJson() => {'raw_tables': rawTables, 'tables': tables};
1516

1617
void validate() {
1718
Set<String> tableNames = {};
@@ -315,6 +316,60 @@ class Column {
315316
Map<String, dynamic> toJson() => {'name': name, 'type': type.sqlite};
316317
}
317318

319+
class RawTable {
320+
final String
321+
name; // TODO: it does not need to be the same name as the raw table
322+
final PendingStatement put;
323+
final PendingStatement delete;
324+
325+
const RawTable(
326+
this.name,
327+
this.put,
328+
this.delete,
329+
);
330+
331+
Map<String, dynamic> toJson() => {
332+
'name': name,
333+
'put': put,
334+
'delete': delete,
335+
};
336+
}
337+
338+
class PendingStatement {
339+
final String sql;
340+
final List<PendingStatementValue> params;
341+
342+
PendingStatement({required this.sql, required this.params});
343+
344+
Map<String, dynamic> toJson() => {
345+
'sql': sql,
346+
'params': params,
347+
};
348+
}
349+
350+
sealed class PendingStatementValue {
351+
dynamic toJson();
352+
}
353+
354+
class PendingStmtValueColumn extends PendingStatementValue {
355+
final String column;
356+
PendingStmtValueColumn(this.column);
357+
358+
@override
359+
dynamic toJson() {
360+
return {
361+
'Column': column,
362+
};
363+
}
364+
}
365+
366+
class PendingStmtValueId extends PendingStatementValue {
367+
@override
368+
dynamic toJson() {
369+
return 'Id';
370+
}
371+
}
372+
318373
/// Type of column.
319374
enum ColumnType {
320375
/// TEXT column.

packages/powersync_core/lib/src/sync/streaming_sync.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'dart:typed_data';
55
import 'package:http/http.dart' as http;
66
import 'package:logging/logging.dart';
77
import 'package:meta/meta.dart';
8+
import 'package:powersync_core/powersync_core.dart';
89
import 'package:powersync_core/src/abort_controller.dart';
910
import 'package:powersync_core/src/exceptions.dart';
1011
import 'package:powersync_core/src/log_internal.dart';
@@ -32,6 +33,7 @@ abstract interface class StreamingSync {
3233

3334
@internal
3435
class StreamingSyncImplementation implements StreamingSync {
36+
final Schema? schema; //TODO(SkillDevs): pass in all implementations
3537
final BucketStorage adapter;
3638
final InternalConnector connector;
3739
final ResolvedSyncOptions options;
@@ -62,6 +64,7 @@ class StreamingSyncImplementation implements StreamingSync {
6264
String? clientId;
6365

6466
StreamingSyncImplementation({
67+
required this.schema,
6568
required this.adapter,
6669
required this.connector,
6770
required this.crudUpdateTriggerStream,
@@ -592,7 +595,7 @@ final class _ActiveRustStreamingIteration {
592595
'start',
593596
convert.json.encode({
594597
'parameters': sync.options.params,
595-
'schema': 'TODO: Pass-through schema (probably in serialized form)',
598+
'schema': sync.schema,
596599
}),
597600
);
598601
assert(_completedStream.isCompleted, 'Should have started streaming');

packages/powersync_core/lib/src/web/sync_worker.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class _SyncRunner {
264264

265265
sync = StreamingSyncImplementation(
266266
adapter: WebBucketStorage(database),
267+
schema: null,
267268
connector: InternalConnector(
268269
getCredentialsCached: client.channel.credentialsCallback,
269270
prefetchCredentials: ({required bool invalidate}) async {

packages/powersync_core/test/utils/abstract_test_utils.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ extension MockSync on PowerSyncDatabase {
153153
}) {
154154
final impl = StreamingSyncImplementation(
155155
adapter: BucketStorage(this),
156+
schema: null,
156157
client: client,
157158
options: ResolvedSyncOptions(options),
158159
connector: InternalConnector.wrap(connector, this),

0 commit comments

Comments
 (0)