Skip to content

Commit 734e7d2

Browse files
authored
better composite ID column example (#306)
1 parent d6442bf commit 734e7d2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

usage/sync-rules/client-id.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ SELECT client_id as id FROM my_data
1818
MongoDB uses `_id` as the name of the ID field in collections. Therefore, PowerSync requires using `SELECT _id as id` in [Sync Rule's](/usage/sync-rules) data queries when using MongoDB as the backend source database. When inserting new documents from the client, prefer `ObjectId` values for `_id` (stored in the client's `id` column).
1919
</Info>
2020

21-
Custom transformations could also be used for the ID, for example:
21+
Custom transformations can also be used for the ID column. This is useful in certain scenarios for example when dealing with join tables, because PowerSync doesn't currently support composite primary keys. For example:
2222

2323
```sql
2424
-- Concatenate multiple columns into a single id column
25-
SELECT org_id || '.' || record_id as id FROM my_data
25+
SELECT item_id || '.' || category_id as id, * FROM item_categories
26+
27+
-- the source database schema for the above example is CREATE TABLE item_categories(item_id uuid, category_id uuid, PRIMARY KEY(item_id, category_id));
2628
```
2729

2830
<Warning>

0 commit comments

Comments
 (0)