Skip to content

Commit 26e908e

Browse files
committed
Add 1.8.x support
1 parent ed9ff97 commit 26e908e

25 files changed

+3559
-824
lines changed

README.md

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Appwrite React Native SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-react-native.svg?style=flat-square)
4-
![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.8.0-blue.svg?style=flat-square)
55
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
88

9-
**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).**
9+
**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).**
1010

1111
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the React Native SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1212

@@ -21,15 +21,16 @@ npx expo install react-native-appwrite react-native-url-polyfill
2121
```
2222

2323

24-
2524
## Getting Started
2625

2726
### Add your Platform
27+
2828
If this is your first time using Appwrite, create an account and create your first project.
2929

3030
Then, under **Add a platform**, add a **Android app** or a **Apple app**. You can skip optional steps.
3131

3232
#### iOS steps
33+
3334
Add your app **name** and **Bundle ID**. You can find your **Bundle Identifier** in the **General** tab for your app's primary target in XCode. For Expo projects you can set or find it on **app.json** file at your project's root directory.
3435

3536
#### Android steps
@@ -47,6 +48,7 @@ import 'react-native-url-polyfill/auto'
4748
> `cd ios && pod install && cd ..`
4849
4950
### Init your SDK
51+
5052
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page.
5153

5254
```js
@@ -62,6 +64,7 @@ client
6264
```
6365

6466
### Make Your First Request
67+
6568
Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.
6669

6770
```js
@@ -78,6 +81,7 @@ account.create(ID.unique(), '[email protected]', 'password', 'Jane Doe')
7881
```
7982

8083
### Full Example
84+
8185
```js
8286
import { Client, Account } from 'react-native-appwrite';
8387
// Init your React Native SDK
@@ -100,13 +104,90 @@ account.create(ID.unique(), '[email protected]', 'password', 'Jane Doe')
100104
});
101105
```
102106

107+
### Type Safety with Models
108+
109+
The Appwrite React Native SDK provides type safety when working with database documents through generic methods. Methods like `listDocuments`, `getDocument`, and others accept a generic type parameter that allows you to specify your custom model type for full type safety.
110+
111+
**TypeScript:**
112+
```typescript
113+
interface Book {
114+
name: string;
115+
author: string;
116+
releaseYear?: string;
117+
category?: string;
118+
genre?: string[];
119+
isCheckedOut: boolean;
120+
}
121+
122+
const databases = new Databases(client);
123+
124+
try {
125+
const documents = await databases.listDocuments<Book>(
126+
'your-database-id',
127+
'your-collection-id'
128+
);
129+
130+
documents.documents.forEach(book => {
131+
console.log(`Book: ${book.name} by ${book.author}`); // Now you have full type safety
132+
});
133+
} catch (error) {
134+
console.error('Appwrite error:', error);
135+
}
136+
```
137+
138+
**JavaScript (with JSDoc for type hints):**
139+
```javascript
140+
/**
141+
* @typedef {Object} Book
142+
* @property {string} name
143+
* @property {string} author
144+
* @property {string} [releaseYear]
145+
* @property {string} [category]
146+
* @property {string[]} [genre]
147+
* @property {boolean} isCheckedOut
148+
*/
149+
150+
const databases = new Databases(client);
151+
152+
try {
153+
/** @type {Models.DocumentList<Book>} */
154+
const documents = await databases.listDocuments(
155+
'your-database-id',
156+
'your-collection-id'
157+
);
158+
159+
documents.documents.forEach(book => {
160+
console.log(`Book: ${book.name} by ${book.author}`); // Type hints available in IDE
161+
});
162+
} catch (error) {
163+
console.error('Appwrite error:', error);
164+
}
165+
```
166+
167+
**Tip**: You can use the `appwrite types` command to automatically generate TypeScript interfaces based on your Appwrite database schema. Learn more about [type generation](https://appwrite.io/docs/products/databases/type-generation).
168+
169+
### Error Handling
170+
171+
The Appwrite React Native SDK raises an `AppwriteException` object with `message`, `code` and `response` properties. You can handle any errors by catching the exception and present the `message` to the user or handle it yourself based on the provided error information. Below is an example.
172+
173+
```javascript
174+
try {
175+
const user = await account.create(ID.unique(), "[email protected]", "password", "Walter O'Brien");
176+
console.log('User created:', user);
177+
} catch (error) {
178+
console.error('Appwrite error:', error.message);
179+
}
180+
```
181+
103182
### Learn more
183+
104184
You can use the following resources to learn more and get help
105185
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/quick-starts/react-native)
106186
- 📜 [Appwrite Docs](https://appwrite.io/docs)
107187
- 💬 [Discord Community](https://appwrite.io/discord)
108188
- 🚂 [Appwrite React Native Playground](https://github.com/appwrite/playground-for-react-native)
109189

190+
110191
## Contribution
111192

112193
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.

docs/examples/databases/decrement-document-attribute.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/examples/databases/increment-document-attribute.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/examples/functions/create-execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const result = await functions.createExecution(
1313
'<PATH>', // path (optional)
1414
ExecutionMethod.GET, // method (optional)
1515
{}, // headers (optional)
16-
'' // scheduledAt (optional)
16+
'<SCHEDULED_AT>' // scheduledAt (optional)
1717
);
1818

1919
console.log(result);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Client, TablesDb } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const tablesDb = new TablesDb(client);
8+
9+
const result = await tablesDb.createRow(
10+
'<DATABASE_ID>', // databaseId
11+
'<TABLE_ID>', // tableId
12+
'<ROW_ID>', // rowId
13+
{}, // data
14+
["read("any")"] // permissions (optional)
15+
);
16+
17+
console.log(result);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Client, TablesDb } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const tablesDb = new TablesDb(client);
8+
9+
const result = await tablesDb.deleteRow(
10+
'<DATABASE_ID>', // databaseId
11+
'<TABLE_ID>', // tableId
12+
'<ROW_ID>' // rowId
13+
);
14+
15+
console.log(result);

docs/examples/tablesdb/get-row.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Client, TablesDb } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const tablesDb = new TablesDb(client);
8+
9+
const result = await tablesDb.getRow(
10+
'<DATABASE_ID>', // databaseId
11+
'<TABLE_ID>', // tableId
12+
'<ROW_ID>', // rowId
13+
[] // queries (optional)
14+
);
15+
16+
console.log(result);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Client, TablesDb } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const tablesDb = new TablesDb(client);
8+
9+
const result = await tablesDb.listRows(
10+
'<DATABASE_ID>', // databaseId
11+
'<TABLE_ID>', // tableId
12+
[] // queries (optional)
13+
);
14+
15+
console.log(result);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Client, TablesDb } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const tablesDb = new TablesDb(client);
8+
9+
const result = await tablesDb.updateRow(
10+
'<DATABASE_ID>', // databaseId
11+
'<TABLE_ID>', // tableId
12+
'<ROW_ID>', // rowId
13+
{}, // data (optional)
14+
["read("any")"] // permissions (optional)
15+
);
16+
17+
console.log(result);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Client, TablesDb } from "react-native-appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
6+
7+
const tablesDb = new TablesDb(client);
8+
9+
const result = await tablesDb.upsertRow(
10+
'<DATABASE_ID>', // databaseId
11+
'<TABLE_ID>', // tableId
12+
'<ROW_ID>', // rowId
13+
{}, // data (optional)
14+
["read("any")"] // permissions (optional)
15+
);
16+
17+
console.log(result);

0 commit comments

Comments
 (0)