Skip to content

Commit e128ade

Browse files
js2702simolus3
authored andcommitted
review comments
1 parent 409cb76 commit e128ade

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

packages/powersync_core/lib/src/database/powersync_db_mixin.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
134134
await _afterSchemaReady();
135135
}
136136

137-
void _assertSchemaIsReady() {
137+
void _checkSchemaIsReady() {
138138
if (!manualSchemaManagement || _manualSchemaManagementCompleted) {
139139
return;
140140
}
141141

142-
throw AssertionError(
142+
throw StateError(
143143
'In manual schema management mode, you need to mark the powersync database as ready');
144144
}
145145

@@ -319,7 +319,7 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
319319
// the lock for the connection.
320320
await initialize();
321321

322-
_assertSchemaIsReady();
322+
_checkSchemaIsReady();
323323

324324
final resolvedOptions = ResolvedSyncOptions.resolve(
325325
options,
@@ -484,15 +484,15 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
484484
/// Get an unique id for this client.
485485
/// This id is only reset when the database is deleted.
486486
Future<String> getClientId() async {
487-
_assertSchemaIsReady(); // TODO(skilldevs): Needed?
487+
_checkSchemaIsReady(); // TODO(skilldevs): Needed?
488488
final row = await get('SELECT powersync_client_id() as client_id');
489489
return row['client_id'] as String;
490490
}
491491

492492
/// Get upload queue size estimate and count.
493493
Future<UploadQueueStats> getUploadQueueStats(
494494
{bool includeSize = false}) async {
495-
_assertSchemaIsReady();
495+
_checkSchemaIsReady();
496496
if (includeSize) {
497497
final row = await getOptional(
498498
'SELECT SUM(cast(data as blob) + 20) as size, count(*) as count FROM ps_crud');
@@ -520,7 +520,7 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
520520
/// data by transaction. One batch may contain data from multiple transactions,
521521
/// and a single transaction may be split over multiple batches.
522522
Future<CrudBatch?> getCrudBatch({int limit = 100}) async {
523-
_assertSchemaIsReady();
523+
_checkSchemaIsReady();
524524
final rows = await getAll(
525525
'SELECT id, tx_id, data FROM ps_crud ORDER BY id ASC LIMIT ?',
526526
[limit + 1]);
@@ -567,7 +567,7 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
567567
/// Unlike [getCrudBatch], this only returns data from a single transaction at a time.
568568
/// All data for the transaction is loaded into memory.
569569
Future<CrudTransaction?> getNextCrudTransaction() async {
570-
_assertSchemaIsReady();
570+
_checkSchemaIsReady();
571571
return await readTransaction((tx) async {
572572
final first = await tx.getOptional(
573573
'SELECT id, tx_id, data FROM ps_crud ORDER BY id ASC LIMIT 1');

packages/powersync_core/lib/src/schema.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,8 @@ class Column {
316316
Map<String, dynamic> toJson() => {'name': name, 'type': type.sqlite};
317317
}
318318

319-
class RawTable {
320-
final String
321-
name; // TODO: it does not need to be the same name as the raw table
319+
final class RawTable {
320+
final String name;
322321
final PendingStatement put;
323322
final PendingStatement delete;
324323

@@ -335,7 +334,7 @@ class RawTable {
335334
};
336335
}
337336

338-
class PendingStatement {
337+
final class PendingStatement {
339338
final String sql;
340339
final List<PendingStatementValue> params;
341340

@@ -348,12 +347,15 @@ class PendingStatement {
348347
}
349348

350349
sealed class PendingStatementValue {
350+
factory PendingStatementValue.id() = _PendingStmtValueId;
351+
factory PendingStatementValue.column(String column) = _PendingStmtValueColumn;
352+
351353
dynamic toJson();
352354
}
353355

354-
class PendingStmtValueColumn extends PendingStatementValue {
356+
class _PendingStmtValueColumn implements PendingStatementValue {
355357
final String column;
356-
PendingStmtValueColumn(this.column);
358+
const _PendingStmtValueColumn(this.column);
357359

358360
@override
359361
dynamic toJson() {
@@ -363,7 +365,9 @@ class PendingStmtValueColumn extends PendingStatementValue {
363365
}
364366
}
365367

366-
class PendingStmtValueId extends PendingStatementValue {
368+
class _PendingStmtValueId implements PendingStatementValue {
369+
const _PendingStmtValueId();
370+
367371
@override
368372
dynamic toJson() {
369373
return 'Id';

0 commit comments

Comments
 (0)