From 568e39e486a67397e8d2cb875db057ed8f2f4f8a Mon Sep 17 00:00:00 2001 From: Aditya Oberai Date: Wed, 20 Sep 2023 12:56:51 +0000 Subject: [PATCH 1/5] Add Node.js quickstart --- .../docs/quick-starts/node/+page.markdoc | 96 +++++++++++++++++++ .../docs/quick-starts/sveltekit/+page.markdoc | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/routes/docs/quick-starts/node/+page.markdoc diff --git a/src/routes/docs/quick-starts/node/+page.markdoc b/src/routes/docs/quick-starts/node/+page.markdoc new file mode 100644 index 0000000000..6d08ac3367 --- /dev/null +++ b/src/routes/docs/quick-starts/node/+page.markdoc @@ -0,0 +1,96 @@ +--- +layout: article +title: Start with Node.js +description: This is the description used for SEO. +--- +Learn to setup your first Node.js project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). + +![Create project screen](/images/docs/databases/quick-start/create-project.png) + +If this is your first time using Appwrite, create an account and create your first project. + +Then, under **Integrate with your server**, add an **API Key**. Make sure to add the `locale.read` scope in the **Other** category (all other scopes are optional). + +![Add API Key]() + +{% /section %} +{% section #step-2 step=2 title="Create Node.js project" %} +Create a Node.js CLI application. + +```sh +mkdir my-app +cd my-app +npm init +``` + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the Node.js Appwrite SDK. + +```sh +npm install node-appwrite +``` +{% /section %} +{% section #step-4 step=4 title="Import Appwrite" %} + +Find your project ID in the **Settings** page. Also, click on the **View API Keys** button to find the API key that was created earlier. + +![Settings page in Appwrite Console.](/images/docs/databases/quick-start/project-id.png) + +Create a new file `app.js` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```js +const sdk = require("node-appwrite"); + +const client = new sdk.Client(); + +client + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); +``` + +{% /section %} +{% section #step-5 step=5 title="Use Locale Service" %} + +Once the Appwrite Client is set up, initialize the Locale service using the Client and use it to get a list of all countries by adding the following code to `app.js`. + +```js +const locale = new sdk.Locale(client); + +locale.listCountries() + .then(response => console.log(response)) + .catch(error => console.log(error)); +``` + +{% /section %} +{% section #step-6 step=6 title="Review your project" %} + +Review the entire program in `app.js` once before running it. This is a good time to catch any errors that may have been made in any past step. + +```js +const sdk = require("node-appwrite"); + +const client = new sdk.Client(); + +client + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); + +const locale = new sdk.Locale(client); + +locale.listCountries() + .then(response => console.log(response)) + .catch(error => console.log(error)); +``` + +{% /section %} +{% section #step-7 step=7 title="Checkout what you've built" %} + +Run your project with `node app.js` and view the response in your console. + +{% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/sveltekit/+page.markdoc b/src/routes/docs/quick-starts/sveltekit/+page.markdoc index d767b33166..39a0ea5893 100644 --- a/src/routes/docs/quick-starts/sveltekit/+page.markdoc +++ b/src/routes/docs/quick-starts/sveltekit/+page.markdoc @@ -9,7 +9,7 @@ Head to the [Appwrite Console](https://cloud.appwrite.io/console). ![Create project screen](/images/docs/databases/quick-start/create-project.png) -If this is your first time using Appwrite, create an accout and create your first project. +If this is your first time using Appwrite, create an account and create your first project. Then, under **Add a platform**, add a **Web app**. The **Hostname** should be localhost. From 9c87ce424b741279904523e356e2234457e1957f Mon Sep 17 00:00:00 2001 From: Aditya Oberai Date: Fri, 22 Sep 2023 16:47:54 +0000 Subject: [PATCH 2/5] Replace Locale service with Database service --- src/routes/docs/quick-starts/+page.svelte | 3 +- .../docs/quick-starts/node/+page.markdoc | 132 ++++++++++++++++-- 2 files changed, 120 insertions(+), 15 deletions(-) diff --git a/src/routes/docs/quick-starts/+page.svelte b/src/routes/docs/quick-starts/+page.svelte index 6ba718cf67..e53a555825 100644 --- a/src/routes/docs/quick-starts/+page.svelte +++ b/src/routes/docs/quick-starts/+page.svelte @@ -10,7 +10,8 @@ 'qwik', 'react', 'sveltekit', - 'vuejs' + 'vuejs', + 'node' ]; diff --git a/src/routes/docs/quick-starts/node/+page.markdoc b/src/routes/docs/quick-starts/node/+page.markdoc index 6d08ac3367..b7c8d3a898 100644 --- a/src/routes/docs/quick-starts/node/+page.markdoc +++ b/src/routes/docs/quick-starts/node/+page.markdoc @@ -11,7 +11,7 @@ Head to the [Appwrite Console](https://cloud.appwrite.io/console). If this is your first time using Appwrite, create an account and create your first project. -Then, under **Integrate with your server**, add an **API Key**. Make sure to add the `locale.read` scope in the **Other** category (all other scopes are optional). +Then, under **Integrate with your server**, add an **API Key**. Make sure to add the `databases.write`, `collections.write`, `attributes.write`, `documents.read`, and `documents.write` scopes in the **Database** category (all other scopes are optional). ![Add API Key]() @@ -54,20 +54,79 @@ client ``` {% /section %} -{% section #step-5 step=5 title="Use Locale Service" %} +{% section #step-5 step=5 title="Initialize Database Service" %} -Once the Appwrite Client is set up, initialize the Locale service using the Client and use it to get a list of all countries by adding the following code to `app.js`. +Once the Appwrite Client is set up, initialize the Database service using the Client and create a function to prepare a Todos database and collection (with the necessary attributes) by adding the following code to `app.js`. ```js -const locale = new sdk.Locale(client); +const databases = new sdk.Databases(client); + +var todoDatabase; +var todoCollection; + +async function prepareDatabase() { + todoDatabase = await databases.create(sdk.ID.unique(), 'TodosDB'); + todoCollection = await databases.createCollection(todoDatabase.$id, sdk.ID.unique(), 'Todos'); + await databases.createStringAttribute(todoDatabase.$id, todoCollection.$id, 'title', 255, true); + await databases.createStringAttribute(todoDatabase.$id, todoCollection.$id, 'description', 255, false, 'This is a test description'); + await databases.createBooleanAttribute(todoDatabase.$id, todoCollection.$id, 'isComplete', true); +} +``` + +{% /section %} +{% section #step-6 step=6 title="Seed Todos Database" %} + +Once the Todos database and collection is ready, create a function to seed it with sample data by adding the following code to `app.js`. + +```js +async function seedDatabase() { + var testTodo1 = { + title: 'Buy apples', + description: 'At least 2KGs', + isComplete: true + }; + + var testTodo2 = { + title: 'Wash the apples', + isComplete: true + }; + + var testTodo3 = { + title: 'Cut the apples', + description: 'Don\'t forget to pack them in a box', + isComplete: false + }; + + await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo1); + await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo2); + await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo3); +} +``` + +{% /section %} +{% section #step-7 step=7 title="Get List Of Todos" %} -locale.listCountries() - .then(response => console.log(response)) - .catch(error => console.log(error)); +After the database is seeded, create a function to get the list of all the seeded data and a function to trigger all the created functions in the steps above by adding the following code to `app.js`. + +```js +async function getTodos() { + var todos = await databases.listDocuments(todoDatabase.$id, todoCollection.$id); + + todos.documents.forEach(todo => { + console.log(`Title: ${todo.title}\nDescription: ${todo.description}\nIs Todo Complete: ${todo.isComplete}\n\n`); + }); +} + +async function runAllTasks() { + await prepareDatabase(); + await seedDatabase(); + await getTodos(); +} +runAllTasks(); ``` {% /section %} -{% section #step-6 step=6 title="Review your project" %} +{% section #step-8 step=8 title="Review your project" %} Review the entire program in `app.js` once before running it. This is a good time to catch any errors that may have been made in any past step. @@ -81,15 +140,60 @@ client .setProject("") .setKey(""); -const locale = new sdk.Locale(client); - -locale.listCountries() - .then(response => console.log(response)) - .catch(error => console.log(error)); +const databases = new sdk.Databases(client); + +var todoDatabase; +var todoCollection; + +async function prepareDatabase() { + todoDatabase = await databases.create(sdk.ID.unique(), 'TodosDB'); + todoCollection = await databases.createCollection(todoDatabase.$id, sdk.ID.unique(), 'Todos'); + await databases.createStringAttribute(todoDatabase.$id, todoCollection.$id, 'title', 255, true); + await databases.createStringAttribute(todoDatabase.$id, todoCollection.$id, 'description', 255, false, 'This is a test description'); + await databases.createBooleanAttribute(todoDatabase.$id, todoCollection.$id, 'isComplete', true); +} + +async function seedDatabase() { + var testTodo1 = { + title: 'Buy apples', + description: 'At least 2KGs', + isComplete: true + }; + + var testTodo2 = { + title: 'Wash the apples', + isComplete: true + }; + + var testTodo3 = { + title: 'Cut the apples', + description: 'Don\'t forget to pack them in a box', + isComplete: false + }; + + await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo1); + await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo2); + await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo3); +} + +async function getTodos() { + var todos = await databases.listDocuments(todoDatabase.$id, todoCollection.$id); + + todos.documents.forEach(todo => { + console.log(`Title: ${todo.title}\nDescription: ${todo.description}\nIs Todo Complete: ${todo.isComplete}\n\n`); + }); +} + +async function runAllTasks() { + await prepareDatabase(); + await seedDatabase(); + await getTodos(); +} +runAllTasks(); ``` {% /section %} -{% section #step-7 step=7 title="Checkout what you've built" %} +{% section #step-9 step=9 title="Check out what you've built" %} Run your project with `node app.js` and view the response in your console. From 4512e482cbdee6f051a54db83611ecc378e6fe70 Mon Sep 17 00:00:00 2001 From: Aditya Oberai Date: Mon, 25 Sep 2023 13:39:58 +0000 Subject: [PATCH 3/5] Add Dart quickstart --- src/routes/docs/quick-starts/+page.svelte | 3 +- .../docs/quick-starts/dart/+page.markdoc | 311 ++++++++++++++++++ 2 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 src/routes/docs/quick-starts/dart/+page.markdoc diff --git a/src/routes/docs/quick-starts/+page.svelte b/src/routes/docs/quick-starts/+page.svelte index e53a555825..b293ac3a44 100644 --- a/src/routes/docs/quick-starts/+page.svelte +++ b/src/routes/docs/quick-starts/+page.svelte @@ -11,7 +11,8 @@ 'react', 'sveltekit', 'vuejs', - 'node' + 'node', + 'dart' ]; diff --git a/src/routes/docs/quick-starts/dart/+page.markdoc b/src/routes/docs/quick-starts/dart/+page.markdoc new file mode 100644 index 0000000000..5556ec7219 --- /dev/null +++ b/src/routes/docs/quick-starts/dart/+page.markdoc @@ -0,0 +1,311 @@ +--- +layout: article +title: Start with Dart +description: This is the description used for SEO. +--- +Learn to setup your first Dart project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). + +![Create project screen](/images/docs/databases/quick-start/create-project.png) + +If this is your first time using Appwrite, create an account and create your first project. + +Then, under **Integrate with your server**, add an **API Key**. Make sure to add the `databases.write`, `collections.write`, `attributes.write`, `documents.read`, and `documents.write` scopes in the **Database** category (all other scopes are optional). + +![Add API Key]() + +{% /section %} +{% section #step-2 step=2 title="Create Dart project" %} +Create a Dart CLI application. + +```sh +dart create -t console my_app +cd my_app +``` + +After entering the project directory, remove the `lib/` and `test/` directories. + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the Dart Appwrite SDK. + +```sh +dart pub add dart_appwrite +``` +{% /section %} +{% section #step-4 step=4 title="Import Appwrite" %} + +Find your project ID in the **Settings** page. Also, click on the **View API Keys** button to find the API key that was created earlier. + +![Settings page in Appwrite Console.](/images/docs/databases/quick-start/project-id.png) + +Open `bin/my_app.dart` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +var client = Client(); + +Future main() async { + client + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); +} +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize Database Service" %} + +Once the Appwrite Client is set up, initialize the Database service using the Client and create a function to prepare a Todos database and collection (with the necessary attributes) by adding the following code to `bin/my_app.dart`. + +```dart +var databases; +var todoDatabase; +var todoCollection; + +Future prepareDatabase() async { + databases = Databases(client); + + todoDatabase = await databases.create( + databaseId: ID.unique(), + name: 'TodosDB' + ); + + todoCollection = await databases.createCollection( + databaseId: todoDatabase.$id, + collectionId: ID.unique(), + name: 'Todos' + ); + + await databases.createStringAttribute( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + key: 'title', + size: 255, + xrequired: true + ); + + await databases.createStringAttribute( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + key: 'description', + size: 255, + xrequired: false, + xdefault: 'This is a test description' + ); + + await databases.createBooleanAttribute( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + key: 'isComplete', + xrequired: true + ); +} +``` + +{% /section %} +{% section #step-6 step=6 title="Seed Todos Database" %} + +Once the Todos database and collection is ready, create a function to seed it with sample data by adding the following code to `bin/my_app.dart`. + +```dart +Future seedDatabase() async { + var testTodo1 = { + 'title': 'Buy apples', + 'description': 'At least 2KGs', + 'isComplete': true + }; + + var testTodo2 = { + 'title': 'Wash the apples', + 'isComplete': true + }; + + var testTodo3 = { + 'title': 'Cut the apples', + 'description': 'Don\'t forget to pack them in a box', + 'isComplete': false + }; + + await databases.createDocument( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + documentId: ID.unique(), + data: testTodo1 + ); + + await databases.createDocument( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + documentId: ID.unique(), + data: testTodo2 + ); + + await databases.createDocument( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + documentId: ID.unique(), + data: testTodo3 + ); +} +``` + +{% /section %} +{% section #step-7 step=7 title="Get List Of Todos" %} + +After the database is seeded, create a function to get the list of all the seeded data by adding the following code to `bin/my_app.dart`. + +```dart +Future getTodos() async { + var todos = await databases.listDocuments( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id + ); + + todos.documents.forEach((todo) { + print('Title: ${todo.data['title']}\nDescription: ${todo.data['description']}\nIs Todo Complete: ${todo.data['isComplete']}\n\n'); + }); +} +``` + +Finally, revisit the `main()` function and update it to add the necessary function calls to trigger all the created functions in the steps above. +```dart +Future main() async { + client + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); + + await prepareDatabase(); + await Future.delayed(const Duration(seconds: 1)); + await seedDatabase(); + await getTodos(); +} +``` + +{% /section %} +{% section #step-8 step=8 title="Review your project" %} + +Review the entire program in `bin/my_app.dart` once before running it. This is a good time to catch any errors that may have been made in any past step. + +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +var client = Client(); + +Future main() async { + client + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); + + await prepareDatabase(); + await Future.delayed(const Duration(seconds: 1)); + await seedDatabase(); + await getTodos(); +} + +var databases; +var todoDatabase; +var todoCollection; + +Future prepareDatabase() async { + databases = Databases(client); + + todoDatabase = await databases.create( + databaseId: ID.unique(), + name: 'TodosDB' + ); + + todoCollection = await databases.createCollection( + databaseId: todoDatabase.$id, + collectionId: ID.unique(), + name: 'Todos' + ); + + await databases.createStringAttribute( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + key: 'title', + size: 255, + xrequired: true + ); + + await databases.createStringAttribute( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + key: 'description', + size: 255, + xrequired: false, + xdefault: 'This is a test description' + ); + + await databases.createBooleanAttribute( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + key: 'isComplete', + xrequired: true + ); +} + +Future seedDatabase() async { + var testTodo1 = { + 'title': 'Buy apples', + 'description': 'At least 2KGs', + 'isComplete': true + }; + + var testTodo2 = { + 'title': 'Wash the apples', + 'isComplete': true + }; + + var testTodo3 = { + 'title': 'Cut the apples', + 'description': 'Don\'t forget to pack them in a box', + 'isComplete': false + }; + + await databases.createDocument( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + documentId: ID.unique(), + data: testTodo1 + ); + + await databases.createDocument( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + documentId: ID.unique(), + data: testTodo2 + ); + + await databases.createDocument( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id, + documentId: ID.unique(), + data: testTodo3 + ); +} + +Future getTodos() async { + var todos = await databases.listDocuments( + databaseId: todoDatabase.$id, + collectionId: todoCollection.$id + ); + + todos.documents.forEach((todo) { + print('Title: ${todo.data['title']}\nDescription: ${todo.data['description']}\nIs Todo Complete: ${todo.data['isComplete']}\n\n'); + }); +} +``` + +{% /section %} +{% section #step-9 step=9 title="Check out what you've built" %} + +Run your project with `dart run bin/my_app.dart` and view the response in your console. + +{% /section %} \ No newline at end of file From 30ee6edd35f01b50c88422160c60ffb194e0904c Mon Sep 17 00:00:00 2001 From: Aditya Oberai Date: Mon, 25 Sep 2023 13:46:12 +0000 Subject: [PATCH 4/5] Improve code example readability --- .../docs/quick-starts/node/+page.markdoc | 129 +++++++++++++++--- 1 file changed, 111 insertions(+), 18 deletions(-) diff --git a/src/routes/docs/quick-starts/node/+page.markdoc b/src/routes/docs/quick-starts/node/+page.markdoc index b7c8d3a898..1fc9db8c2c 100644 --- a/src/routes/docs/quick-starts/node/+page.markdoc +++ b/src/routes/docs/quick-starts/node/+page.markdoc @@ -65,11 +65,39 @@ var todoDatabase; var todoCollection; async function prepareDatabase() { - todoDatabase = await databases.create(sdk.ID.unique(), 'TodosDB'); - todoCollection = await databases.createCollection(todoDatabase.$id, sdk.ID.unique(), 'Todos'); - await databases.createStringAttribute(todoDatabase.$id, todoCollection.$id, 'title', 255, true); - await databases.createStringAttribute(todoDatabase.$id, todoCollection.$id, 'description', 255, false, 'This is a test description'); - await databases.createBooleanAttribute(todoDatabase.$id, todoCollection.$id, 'isComplete', true); + todoDatabase = await databases.create( + sdk.ID.unique(), + 'TodosDB' + ); + + todoCollection = await databases.createCollection( + todoDatabase.$id, + sdk.ID.unique(), + 'Todos' + ); + + await databases.createStringAttribute( + todoDatabase.$id, + todoCollection.$id, + 'title', + 255, + true + ); + + await databases.createStringAttribute( + todoDatabase.$id, + todoCollection.$id, + 'description', + 255, false, + 'This is a test description' + ); + + await databases.createBooleanAttribute( + todoDatabase.$id, + todoCollection.$id, + 'isComplete', + true + ); } ``` @@ -97,9 +125,22 @@ async function seedDatabase() { isComplete: false }; - await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo1); - await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo2); - await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo3); + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + sdk.ID.unique(), + testTodo1 + ); + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + sdk.ID.unique(), + testTodo2 + ); + + await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo3 + ); } ``` @@ -110,7 +151,10 @@ After the database is seeded, create a function to get the list of all the seede ```js async function getTodos() { - var todos = await databases.listDocuments(todoDatabase.$id, todoCollection.$id); + var todos = await databases.listDocuments( + todoDatabase.$id, + todoCollection.$id + ); todos.documents.forEach(todo => { console.log(`Title: ${todo.title}\nDescription: ${todo.description}\nIs Todo Complete: ${todo.isComplete}\n\n`); @@ -146,11 +190,40 @@ var todoDatabase; var todoCollection; async function prepareDatabase() { - todoDatabase = await databases.create(sdk.ID.unique(), 'TodosDB'); - todoCollection = await databases.createCollection(todoDatabase.$id, sdk.ID.unique(), 'Todos'); - await databases.createStringAttribute(todoDatabase.$id, todoCollection.$id, 'title', 255, true); - await databases.createStringAttribute(todoDatabase.$id, todoCollection.$id, 'description', 255, false, 'This is a test description'); - await databases.createBooleanAttribute(todoDatabase.$id, todoCollection.$id, 'isComplete', true); + todoDatabase = await databases.create( + sdk.ID.unique(), + 'TodosDB' + ); + + todoCollection = await databases.createCollection( + todoDatabase.$id, + sdk.ID.unique(), + 'Todos' + ); + + await databases.createStringAttribute( + todoDatabase.$id, + todoCollection.$id, + 'title', + 255, + true + ); + + await databases.createStringAttribute( + todoDatabase.$id, + todoCollection.$id, + 'description', + 255, + false, + 'This is a test description' + ); + + await databases.createBooleanAttribute( + todoDatabase.$id, + todoCollection.$id, + 'isComplete', + true + ); } async function seedDatabase() { @@ -171,13 +244,33 @@ async function seedDatabase() { isComplete: false }; - await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo1); - await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo2); - await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo3); + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + sdk.ID.unique(), + testTodo1 + ); + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + sdk.ID.unique(), + testTodo2 + ); + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + sdk.ID.unique(), + testTodo3 + ); } async function getTodos() { - var todos = await databases.listDocuments(todoDatabase.$id, todoCollection.$id); + var todos = await databases.listDocuments( + todoDatabase.$id, + todoCollection.$id + ); todos.documents.forEach(todo => { console.log(`Title: ${todo.title}\nDescription: ${todo.description}\nIs Todo Complete: ${todo.isComplete}\n\n`); From 984530760d5c4e70c4e00ee8826b7fc2bcff025f Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Mon, 25 Sep 2023 15:36:24 +0000 Subject: [PATCH 5/5] Fixed some formatting --- .../docs/quick-starts/dart/+page.markdoc | 149 +++-------------- .../docs/quick-starts/node/+page.markdoc | 150 +++--------------- 2 files changed, 44 insertions(+), 255 deletions(-) diff --git a/src/routes/docs/quick-starts/dart/+page.markdoc b/src/routes/docs/quick-starts/dart/+page.markdoc index 5556ec7219..e6a6a94c0d 100644 --- a/src/routes/docs/quick-starts/dart/+page.markdoc +++ b/src/routes/docs/quick-starts/dart/+page.markdoc @@ -11,7 +11,18 @@ Head to the [Appwrite Console](https://cloud.appwrite.io/console). If this is your first time using Appwrite, create an account and create your first project. -Then, under **Integrate with your server**, add an **API Key**. Make sure to add the `databases.write`, `collections.write`, `attributes.write`, `documents.read`, and `documents.write` scopes in the **Database** category (all other scopes are optional). + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +| Category {% width=120 %} | Required scopes | Purpose | +|-----------|-----------------------|---------| +| Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | +| | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | +| | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | +| | `documents.read` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to read [documents](/docs/products/databases/documents). | + +Other scopes are optional. ![Add API Key]() @@ -57,9 +68,9 @@ Future main() async { ``` {% /section %} -{% section #step-5 step=5 title="Initialize Database Service" %} +{% section #step-5 step=5 title="Initialize database" %} -Once the Appwrite Client is set up, initialize the Database service using the Client and create a function to prepare a Todos database and collection (with the necessary attributes) by adding the following code to `bin/my_app.dart`. +Once the Appwrite Client is initialized, create a function to configure a todo collection. ```dart var databases; @@ -107,10 +118,8 @@ Future prepareDatabase() async { ``` {% /section %} -{% section #step-6 step=6 title="Seed Todos Database" %} - -Once the Todos database and collection is ready, create a function to seed it with sample data by adding the following code to `bin/my_app.dart`. - +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. ```dart Future seedDatabase() async { var testTodo1 = { @@ -154,10 +163,9 @@ Future seedDatabase() async { ``` {% /section %} -{% section #step-7 step=7 title="Get List Of Todos" %} - -After the database is seeded, create a function to get the list of all the seeded data by adding the following code to `bin/my_app.dart`. +{% section #step-7 step=7 title="Retrieve documents" %} +Create a function to retrieve the mock todo data. ```dart Future getTodos() async { var todos = await databases.listDocuments( @@ -171,7 +179,7 @@ Future getTodos() async { } ``` -Finally, revisit the `main()` function and update it to add the necessary function calls to trigger all the created functions in the steps above. +Finally, revisit the `main()` function and call the functions created in previous steps. ```dart Future main() async { client @@ -187,124 +195,7 @@ Future main() async { ``` {% /section %} -{% section #step-8 step=8 title="Review your project" %} - -Review the entire program in `bin/my_app.dart` once before running it. This is a good time to catch any errors that may have been made in any past step. - -```dart -import 'package:dart_appwrite/dart_appwrite.dart'; - -var client = Client(); - -Future main() async { - client - .setEndpoint("https://cloud.appwrite.io/v1") - .setProject("") - .setKey(""); - - await prepareDatabase(); - await Future.delayed(const Duration(seconds: 1)); - await seedDatabase(); - await getTodos(); -} - -var databases; -var todoDatabase; -var todoCollection; - -Future prepareDatabase() async { - databases = Databases(client); - - todoDatabase = await databases.create( - databaseId: ID.unique(), - name: 'TodosDB' - ); - - todoCollection = await databases.createCollection( - databaseId: todoDatabase.$id, - collectionId: ID.unique(), - name: 'Todos' - ); - - await databases.createStringAttribute( - databaseId: todoDatabase.$id, - collectionId: todoCollection.$id, - key: 'title', - size: 255, - xrequired: true - ); - - await databases.createStringAttribute( - databaseId: todoDatabase.$id, - collectionId: todoCollection.$id, - key: 'description', - size: 255, - xrequired: false, - xdefault: 'This is a test description' - ); - - await databases.createBooleanAttribute( - databaseId: todoDatabase.$id, - collectionId: todoCollection.$id, - key: 'isComplete', - xrequired: true - ); -} - -Future seedDatabase() async { - var testTodo1 = { - 'title': 'Buy apples', - 'description': 'At least 2KGs', - 'isComplete': true - }; - - var testTodo2 = { - 'title': 'Wash the apples', - 'isComplete': true - }; - - var testTodo3 = { - 'title': 'Cut the apples', - 'description': 'Don\'t forget to pack them in a box', - 'isComplete': false - }; - - await databases.createDocument( - databaseId: todoDatabase.$id, - collectionId: todoCollection.$id, - documentId: ID.unique(), - data: testTodo1 - ); - - await databases.createDocument( - databaseId: todoDatabase.$id, - collectionId: todoCollection.$id, - documentId: ID.unique(), - data: testTodo2 - ); - - await databases.createDocument( - databaseId: todoDatabase.$id, - collectionId: todoCollection.$id, - documentId: ID.unique(), - data: testTodo3 - ); -} - -Future getTodos() async { - var todos = await databases.listDocuments( - databaseId: todoDatabase.$id, - collectionId: todoCollection.$id - ); - - todos.documents.forEach((todo) { - print('Title: ${todo.data['title']}\nDescription: ${todo.data['description']}\nIs Todo Complete: ${todo.data['isComplete']}\n\n'); - }); -} -``` - -{% /section %} -{% section #step-9 step=9 title="Check out what you've built" %} +{% section #step-8 step=8 title="All set" %} Run your project with `dart run bin/my_app.dart` and view the response in your console. diff --git a/src/routes/docs/quick-starts/node/+page.markdoc b/src/routes/docs/quick-starts/node/+page.markdoc index 1fc9db8c2c..e666bcd6d3 100644 --- a/src/routes/docs/quick-starts/node/+page.markdoc +++ b/src/routes/docs/quick-starts/node/+page.markdoc @@ -11,7 +11,17 @@ Head to the [Appwrite Console](https://cloud.appwrite.io/console). If this is your first time using Appwrite, create an account and create your first project. -Then, under **Integrate with your server**, add an **API Key**. Make sure to add the `databases.write`, `collections.write`, `attributes.write`, `documents.read`, and `documents.write` scopes in the **Database** category (all other scopes are optional). +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +| Category {% width=120 %} | Required scopes | Purpose | +|-----------|-----------------------|---------| +| Database | `databases.write` | Allows API key to create, update, and delete [databases](/docs/products/databases/databases). | +| | `collections.write` | Allows API key to create, update, and delete [collections](/docs/products/databases/collections). | +| | `attributes.write` | Allows API key to create, update, and delete [attributes](/docs/products/databases/collections#attributes). | +| | `documents.read` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to read [documents](/docs/products/databases/documents). | + +Other scopes are optional. ![Add API Key]() @@ -54,9 +64,9 @@ client ``` {% /section %} -{% section #step-5 step=5 title="Initialize Database Service" %} +{% section #step-5 step=5 title="Initialize database" %} -Once the Appwrite Client is set up, initialize the Database service using the Client and create a function to prepare a Todos database and collection (with the necessary attributes) by adding the following code to `app.js`. +Once the Appwrite Client is initialized, create a function to configure a todo collection. ```js const databases = new sdk.Databases(client); @@ -102,10 +112,8 @@ async function prepareDatabase() { ``` {% /section %} -{% section #step-6 step=6 title="Seed Todos Database" %} - -Once the Todos database and collection is ready, create a function to seed it with sample data by adding the following code to `app.js`. - +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. ```js async function seedDatabase() { var testTodo1 = { @@ -139,133 +147,22 @@ async function seedDatabase() { testTodo2 ); - await databases.createDocument(todoDatabase.$id, todoCollection.$id, sdk.ID.unique(), testTodo3 - ); -} -``` - -{% /section %} -{% section #step-7 step=7 title="Get List Of Todos" %} - -After the database is seeded, create a function to get the list of all the seeded data and a function to trigger all the created functions in the steps above by adding the following code to `app.js`. - -```js -async function getTodos() { - var todos = await databases.listDocuments( + await databases.createDocument( todoDatabase.$id, - todoCollection.$id + todoCollection.$id, + sdk.ID.unique(), + testTodo3 ); - - todos.documents.forEach(todo => { - console.log(`Title: ${todo.title}\nDescription: ${todo.description}\nIs Todo Complete: ${todo.isComplete}\n\n`); - }); } - -async function runAllTasks() { - await prepareDatabase(); - await seedDatabase(); - await getTodos(); -} -runAllTasks(); ``` {% /section %} -{% section #step-8 step=8 title="Review your project" %} +{% section #step-7 step=7 title="Retrieve documents" %} -Review the entire program in `app.js` once before running it. This is a good time to catch any errors that may have been made in any past step. +Create a function to retrieve the mock todo data and a function to execute the requests in order. +Run the functions to by calling `runAllTasks();`. ```js -const sdk = require("node-appwrite"); - -const client = new sdk.Client(); - -client - .setEndpoint("https://cloud.appwrite.io/v1") - .setProject("") - .setKey(""); - -const databases = new sdk.Databases(client); - -var todoDatabase; -var todoCollection; - -async function prepareDatabase() { - todoDatabase = await databases.create( - sdk.ID.unique(), - 'TodosDB' - ); - - todoCollection = await databases.createCollection( - todoDatabase.$id, - sdk.ID.unique(), - 'Todos' - ); - - await databases.createStringAttribute( - todoDatabase.$id, - todoCollection.$id, - 'title', - 255, - true - ); - - await databases.createStringAttribute( - todoDatabase.$id, - todoCollection.$id, - 'description', - 255, - false, - 'This is a test description' - ); - - await databases.createBooleanAttribute( - todoDatabase.$id, - todoCollection.$id, - 'isComplete', - true - ); -} - -async function seedDatabase() { - var testTodo1 = { - title: 'Buy apples', - description: 'At least 2KGs', - isComplete: true - }; - - var testTodo2 = { - title: 'Wash the apples', - isComplete: true - }; - - var testTodo3 = { - title: 'Cut the apples', - description: 'Don\'t forget to pack them in a box', - isComplete: false - }; - - await databases.createDocument( - todoDatabase.$id, - todoCollection.$id, - sdk.ID.unique(), - testTodo1 - ); - - await databases.createDocument( - todoDatabase.$id, - todoCollection.$id, - sdk.ID.unique(), - testTodo2 - ); - - await databases.createDocument( - todoDatabase.$id, - todoCollection.$id, - sdk.ID.unique(), - testTodo3 - ); -} - async function getTodos() { var todos = await databases.listDocuments( todoDatabase.$id, @@ -286,7 +183,8 @@ runAllTasks(); ``` {% /section %} -{% section #step-9 step=9 title="Check out what you've built" %} + +{% section #step-8 step=8 title="All set" %} Run your project with `node app.js` and view the response in your console.