Skip to content

Commit 4309abd

Browse files
Powersync docs (#756)
Add PowerSync docs
1 parent 88a38cc commit 4309abd

19 files changed

+1069
-1
lines changed

docs/config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
{
106106
"label": "RxDB Collection",
107107
"to": "collections/rxdb-collection"
108+
},
109+
{
110+
"label": "PowerSync Collection",
111+
"to": "collections/powersync-collection"
108112
}
109113
]
110114
},
@@ -171,6 +175,14 @@
171175
{
172176
"label": "rxdbCollectionOptions",
173177
"to": "reference/rxdb-db-collection/functions/rxdbcollectionoptions"
178+
},
179+
{
180+
"label": "PowerSync Collection",
181+
"to": "reference/powersync-db-collection/index"
182+
},
183+
{
184+
"label": "powersyncCollectionOptions",
185+
"to": "reference/powersync-db-collection/functions/powerSyncCollectionOptions"
174186
}
175187
],
176188
"frameworks": [

docs/overview.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ TanStack DB provides several built-in collection types for different data source
143143

144144
- **[RxDBCollection](./collections/rxdb-collection.md)** — Integrate with RxDB for offline-first local persistence with powerful replication and sync capabilities.
145145

146+
- **[PowerSyncCollection](./collections/powersync-collection.md)** — Sync with PowerSync's SQLite-based database for offline-first persistence with real-time synchronization with PostgreSQL, MongoDB, and MySQL backends.
147+
146148
**Local Collections**
147149

148150
- **[LocalStorageCollection](./collections/local-storage-collection.md)** — Store small amounts of local-only state that persists across sessions and syncs across browser tabs.
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
---
2+
id: PowerSyncTransactor
3+
title: PowerSyncTransactor
4+
---
5+
6+
# Class: PowerSyncTransactor
7+
8+
Defined in: [PowerSyncTransactor.ts:51](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L51)
9+
10+
Applies mutations to the PowerSync database. This method is called automatically by the collection's
11+
insert, update, and delete operations. You typically don't need to call this directly unless you
12+
have special transaction requirements.
13+
14+
## Example
15+
16+
```typescript
17+
// Create a collection
18+
const collection = createCollection(
19+
powerSyncCollectionOptions<Document>({
20+
database: db,
21+
table: APP_SCHEMA.props.documents,
22+
})
23+
)
24+
25+
const addTx = createTransaction({
26+
autoCommit: false,
27+
mutationFn: async ({ transaction }) => {
28+
await new PowerSyncTransactor({ database: db }).applyTransaction(transaction)
29+
},
30+
})
31+
32+
addTx.mutate(() => {
33+
for (let i = 0; i < 5; i++) {
34+
collection.insert({ id: randomUUID(), name: `tx-${i}` })
35+
}
36+
})
37+
38+
await addTx.commit()
39+
await addTx.isPersisted.promise
40+
```
41+
42+
## Param
43+
44+
The transaction containing mutations to apply
45+
46+
## Constructors
47+
48+
### Constructor
49+
50+
```ts
51+
new PowerSyncTransactor(options): PowerSyncTransactor;
52+
```
53+
54+
Defined in: [PowerSyncTransactor.ts:55](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L55)
55+
56+
#### Parameters
57+
58+
##### options
59+
60+
[`TransactorOptions`](../type-aliases/TransactorOptions.md)
61+
62+
#### Returns
63+
64+
`PowerSyncTransactor`
65+
66+
## Properties
67+
68+
### database
69+
70+
```ts
71+
database: AbstractPowerSyncDatabase;
72+
```
73+
74+
Defined in: [PowerSyncTransactor.ts:52](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L52)
75+
76+
***
77+
78+
### pendingOperationStore
79+
80+
```ts
81+
pendingOperationStore: PendingOperationStore;
82+
```
83+
84+
Defined in: [PowerSyncTransactor.ts:53](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L53)
85+
86+
## Methods
87+
88+
### applyTransaction()
89+
90+
```ts
91+
applyTransaction(transaction): Promise<void>;
92+
```
93+
94+
Defined in: [PowerSyncTransactor.ts:63](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L63)
95+
96+
Persists a Transaction to the PowerSync SQLite database.
97+
98+
#### Parameters
99+
100+
##### transaction
101+
102+
`Transaction`\<`any`\>
103+
104+
#### Returns
105+
106+
`Promise`\<`void`\>
107+
108+
***
109+
110+
### handleDelete()
111+
112+
```ts
113+
protected handleDelete(
114+
mutation,
115+
context,
116+
waitForCompletion): Promise<PendingOperation | null>;
117+
```
118+
119+
Defined in: [PowerSyncTransactor.ts:204](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L204)
120+
121+
#### Parameters
122+
123+
##### mutation
124+
125+
`PendingMutation`\<`any`\>
126+
127+
##### context
128+
129+
`LockContext`
130+
131+
##### waitForCompletion
132+
133+
`boolean` = `false`
134+
135+
#### Returns
136+
137+
`Promise`\<`PendingOperation` \| `null`\>
138+
139+
***
140+
141+
### handleInsert()
142+
143+
```ts
144+
protected handleInsert(
145+
mutation,
146+
context,
147+
waitForCompletion): Promise<PendingOperation | null>;
148+
```
149+
150+
Defined in: [PowerSyncTransactor.ts:149](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L149)
151+
152+
#### Parameters
153+
154+
##### mutation
155+
156+
`PendingMutation`\<`any`\>
157+
158+
##### context
159+
160+
`LockContext`
161+
162+
##### waitForCompletion
163+
164+
`boolean` = `false`
165+
166+
#### Returns
167+
168+
`Promise`\<`PendingOperation` \| `null`\>
169+
170+
***
171+
172+
### handleOperationWithCompletion()
173+
174+
```ts
175+
protected handleOperationWithCompletion(
176+
mutation,
177+
context,
178+
waitForCompletion,
179+
handler): Promise<PendingOperation | null>;
180+
```
181+
182+
Defined in: [PowerSyncTransactor.ts:232](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L232)
183+
184+
Helper function which wraps a persistence operation by:
185+
- Fetching the mutation's collection's SQLite table details
186+
- Executing the mutation
187+
- Returning the last pending diff operation if required
188+
189+
#### Parameters
190+
191+
##### mutation
192+
193+
`PendingMutation`\<`any`\>
194+
195+
##### context
196+
197+
`LockContext`
198+
199+
##### waitForCompletion
200+
201+
`boolean`
202+
203+
##### handler
204+
205+
(`tableName`, `mutation`, `serializeValue`) => `Promise`\<`void`\>
206+
207+
#### Returns
208+
209+
`Promise`\<`PendingOperation` \| `null`\>
210+
211+
***
212+
213+
### handleUpdate()
214+
215+
```ts
216+
protected handleUpdate(
217+
mutation,
218+
context,
219+
waitForCompletion): Promise<PendingOperation | null>;
220+
```
221+
222+
Defined in: [PowerSyncTransactor.ts:177](https://github.com/powersync-ja/temp-tanstack-db/blob/main/packages/powersync-db-collection/src/PowerSyncTransactor.ts#L177)
223+
224+
#### Parameters
225+
226+
##### mutation
227+
228+
`PendingMutation`\<`any`\>
229+
230+
##### context
231+
232+
`LockContext`
233+
234+
##### waitForCompletion
235+
236+
`boolean` = `false`
237+
238+
#### Returns
239+
240+
`Promise`\<`PendingOperation` \| `null`\>

0 commit comments

Comments
 (0)