Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Formatting in README; consistently suggest using `npx`
  • Loading branch information
cahofmeyr authored Oct 3, 2023
1 parent 6d7a4b1 commit 8218c44
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions packages/powersync-sdk-react-native/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# Alpha
This package is currently in an alpha release. Functionality could change dramatically in future releases. Certain functions may be partially implemented or buggy.

# PowerSync SDK for React Native

[PowerSync](https://powersync.co) is a cloud service and set of SDKs that keeps PostgreSQL databases in sync with on-device SQLite databases.

## Alpha Release
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.

# Installation
Install package

## Install Package

```bash
yarn add @journeyapps/powersync-sdk-react-native
npx expo install @journeyapps/powersync-sdk-react-native
```

## Peer dependencies
## Peer Dependencies: SQLite

This SDK currently requires `@journeyapps/react-native-quick-sqlite` as a peer dependency.

Install it in your app with
Install it in your app with:

```bash
yarn exec expo install @journeyapps/react-native-quick-sqlite
npx expo install @journeyapps/react-native-quick-sqlite
```


## Polyfills
## Polyfills: Fetch

This SDK requires HTTP streaming in order to function. The following `fetch` polyfills are required for the React Native implementation of `fetch`:

Expand All @@ -36,7 +37,7 @@ This SDK requires HTTP streaming in order to function. The following `fetch` pol
These are listed as peer dependencies and need to be added to the React Native project

```bash
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
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
```

Enable the polyfills in React Native app with
Expand All @@ -46,19 +47,12 @@ This SDK requires HTTP streaming in order to function. The following `fetch` pol
import 'react-native-polyfill-globals/auto';
```

## Native Projects
## Polyfills & Babel Plugins: Watched Queries

This package uses native libraries. Create native Android and iOS projects (if not created already) with

```bash
yarn exec expo run:android
```

## Watched Queries
Watched queries require support for Async Iterators. Expo apps currently require polyfill and Babel plugins in order to use this functionality.

```bash
yarn add @azure/core-asynciterator-polyfill
npx expo install @azure/core-asynciterator-polyfill
```

Make sure to import the polyfill early in your application
Expand All @@ -69,7 +63,7 @@ yarn exec expo run:android
```

```bash
yarn add -D @babel/plugin-transform-async-generator-functions
npx expo install -D @babel/plugin-transform-async-generator-functions
```

Add the Babel plugin to your `babel.config.js` file
Expand All @@ -86,6 +80,14 @@ yarn exec expo run:android
};
```

## Native Projects

This package uses native libraries. Create native Android and iOS projects (if not created already) with

```bash
yarn exec expo run:android
```

# SDK Features

* Direct access to the SQLite database - use SQL on the client and server.
Expand All @@ -95,11 +97,12 @@ yarn exec expo run:android
* Subscribe to queries for live updates.

Upcoming features:
* Supports one write and many reads concurrently.
* Support one write and many reads concurrently.

# Getting Started

# Getting started
## Declare the Schema

Declare the Schema
```JavaScript
// lib/Schema.js
import { Column, ColumnType, Index, IndexedColumn, Schema, Table } from '@journeyapps/powersync-sdk-react-native';
Expand Down Expand Up @@ -129,7 +132,8 @@ export const AppSchema = new Schema([
]);
```

Create an Upload Connector
## Create an Upload Connector

```JavaScript
// lib/Connector.js
import { UpdateType} from '@journeyapps/powersync-sdk-react-native';
Expand Down Expand Up @@ -218,11 +222,9 @@ export class Connector {

```

## Create a PowerSync Connection

Create a PowerSync connection

- Use a DB adapter to connect to a SQLite DB

Use a DB adapter to connect to a SQLite DB:

```JavaScript
// lib/setup-powersync.js
Expand All @@ -246,14 +248,14 @@ export const setupPowerSync = async () => {
await PowerSync.init();
await PowerSync.connect(connector);
};

```

## Using PowerSync
# Using PowerSync

Once the PowerSync instance is configured you can start using the SQLite DB functions

### Querying items
### Querying Items

```JSX
// ListWidget.jsx
export const ListWidget = () => {
Expand Down Expand Up @@ -289,7 +291,7 @@ export const ListWidget = () => {
```


### Watching queries
### Watching Queries

A watch API allows for queries to be executed whenever a change to a dependant table is made.

Expand Down Expand Up @@ -363,4 +365,4 @@ Uncomment the following from
// }
// });
// client.addPlugin(networkFlipperPlugin);
```
```

0 comments on commit 8218c44

Please sign in to comment.