You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Description:** Initializes a table for `sqlite-sync` synchronization. This function is idempotent and needs to be called only once per table on each site; configurations are stored in the database and automatically loaded with the extension.
44
46
@@ -62,25 +64,32 @@ For comprehensive guidelines, see the [Database Schema Recommendations](docs/sch
62
64
The function supports three overloads:
63
65
-`cloudsync_init(table_name)`: Uses the default 'cls' CRDT algorithm.
64
66
-`cloudsync_init(table_name, crdt_algo)`: Specifies a CRDT algorithm ('cls', 'dws', 'aws', 'gos').
65
-
-`cloudsync_init(table_name, crdt_algo, force)`: Specifies an algorithm and, if `force` is `true` (or `1`), skips the integer primary key check (use with caution, GUIDs are strongly recommended).
67
+
-`cloudsync_init(table_name, crdt_algo, init_flags)`: Specifies an algorithm and a bitmask of initialization flags to control which schema sanity checks are skipped.
66
68
67
69
**Parameters:**
68
70
69
71
-`table_name` (TEXT): The name of the table to initialize.
70
-
-`crdt_algo` (TEXT, optional): The CRDT algorithm to use. Can be "cls", "dws", "aws", "gos". Defaults to "cls".
71
-
-`force` (BOOLEAN, optional): If `true` (or `1`), it skips the check that prevents the use of a single-column INTEGER primary key. Defaults to `false`. It is strongly recommended to use globally unique primary keys instead of integers.
72
+
-`crdt_algo` (TEXT, optional): The CRDT algorithm to use. Can be `"cls"`, `"dws"`, `"aws"`, `"gos"`. Defaults to `"cls"`.
73
+
-`init_flags` (INTEGER, optional): A bitmask of flags that control initialization behavior. Defaults to `0` (no flags). Available flags:
74
+
-`0` — No flags; all sanity checks are performed (default).
75
+
-`1` (`CLOUDSYNC_INIT_FLAG_SKIP_INT_PK_CHECK`) — Skip the check that prevents the use of a single-column INTEGER primary key. Use with caution; globally unique primary keys (UUID/ULID) are strongly recommended.
76
+
-`2` (`CLOUDSYNC_INIT_FLAG_SKIP_NOT_NULL_DEFAULT_CHECK`) — Skip the check that requires all NOT NULL non-PK columns to have a DEFAULT value.
77
+
-`4` (`CLOUDSYNC_INIT_FLAG_SKIP_NOT_NULL_PRIKEYS_CHECK`) — Skip the check that rejects NULL primary key values.
78
+
- Flags can be combined with bitwise OR (e.g., `3` skips both the integer PK check and the NOT NULL default check).
72
79
73
80
**Returns:** None.
74
81
75
82
**Example:**
76
83
77
84
```sql
78
-
-- Initialize a single table for synchronization with the Causal-Length Set (CLS) Algorithm (default)
85
+
-- Initialize a table with the default CLS algorithm
79
86
SELECT cloudsync_init('my_table');
80
87
81
-
-- Initialize a single table for synchronization with a different algorithm Delete-Wins Set (DWS)
88
+
-- Initialize a table with the Delete-Wins Set algorithm
82
89
SELECT cloudsync_init('my_table', 'dws');
83
90
91
+
-- Initialize a table with an integer primary key (skip the integer PK check)
**Description:** Sets a row-level filter expression on a synchronized table. Only rows that match the filter are tracked by the sync triggers; changes to rows that do not satisfy the expression are ignored and never replicated.
154
+
155
+
The filter expression is a standard SQL boolean expression written using bare column names (without a table or alias prefix). The extension automatically rewrites it with `NEW.` for INSERT/UPDATE triggers and `OLD.` for DELETE triggers. The expression is evaluated inside the trigger `WHEN` clause.
156
+
157
+
This function stores the filter in the table's settings and immediately recreates the sync triggers to apply it. The filter persists across database reopens. Use [`cloudsync_clear_filter()`](#cloudsync_clear_filtertable_name) to remove it.
158
+
159
+
**Parameters:**
160
+
161
+
-`table_name` (TEXT): The name of the synchronized table.
162
+
-`filter_expr` (TEXT): A SQL boolean expression referencing column names of the table. Only rows for which this expression evaluates to true are tracked for sync.
SELECT cloudsync_set_filter('messages', "deleted = 0 AND type != 'ephemeral'");
177
+
```
178
+
179
+
---
180
+
181
+
### `cloudsync_clear_filter(table_name)`
182
+
183
+
**Description:** Removes the row-level filter previously set with [`cloudsync_set_filter()`](#cloudsync_set_filtertable_name-filter_expr). After clearing, all row changes in the table are tracked and replicated regardless of column values.
184
+
185
+
This function updates the stored settings and immediately recreates the sync triggers without a filter condition.
186
+
187
+
**Parameters:**
188
+
189
+
-`table_name` (TEXT): The name of the synchronized table.
190
+
191
+
**Returns:**`1` on success.
192
+
193
+
**Example:**
194
+
195
+
```sql
196
+
SELECT cloudsync_clear_filter('tasks');
197
+
```
198
+
199
+
---
200
+
142
201
### `cloudsync_cleanup(table_name)`
143
202
144
203
**Description:** Removes the `sqlite-sync` synchronization mechanism from a specified table or all tables. This operation drops the associated `_cloudsync` metadata table and removes triggers from the target table(s). Use this function when synchronization is no longer desired for a table.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
4
4
5
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
7
+
## [1.0.9] - 2026-04-08
8
+
9
+
### Changed
10
+
11
+
-**cloudsync_init**: Replaced the `force` boolean parameter with an `init_flags` integer bitmask (`CLOUDSYNC_INIT_FLAG`), allowing fine-grained control over which schema sanity checks are skipped. Existing callers passing `0`/`false` or `1`/`true` remain compatible.
12
+
-**API**: Updated `cloudsync_init` SQL signature (PostgreSQL) to accept `integer` instead of `boolean` for the third argument, enabling flag combinations via bitwise OR.
0 commit comments