@@ -7,7 +7,18 @@ import 'schema_logic.dart';
77/// No migrations are required on the client.
88class Schema {
99 /// List of tables in the schema.
10+ ///
11+ /// When opening a PowerSync database, these tables will be created and
12+ /// migrated automatically.
1013 final List <Table > tables;
14+
15+ /// A list of [RawTable] s in addition to PowerSync-managed [tables] .
16+ ///
17+ /// Raw tables give users full control over the SQLite tables, but that
18+ /// includes the responsibility to create those tables and to write migrations
19+ /// for them.
20+ ///
21+ /// For more information on raw tables, see [RawTable] and [the documentation] (https://docs.powersync.com/usage/use-case-examples/raw-tables).
1122 final List <RawTable > rawTables;
1223
1324 const Schema (this .tables, {this .rawTables = const []});
@@ -316,9 +327,45 @@ class Column {
316327 Map <String , dynamic > toJson () => {'name' : name, 'type' : type.sqlite};
317328}
318329
330+ /// A raw table, defined by the user instead of being managed by PowerSync.
331+ ///
332+ /// Any ordinary SQLite table can be defined as a raw table, which enables:
333+ ///
334+ /// - More performant queries, since data is stored in typed rows instead of the
335+ /// schemaless JSON view PowerSync uses by default.
336+ /// - More control over the table, since custom column constraints can be used
337+ /// in its definition.
338+ ///
339+ /// PowerSync doesn't know anything about the internal structure of raw tables -
340+ /// instead, it relies on user-defined [put] and [delete] statements to sync
341+ /// data into them.
342+ ///
343+ /// When using raw tables, you are responsible for creating and migrating them
344+ /// when they've changed. Further, triggers are necessary to collect local
345+ /// writes to those tables. For more information, see
346+ /// [the documentation] (https://docs.powersync.com/usage/use-case-examples/raw-tables).
347+ ///
348+ /// Note that raw tables are only supported by the Rust sync client, which needs
349+ /// to be enabled when connecting with raw tables.
319350final class RawTable {
351+ /// The name of the table as used by the sync service.
352+ ///
353+ /// This doesn't necessarily have to match the name of the SQLite table that
354+ /// [put] and [delete] write to. Instead, it's used by the sync client to
355+ /// identify which statements to use when it encounters sync operations for
356+ /// this table.
320357 final String name;
358+
359+ /// A statement responsible for inserting or updating a row in this raw table
360+ /// based on data from the sync service.
361+ ///
362+ /// See [PendingStatement] for details.
321363 final PendingStatement put;
364+
365+ /// A statement responsible for deleting a row based on its PowerSync id.
366+ ///
367+ /// See [PendingStatement] for details. Note that [PendingStatementValue] s
368+ /// used here must all be [PendingStatementValue.id] .
322369 final PendingStatement delete;
323370
324371 const RawTable ({
@@ -334,8 +381,22 @@ final class RawTable {
334381 };
335382}
336383
384+ /// An SQL statement to be run by the sync client against raw tables.
385+ ///
386+ /// Since raw tables are managed by the user, PowerSync can't know how to apply
387+ /// serverside changes to them. These statements bridge raw tables and PowerSync
388+ /// by providing upserts and delete statements.
389+ ///
390+ /// For more information, see [the documentation] (https://docs.powersync.com/usage/use-case-examples/raw-tables)
337391final class PendingStatement {
392+ /// The SQL statement to run to upsert or delete data from a raw table.
338393 final String sql;
394+
395+ /// A list of value identifiers for parameters in [sql] .
396+ ///
397+ /// Put statements can use both [PendingStatementValue.id] and
398+ /// [PendingStatementValue.column] , whereas delete statements can only use
399+ /// [PendingStatementValue.id] .
339400 final List <PendingStatementValue > params;
340401
341402 PendingStatement ({required this .sql, required this .params});
@@ -346,8 +407,14 @@ final class PendingStatement {
346407 };
347408}
348409
410+ /// A description of a value that will be resolved in the sync client when
411+ /// running a [PendingStatement] for a [RawTable] .
349412sealed class PendingStatementValue {
413+ /// A value that is bound to the textual id used in the PowerSync protocol.
350414 factory PendingStatementValue .id () = _PendingStmtValueId ;
415+
416+ /// A value that is bound to the value of a column in a replace (`PUT` )
417+ /// operation of the PowerSync protocol.
351418 factory PendingStatementValue .column (String column) = _PendingStmtValueColumn ;
352419
353420 dynamic toJson ();
0 commit comments