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
* This uses react-native-quick-sqlite to open a SQLite database file
134
-
*/
135
-
exportconstdb=newPowerSyncDatabase({
136
-
// The schema you defined in the previous step
137
-
schema: AppSchema,
138
-
database: {
139
-
// Filename for the SQLite database — it's important to only instantiate one instance per file.
140
-
dbFilename:'powersync.db'
141
-
// Optional. Directory where the database file is located.'
142
-
// dbLocation: 'path/to/directory'
143
-
}
144
-
});
145
-
```
125
+
<Tabs>
126
+
<Tabtitle="React Native Quick SQLite">
127
+
For getting started and testing PowerSync use the [@journeyapps/react-native-quick-sqlite](https://github.com/powersync-ja/react-native-quick-sqlite) package.
128
+
<Note>By default, this SDK requires @journeyapps/react-native-quick-sqlite as a peer dependency.</Note>
If you want to include encryption with SQLCipher use the [@powersync/op-sqlite](https://www.npmjs.com/package/@powersync/op-sqlite) package.
150
+
<Note>If you've already installed `@journeyapps/react-native-quick-sqlite`, You will have to uninstall it and then install both `@powersync/op-sqlite` and it's peer dependency `@op-engineering/op-sqlite` to use this.</Note>
import { OPSqliteOpenFactory } from'@powersync/op-sqlite'; // Add this import
155
+
import { AppSchema } from'./Schema';
156
+
157
+
// Create the factory
158
+
const opSqlite =newOPSqliteOpenFactory({
159
+
dbFilename: 'powersync.db'
160
+
});
161
+
162
+
exportconst powersync =newPowerSyncDatabase({
163
+
// For other options see,
164
+
schema: AppSchema,
165
+
// Override the default database
166
+
database: opSqlite
167
+
});
168
+
```
169
+
</Tab>
170
+
</Tabs>
146
171
147
172
<Note>
148
173
**SDK versions lower than 1.8.0**
@@ -152,11 +177,13 @@ In SDK versions lower than 1.8.0, you will need to use the deprecated [RNQSPower
152
177
153
178
Once you've instantiated your PowerSync database, you will need to call the [connect()](https://powersync-ja.github.io/powersync-js/react-native-sdk/classes/AbstractPowerSyncDatabase#connect) method to activate it.
154
179
155
-
```js
180
+
```typescript powersync/system.ts
181
+
import { Connector } from'./Connector';
182
+
156
183
exportconst setupPowerSync =async () => {
157
184
// Uses the backend connector that will be created in the next section
158
185
const connector =newConnector();
159
-
db.connect(connector);
186
+
powersync.connect(connector);
160
187
};
161
188
```
162
189
@@ -177,46 +204,65 @@ Accordingly, the connector must implement two methods:
endpoint:'[Your PowerSync instance URL or self-hosted endpoint]',
210
-
// Use a development token (see Authentication Setup https://docs.powersync.com/installation/authentication-setup/development-tokens) to get up and running quickly
211
-
token:'An authentication token'
212
-
};
230
+
/**
231
+
* Implement uploadData to send local changes to your backend service.
232
+
* You can omit this method if you only want to sync data from the database to the client
233
+
* See example implementation here:https://docs.powersync.com/client-sdk-references/react-native-and-expo#3-integrate-with-your-backend
// Implement uploadData to send local changes to your backend service.
217
-
// You can omit this method if you only want to sync data from the database to the client
247
+
for (const op oftransaction.crud) {
248
+
// The data that needs to be changed in the remote db
249
+
const record = { ...op.opData, id: op.id };
250
+
switch (op.op) {
251
+
caseUpdateType.PUT:
252
+
// TODO: Instruct your backend API to CREATE a record
253
+
break;
254
+
caseUpdateType.PATCH:
255
+
// TODO: Instruct your backend API to PATCH a record
256
+
break;
257
+
caseUpdateType.DELETE:
258
+
//TODO: Instruct your backend API to DELETE a record
259
+
break;
260
+
}
261
+
}
218
262
219
-
// See example implementation here:https://docs.powersync.com/client-sdk-references/react-native-and-expo#3-integrate-with-your-backend
263
+
// Completes the transaction and moves onto the next one
264
+
awaittransaction.complete();
265
+
}
220
266
}
221
267
```
222
268
@@ -236,17 +282,17 @@ The most commonly used CRUD functions to interact with your SQLite data are:
236
282
The [get](https://powersync-ja.github.io/powersync-js/react-native-sdk/classes/PowerSyncDatabase#get) method executes a read-only (SELECT) query and returns a single result. It throws an exception if no result is found. Use [getOptional](https://powersync-ja.github.io/powersync-js/react-native-sdk/classes/PowerSyncDatabase#getoptional) to return a single optional result (returns `null` if no result is found).
The [watch](https://powersync-ja.github.io/powersync-js/react-native-sdk/classes/PowerSyncDatabase#watch) method executes a read query whenever a change to a dependent table is made. It can be used with an `AsyncGenerator`, or with a callback.
The [execute](https://powersync-ja.github.io/powersync-js/react-native-sdk/classes/PowerSyncDatabase#execute) method can be used for executing single SQLite write statements.
0 commit comments