Skip to content

Commit e88863d

Browse files
committed
chore: add setDevKey method
1 parent 0ef3018 commit e88863d

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Client, Account } from "appwrite";
3333
To install with a CDN (content delivery network) add the following scripts to the bottom of your <body> tag, but before you use any Appwrite services:
3434

3535
```html
36-
<script src="https://cdn.jsdelivr.net/npm/appwrite@18.0.0"></script>
36+
<script src="https://cdn.jsdelivr.net/npm/appwrite@18.1.0"></script>
3737
```
3838

3939

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Client, Databases } from "appwrite";
2+
3+
const client = new Client()
4+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') // Your API Endpoint
5+
.setKey(''); //
6+
7+
const databases = new Databases(client);
8+
9+
const result = await databases.createDocuments(
10+
'<DATABASE_ID>', // databaseId
11+
'<COLLECTION_ID>', // collectionId
12+
[] // documents
13+
);
14+
15+
console.log(result);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "appwrite",
33
"homepage": "https://appwrite.io/support",
44
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
5-
"version": "18.0.0",
5+
"version": "18.1.0",
66
"license": "BSD-3-Clause",
77
"main": "dist/cjs/sdk.js",
88
"exports": {

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class Client {
315315
'x-sdk-name': 'Web',
316316
'x-sdk-platform': 'client',
317317
'x-sdk-language': 'web',
318-
'x-sdk-version': '18.0.0',
318+
'x-sdk-version': '18.1.0',
319319
'X-Appwrite-Response-Format': '1.7.0',
320320
};
321321

src/services/databases.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,43 @@ export class Databases {
9090
payload
9191
);
9292
}
93+
/**
94+
* Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
95+
*
96+
* @param {string} databaseId
97+
* @param {string} collectionId
98+
* @param {object[]} documents
99+
* @throws {AppwriteException}
100+
* @returns {Promise<Models.DocumentList<Document>>}
101+
*/
102+
createDocuments<Document extends Models.Document>(databaseId: string, collectionId: string, documents: object[]): Promise<Models.DocumentList<Document>> {
103+
if (typeof databaseId === 'undefined') {
104+
throw new AppwriteException('Missing required parameter: "databaseId"');
105+
}
106+
if (typeof collectionId === 'undefined') {
107+
throw new AppwriteException('Missing required parameter: "collectionId"');
108+
}
109+
if (typeof documents === 'undefined') {
110+
throw new AppwriteException('Missing required parameter: "documents"');
111+
}
112+
const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId);
113+
const payload: Payload = {};
114+
if (typeof documents !== 'undefined') {
115+
payload['documents'] = documents;
116+
}
117+
const uri = new URL(this.client.config.endpoint + apiPath);
118+
119+
const apiHeaders: { [header: string]: string } = {
120+
'content-type': 'application/json',
121+
}
122+
123+
return this.client.call(
124+
'post',
125+
uri,
126+
apiHeaders,
127+
payload
128+
);
129+
}
93130
/**
94131
* Get a document by its unique ID. This endpoint response returns a JSON object with the document data.
95132
*

0 commit comments

Comments
 (0)