1- # Alpha
2- This package is currently in an alpha release. Functionality could change dramatically in future releases. Certain functions may be partially implemented or buggy.
3-
41# PowerSync SDK for React Native
52
63[ PowerSync] ( https://powersync.co ) is a cloud service and set of SDKs that keeps PostgreSQL databases in sync with on-device SQLite databases.
74
5+ ## Alpha Release
6+ This React Native SDK package is currently in an alpha release. Functionality could change dramatically in future releases. Certain functions may be partially implemented or buggy.
7+
88# Installation
9- Install package
9+
10+ ## Install Package
1011
1112``` bash
12- yarn add @journeyapps/powersync-sdk-react-native
13+ npx expo install @journeyapps/powersync-sdk-react-native
1314```
1415
15- ## Peer dependencies
16+ ## Peer Dependencies: SQLite
1617
1718This SDK currently requires ` @journeyapps/react-native-quick-sqlite ` as a peer dependency.
1819
19- Install it in your app with
20+ Install it in your app with:
2021
2122``` bash
22- yarn exec expo install @journeyapps/react-native-quick-sqlite
23+ npx expo install @journeyapps/react-native-quick-sqlite
2324```
2425
2526
26- ## Polyfills
27+ ## Polyfills: Fetch
2728
2829This SDK requires HTTP streaming in order to function. The following ` fetch ` polyfills are required for the React Native implementation of ` fetch ` :
2930
@@ -36,7 +37,7 @@ This SDK requires HTTP streaming in order to function. The following `fetch` pol
3637 These are listed as peer dependencies and need to be added to the React Native project
3738
3839 ``` bash
39- yarn exec expo install react-native-fetch-api react-native-polyfill-globals react-native-url-polyfill text-encoding web-streams-polyfill base-64 react-native-get-random-values
40+ npx expo install react-native-fetch-api react-native-polyfill-globals react-native-url-polyfill text-encoding web-streams-polyfill base-64 react-native-get-random-values
4041 ```
4142
4243 Enable the polyfills in React Native app with
@@ -46,19 +47,12 @@ This SDK requires HTTP streaming in order to function. The following `fetch` pol
4647import ' react-native-polyfill-globals/auto' ;
4748 ```
4849
49- ## Native Projects
50+ ## Polyfills & Babel Plugins: Watched Queries
5051
51- This package uses native libraries. Create native Android and iOS projects (if not created already) with
52-
53- ``` bash
54- yarn exec expo run:android
55- ```
56-
57- ## Watched Queries
5852 Watched queries require support for Async Iterators. Expo apps currently require polyfill and Babel plugins in order to use this functionality.
5953
6054 ``` bash
61- yarn add @azure/core-asynciterator-polyfill
55+ npx expo install @azure/core-asynciterator-polyfill
6256 ```
6357
6458 Make sure to import the polyfill early in your application
@@ -69,7 +63,7 @@ yarn exec expo run:android
6963 ```
7064
7165 ``` bash
72- yarn add -D @babel/plugin-transform-async-generator-functions
66+ npx expo install -D @babel/plugin-transform-async-generator-functions
7367 ```
7468
7569 Add the Babel plugin to your ` babel.config.js ` file
@@ -86,6 +80,14 @@ yarn exec expo run:android
8680};
8781 ```
8882
83+ ## Native Projects
84+
85+ This package uses native libraries. Create native Android and iOS projects (if not created already) with
86+
87+ ``` bash
88+ yarn exec expo run:android
89+ ```
90+
8991# SDK Features
9092
9193 * Direct access to the SQLite database - use SQL on the client and server.
@@ -95,11 +97,12 @@ yarn exec expo run:android
9597 * Subscribe to queries for live updates.
9698
9799 Upcoming features:
98- * Supports one write and many reads concurrently.
100+ * Support one write and many reads concurrently.
101+
102+ # Getting Started
99103
100- # Getting started
104+ ## Declare the Schema
101105
102- Declare the Schema
103106``` JavaScript
104107// lib/Schema.js
105108import { Column , ColumnType , Index , IndexedColumn , Schema , Table } from ' @journeyapps/powersync-sdk-react-native' ;
@@ -129,7 +132,8 @@ export const AppSchema = new Schema([
129132]);
130133```
131134
132- Create an Upload Connector
135+ ## Create an Upload Connector
136+
133137``` JavaScript
134138// lib/Connector.js
135139import { UpdateType } from ' @journeyapps/powersync-sdk-react-native' ;
@@ -218,11 +222,9 @@ export class Connector {
218222
219223```
220224
225+ ## Create a PowerSync Connection
221226
222- Create a PowerSync connection
223-
224- - Use a DB adapter to connect to a SQLite DB
225-
227+ Use a DB adapter to connect to a SQLite DB:
226228
227229``` JavaScript
228230// lib/setup-powersync.js
@@ -246,14 +248,14 @@ export const setupPowerSync = async () => {
246248 await PowerSync .init ();
247249 await PowerSync .connect (connector);
248250};
249-
250251```
251252
252- ## Using PowerSync
253+ # Using PowerSync
253254
254255Once the PowerSync instance is configured you can start using the SQLite DB functions
255256
256- ### Querying items
257+ ### Querying Items
258+
257259``` JSX
258260// ListWidget.jsx
259261export const ListWidget = () => {
@@ -289,7 +291,7 @@ export const ListWidget = () => {
289291```
290292
291293
292- ### Watching queries
294+ ### Watching Queries
293295
294296A watch API allows for queries to be executed whenever a change to a dependant table is made.
295297
@@ -363,4 +365,4 @@ Uncomment the following from
363365 // }
364366 // });
365367 // client.addPlugin(networkFlipperPlugin);
366- ```
368+ ```
0 commit comments