From b30ed546cf4d727cbcac97d053ea7f8ed1c391ae Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 18 Jan 2024 03:00:13 +0000 Subject: [PATCH 01/17] add php quickstart --- src/routes/docs/quick-starts/+page.svelte | 8 +- .../docs/quick-starts/node/+page.markdoc | 2 +- .../docs/quick-starts/php/+page.markdoc | 212 ++++++++++++++++ .../docs/quick-starts/ruby/+page.markdoc | 228 ++++++++++++++++++ 4 files changed, 448 insertions(+), 2 deletions(-) create mode 100644 src/routes/docs/quick-starts/php/+page.markdoc create mode 100644 src/routes/docs/quick-starts/ruby/+page.markdoc diff --git a/src/routes/docs/quick-starts/+page.svelte b/src/routes/docs/quick-starts/+page.svelte index 94ce6cf70b..e8d89d05f9 100644 --- a/src/routes/docs/quick-starts/+page.svelte +++ b/src/routes/docs/quick-starts/+page.svelte @@ -112,7 +112,13 @@ icon: 'icon-dart', image: '/images/blog/placeholder.png', href: 'dart' - } + }, + { + title: 'Ruby', + icon: 'icon-ruby', + image: '/images/blog/placeholder.png', + href: 'ruby' + }, ] } ]; diff --git a/src/routes/docs/quick-starts/node/+page.markdoc b/src/routes/docs/quick-starts/node/+page.markdoc index dda4237883..ec45330d23 100644 --- a/src/routes/docs/quick-starts/node/+page.markdoc +++ b/src/routes/docs/quick-starts/node/+page.markdoc @@ -194,7 +194,7 @@ async function getTodos() { } async function runAllTasks() { - await prepareDatabase(); + await prepareDatabase(); await seedDatabase(); await getTodos(); } diff --git a/src/routes/docs/quick-starts/php/+page.markdoc b/src/routes/docs/quick-starts/php/+page.markdoc new file mode 100644 index 0000000000..0019b55de8 --- /dev/null +++ b/src/routes/docs/quick-starts/php/+page.markdoc @@ -0,0 +1,212 @@ +--- +layout: article +title: Start with PHP +description: Dive into our step-by-step guide on integrating Appwrite with your PHP server backend application. Get your backend up and running quickly with this tutorial. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first PHP project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +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. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} + +| 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. + +{% /section %} +{% section #step-2 step=2 title="Create PHP project" %} +Create a PHP CLI application. + +```sh +mkdir my-app +cd my-app +composer init +``` + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the PHP Appwrite SDK. + +```sh +composer require appwrite/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. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Create a new file `index.php` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```php +setEndpoint('https://cloud.appwrite.io/v1') + ->setProject('') + ->setKey(''); +?> +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```php +$databases = new Databases($client); + +$todoDatabase = $databases->create(ID::unique(), 'TodosDB'); + +$todoCollection = $databases->createCollection( + $todoDatabase['$id'], + ID::unique(), + 'Todos' +); + +function prepareDatabase($databases, $todoDatabase, $todoCollection) { + + $databases->createStringAttribute( + $todoDatabase['$id'], + $todoCollection['$id'], + 'title', + 255, + true + ); + + $databases->createStringAttribute( + $todoDatabase['$id'], + $todoCollection['$id'], + 'description', + 255, + false, + ); + + $databases->createBooleanAttribute( + $todoDatabase['$id'], + $todoCollection['$id'], + 'isComplete', + true + ); +} +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. + +```php +function seedDatabase($databases, $todoDatabase, $todoCollection) { + $testTodo1 = [ + 'title' => 'Buy apples', + 'description' => 'At least 2KGs', + 'isComplete' => true + ]; + + $testTodo2 = [ + 'title' => 'Wash the apples', + 'isComplete' => true + ]; + + $testTodo3 = [ + 'title' => 'Cut the apples', + 'description' => 'Don\'t forget to pack them in a box', + 'isComplete' => false + ]; + + $databases->createDocument( + $todoDatabase['$id'], + $todoCollection['$id'], + ID::unique(), + $testTodo1 + ); + + $databases->createDocument( + $todoDatabase['$id'], + $todoCollection['$id'], + ID::unique(), + $testTodo2 + ); + + $databases->createDocument( + $todoDatabase['$id'], + $todoCollection['$id'], + ID::unique(), + $testTodo3 + ); +} +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +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();`. + +```php +function getTodos($databases, $todoDatabase, $todoCollection) { + $todos = $databases->listDocuments( + $todoDatabase['$id'], + $todoCollection['$id'] + ); + + foreach ($todos['documents'] as $todo) { + echo "Title: {$todo['title']}\nDescription: {$todo['description']}\nIs Todo Complete: {$todo['isComplete']}\n\n"; + } +} + +function runAllTasks($databases, $todoDatabase, $todoCollection) { + prepareDatabase($databases, $todoDatabase, $todoCollection); + seedDatabase($databases, $todoDatabase, $todoCollection); + getTodos($databases, $todoDatabase, $todoCollection); +} + +runAllTasks($databases, $todoDatabase, $todoCollection); +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with `php index.php` and view the response in your console. + +{% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/ruby/+page.markdoc b/src/routes/docs/quick-starts/ruby/+page.markdoc new file mode 100644 index 0000000000..80401651b4 --- /dev/null +++ b/src/routes/docs/quick-starts/ruby/+page.markdoc @@ -0,0 +1,228 @@ +--- +layout: article +title: Start with Ruby +description: Dive into our step-by-step guide on integrating Appwrite with your Ruby server backend application. Get your backend up and running quickly with this tutorial. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first Ruby project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +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. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} + +| 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. + +{% /section %} +{% section #step-2 step=2 title="Create Ruby project" %} +Create a Ruby CLI application. + +```sh +mkdir my-app +cd my-app +bundle init +``` + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the Ruby 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. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Create a new file `app.ruby` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```ruby +# Install the Appwrite SDK for Ruby +gem install appwrite + +# Initialize the Appwrite client +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://cloud.appwrite.io/v1') # Your Appwrite Endpoint + .set_project('') # Your project ID + .set_key('') # Your secret API key +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```ruby +# Initialize the Appwrite client +require 'appwrite' + +client = Appwrite::Client.new() + +client + .set_endpoint('https://cloud.appwrite.io/v1') # Your Appwrite Endpoint + .set_project('') # Your project ID + .set_key('') # Your secret API key + +databases = Appwrite::Database.new(client) + +todo_database = nil +todo_collection = nil + +def prepare_database + todo_database = databases.create('TodosDB') + + todo_collection = databases.create_collection( + todo_database['$id'], + 'Todos' + ) + + databases.create_attribute( + todo_database['$id'], + todo_collection['$id'], + 'title', + 'string', + 255, + true + ) + + databases.create_attribute( + todo_database['$id'], + todo_collection['$id'], + 'description', + 'string', + 255, + false, + 'This is a test description' + ) + + databases.create_attribute( + todo_database['$id'], + todo_collection['$id'], + 'isComplete', + 'boolean', + true + ) +end + +prepare_database +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. + +```ruby +def seed_database(todo_database, todo_collection) + test_todo1 = { + 'title' => 'Buy apples', + 'description' => 'At least 2KGs', + 'isComplete' => true + } + + test_todo2 = { + 'title' => 'Wash the apples', + 'isComplete' => true + } + + test_todo3 = { + 'title' => 'Cut the apples', + 'description' => 'Don\'t forget to pack them in a box', + 'isComplete' => false + } + + databases.create_document( + todo_database['$id'], + todo_collection['$id'], + SecureRandom.uuid, + test_todo1 + ) + + databases.create_document( + todo_database['$id'], + todo_collection['$id'], + SecureRandom.uuid, + test_todo2 + ) + + databases.create_document( + todo_database['$id'], + todo_collection['$id'], + SecureRandom.uuid, + test_todo3 + ) +end + +seed_database(todo_database, todo_collection) +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +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();`. + +```ruby +def get_todos(todo_database, todo_collection) + todos = databases.list_documents( + todo_database['$id'], + todo_collection['$id'] + ) + + todos['documents'].each do |todo| + puts "Title: #{todo['title']}\nDescription: #{todo['description']}\nIs Todo Complete: #{todo['isComplete']}\n\n" + end +end + +def run_all_tasks + prepare_database + seed_database + get_todos +end +run_all_tasks +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with `node app.js` and view the response in your console. + +{% /section %} \ No newline at end of file From 538e9ec2f7fe0c1bd41094403498b340653d3106 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 18 Jan 2024 03:18:05 +0000 Subject: [PATCH 02/17] Add deno --- .../docs/quick-starts/deno/+page.markdoc | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 src/routes/docs/quick-starts/deno/+page.markdoc diff --git a/src/routes/docs/quick-starts/deno/+page.markdoc b/src/routes/docs/quick-starts/deno/+page.markdoc new file mode 100644 index 0000000000..b35ff6b542 --- /dev/null +++ b/src/routes/docs/quick-starts/deno/+page.markdoc @@ -0,0 +1,216 @@ +--- +layout: article +title: Start with Deno +description: Dive into our step-by-step guide on integrating Appwrite with your Deno server backend application. Get your backend up and running quickly with this tutorial. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first Deno project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +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. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} + +| 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. + +{% /section %} +{% section #step-2 step=2 title="Create Deno project" %} +Create a Deno CLI application. + +```sh +mkdir my-app +cd my-app +echo "console.log('Hello, Deno!');" > mod.ts +``` + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the Deno 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. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Open `mod.ts` in your ID and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```ts +import { Client, ID, Databases, Models } from "https://deno.land/x/appwrite/mod.ts"; + +const client: Models.Client = new Client(); + +client + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```ts +const databases: Models.Databases = new Databases(client); + +var todoDatabase: Models.Database; +var todoCollection: Models.Collection; + +interface Todo { + title: string; + description: string; + isComplete?: boolean; +} + +async function prepareDatabase(): Promise { + todoDatabase = await databases.create( + ID.unique(), + 'TodosDB' + ); + + todoCollection = await databases.createCollection( + todoDatabase.$id, + 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="Add documents" %} +Create a function to add some mock data into your new collection. + +```ts +async function seedDatabase(): Promise { + const testTodo1: Todo = { + title: 'Buy apples', + description: 'At least 2KGs', + isComplete: true + }; + + const testTodo2: Todo = { + title: 'Wash the apples', + isComplete: true + }; + + const testTodo3: Todo = { + title: 'Cut the apples', + description: 'Don\'t forget to pack them in a box', + isComplete: false + }; + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + ID.unique(), + testTodo1 + ); + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + ID.unique(), + testTodo2 + ); + + await databases.createDocument( + todoDatabase.$id, + todoCollection.$id, + ID.unique(), + testTodo3 + ); +} +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +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();`. + +```ts +async function getTodos(): Promise { + var todos = await databases.listDocuments( + todoDatabase.$id, + todoCollection.$id + ); + + todos.documents.forEach((todo: Todo) => { + console.log(`Title: ${todo.title}\nDescription: ${todo.description}\nIs Todo Complete: ${todo.isComplete}\n\n`); + }); +} + +async function runAllTasks(): Promise { + await prepareDatabase(); + await seedDatabase(); + await getTodos(); +} +runAllTasks(); +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with `deno mod.ts` and view the response in your console. + +{% /section %} \ No newline at end of file From fa41045bfba300da9d979cb49baef12e9cba7be7 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 18 Jan 2024 22:37:18 +0000 Subject: [PATCH 03/17] Add ruby and swift --- .../docs/quick-starts/ruby/+page.markdoc | 124 ++++++------- .../docs/quick-starts/swift/+page.markdoc | 167 ++++++++++++++++++ 2 files changed, 221 insertions(+), 70 deletions(-) create mode 100644 src/routes/docs/quick-starts/swift/+page.markdoc diff --git a/src/routes/docs/quick-starts/ruby/+page.markdoc b/src/routes/docs/quick-starts/ruby/+page.markdoc index 80401651b4..95fef0cd64 100644 --- a/src/routes/docs/quick-starts/ruby/+page.markdoc +++ b/src/routes/docs/quick-starts/ruby/+page.markdoc @@ -54,7 +54,7 @@ bundle init Install the Ruby Appwrite SDK. ```sh -npm install node-appwrite +gem install appwrite ``` {% /section %} {% section #step-4 step=4 title="Import Appwrite" %} @@ -71,9 +71,6 @@ Find your project ID in the **Settings** page. Also, click on the **View API Key Create a new file `app.ruby` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. ```ruby -# Install the Appwrite SDK for Ruby -gem install appwrite - # Initialize the Appwrite client require 'appwrite' @@ -91,58 +88,47 @@ client Once the Appwrite Client is initialized, create a function to configure a todo collection. ```ruby -# Initialize the Appwrite client -require 'appwrite' - -client = Appwrite::Client.new() - -client - .set_endpoint('https://cloud.appwrite.io/v1') # Your Appwrite Endpoint - .set_project('') # Your project ID - .set_key('') # Your secret API key +@databases = Databases.new(@client) -databases = Appwrite::Database.new(client) +@todo_database = nil +@todo_collection = nil -todo_database = nil -todo_collection = nil +@todo_database = @databases.create( + database_id: ID.unique(), + name: 'TodosDB' +) +@todo_collection = @databases.create_collection( + database_id: @todo_database.id, + collection_id: ID.unique(), + name: 'Todos' +) def prepare_database - todo_database = databases.create('TodosDB') - todo_collection = databases.create_collection( - todo_database['$id'], - 'Todos' + @databases.create_string_attribute( + database_id: @todo_database.id, + collection_id: @todo_collection.id, + key: 'title', + size: 255, + required: true ) - databases.create_attribute( - todo_database['$id'], - todo_collection['$id'], - 'title', - 'string', - 255, - true + @databases.create_string_attribute( + database_id: @todo_database.id, + collection_id: @todo_collection.id, + key: 'description', + size: 255, + required: false ) - databases.create_attribute( - todo_database['$id'], - todo_collection['$id'], - 'description', - 'string', - 255, - false, - 'This is a test description' - ) - - databases.create_attribute( - todo_database['$id'], - todo_collection['$id'], - 'isComplete', - 'boolean', - true + @databases.create_boolean_attribute( + database_id: @todo_database.id, + collection_id: @todo_collection.id, + key: 'isComplete', + required: false, + default: false ) end - -prepare_database ``` {% /section %} @@ -150,7 +136,7 @@ prepare_database Create a function to add some mock data into your new collection. ```ruby -def seed_database(todo_database, todo_collection) +def seed_database() test_todo1 = { 'title' => 'Buy apples', 'description' => 'At least 2KGs', @@ -168,29 +154,27 @@ def seed_database(todo_database, todo_collection) 'isComplete' => false } - databases.create_document( - todo_database['$id'], - todo_collection['$id'], - SecureRandom.uuid, - test_todo1 + @databases.create_document( + database_id: @todo_database.id, + collection_id: @todo_collection.id, + document_id: ID.unique(), + data: test_todo1 ) - databases.create_document( - todo_database['$id'], - todo_collection['$id'], - SecureRandom.uuid, - test_todo2 + @databases.create_document( + database_id: @todo_database.id, + collection_id: @todo_collection.id, + document_id: ID.unique(), + data: test_todo2 ) - databases.create_document( - todo_database['$id'], - todo_collection['$id'], - SecureRandom.uuid, - test_todo3 + @databases.create_document( + database_id: @todo_database.id, + collection_id: @todo_collection.id, + document_id: ID.unique(), + data: test_todo3 ) end - -seed_database(todo_database, todo_collection) ``` {% /section %} @@ -200,14 +184,14 @@ Create a function to retrieve the mock todo data and a function to execute the r Run the functions to by calling `runAllTasks();`. ```ruby -def get_todos(todo_database, todo_collection) - todos = databases.list_documents( - todo_database['$id'], - todo_collection['$id'] +def get_todos + todos = @databases.list_documents( + database_id: @todo_database.id, + collection_id: @todo_collection.id ) - todos['documents'].each do |todo| - puts "Title: #{todo['title']}\nDescription: #{todo['description']}\nIs Todo Complete: #{todo['isComplete']}\n\n" + todos.documents.each do |todo| + puts "Title: #{todo.data['title']}\nDescription: #{todo.data['description']}\nIs Todo Complete: #{todo.data['isComplete']}\n\n" end end @@ -223,6 +207,6 @@ run_all_tasks {% section #step-8 step=8 title="All set" %} -Run your project with `node app.js` and view the response in your console. +Run your project with `ruby app.ruby` and view the response in your console. {% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc new file mode 100644 index 0000000000..01e3f7b999 --- /dev/null +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -0,0 +1,167 @@ +--- +layout: article +title: Start with Swift +description: Learn to get started with server integrations with Appwrite Swift SDK. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first Swift project powered by Appwrite. + +{% info title="Server SDK" %} +This tutorial is for the Swift Server SDK, meant for server and backend applications. +If you're trying to build a client-side app, like an iOS, macOS, watchOS or tvOS app, +follow the [Start with Apple guide](https://appwrite.io/docs/quick-starts/apple). +{% /info %} + +{% section #step-1 step=1 title="Create project" %} +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. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Server integrations](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Server integrations](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} +| 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. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +{% /section %} +{% section #step-2 step=2 title="Create Swift project" %} +Create a Swift CLI application by opening **XCode** > **Create a new XCode project** +> **macOS** > **Command Line Tool**. + +Follow the wizard and open your new project. + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} + +Install the Swift Appwrite SDK by going to **File** > **Add Packages...** and search for the repo url +`https://github.com/appwrite/sdk-for-swift` and select `sdk-for-swift`. + +{% /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. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Open the file `main.swift` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```swift +import Foundation +import Appwrite + +let client = Client() +client.setEndpoint("https://cloud.appwrite.io/v1") +client.setProject("") +client.setKey("") +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```swift +let databases = Databases(client) + +var todoDatabase: Database? +var todoCollection: Collection? + +todoDatabase = try? await databases.create(databaseId: ID.unique(), name: "TodosDB") +todoCollection = try? await databases.createCollection(databaseId: todoDatabase!.id, collectionId: ID.unique(), name: "Todos") + +func prepareDatabase() async { + + try? await databases.createStringAttribute(databaseId: todoDatabase!.id, collectionId: todoCollection!.id, key: "title", size: 255, xrequired: true) + try? await databases.createStringAttribute(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, key: "description", size: 255, xrequired: false, xdefault: "This is a test description.") + try? await databases.createBooleanAttribute(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, key: "isComplete", xrequired: true) +} +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. +```swift +func seedDatabase() async { + let testTodo1: [String: Any] = [ + "title": "Buy apples", + "description": "At least 2KGs", + "isComplete": true + ] + + let testTodo2: [String: Any] = [ + "title": "Wash the apples", + "isComplete": true + ] + + let testTodo3: [String: Any] = [ + "title": "Cut the apples", + "description": "Don't forget to pack them in a box", + "isComplete": false + ] + + try? await databases.createDocument(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, documentId: UUID().uuidString, data: testTodo1) + try? await databases.createDocument(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, documentId: UUID().uuidString, data: testTodo2) + try? await databases.createDocument(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, documentId: UUID().uuidString, data: testTodo3) +} +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +Create a function to retrieve the mock todo data. + +```swift +func getTodos() async { + let todos = try? await databases.listDocuments(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String) + for document in todos?.documents ?? [] { + if let todo = document.data as? [String: Any] { + print("Title: \(todo["title"] ?? "")\nDescription: \(todo["description"] ?? "")\nIs Todo Complete: \(todo["isComplete"] ?? "")\n\n") + } + } +} + +await prepareDatabase() +await seedDatabase() +await getTodos() +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with XCode and see the results in the console. + +{% /section %} \ No newline at end of file From 6091acf5d8ef4c240fdc02d9e1a2afe4931f785f Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 18 Jan 2024 23:04:15 +0000 Subject: [PATCH 04/17] Add server quickstarts --- .../docs/quick-starts/kotlin/+page.markdoc | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/routes/docs/quick-starts/kotlin/+page.markdoc diff --git a/src/routes/docs/quick-starts/kotlin/+page.markdoc b/src/routes/docs/quick-starts/kotlin/+page.markdoc new file mode 100644 index 0000000000..db7df6bee4 --- /dev/null +++ b/src/routes/docs/quick-starts/kotlin/+page.markdoc @@ -0,0 +1,173 @@ +--- +layout: article +title: Start with Kotlin +description: Learn to get started with server integrations with Appwrite Kotlin SDK. +difficulty: beginner +readtime: 5 +back: /docs/quick-starts +--- +Learn how to setup your first Kotlin project powered by Appwrite. +{% section #step-1 step=1 title="Create project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). + +{% info title="Server SDK" %} +This tutorial is for the Swift Server SDK, meant for server and backend applications. +If you're trying to build a client-side app, like an Android app, +follow the [Start with Android guide](https://appwrite.io/docs/quick-starts/android). +{% /info %} + +If this is your first time using Appwrite, create an account and create your first project. + +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} + +Then, under **Integrate with your server**, add an **API Key** with the following scopes. + +{% only_dark %} +![Server integrations](/images/docs/quick-starts/dark/integrate-server.png) +{% /only_dark %} +{% only_light %} +![Server integrations](/images/docs/quick-starts/integrate-server.png) +{% /only_light %} +| 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. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +{% /section %} +{% section #step-2 step=2 title="Create Kotlin project" %} +Create a Kotlin application by opening **IntelliJ IDEA** > **New Project** and create a **Kotlin** application. +This quick start will use **Gradle** as the build system, but you can follow with Maven or IntelliJ if you're more comfortable. + +Follow the wizard and open your new project. + +{% /section %} +{% section #step-3 step=3 title="Install Appwrite" %} +Open you `build.gradle.kts` file and implement the following dependency. + +```groovy +dependencies { + ... other dependencies + implementation("io.appwrite:sdk-for-kotlin:4.1.0") +} +``` + +{% /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. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Open the file `Main.kt` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. + +```kotlin +import io.appwrite.Client +import io.appwrite.services.Databases +import io.appwrite.models.Database as DatabaseModel +import io.appwrite.models.Collection +import kotlinx.coroutines.runBlocking +import java.util.UUID +val client = Client() + .SetEndpoint("https://cloud.appwrite.io/v1") + .SetProject("") + .SetKey(""); +``` + +{% /section %} +{% section #step-5 step=5 title="Initialize database" %} + +Once the Appwrite Client is initialized, create a function to configure a todo collection. + +```kotlin +val databases = Databases(client) + +var todoDatabase: DatabaseModel? = null +var todoCollection: Collection? = null + +fun prepareDatabase() = runBlocking { + todoDatabase = databases.create(UUID.randomUUID().toString(), "TodosDB") + todoCollection = databases.createCollection(todoDatabase?.id!!, UUID.randomUUID().toString(), "Todos") + + databases.createStringAttribute(todoDatabase?.id!!, todoCollection?.id!!, "title", 255, true) + databases.createStringAttribute(todoDatabase?.id!!, todoCollection?.id!!, "description", 255, false, "This is a test description.") + databases.createBooleanAttribute(todoDatabase?.id!!, todoCollection?.id!!, "isComplete", true) +} +``` + +{% /section %} +{% section #step-6 step=6 title="Add documents" %} +Create a function to add some mock data into your new collection. +```kotlin +fun seedDatabase() = runBlocking { + val testTodo1 = mapOf( + "title" to "Buy apples", + "description" to "At least 2KGs", + "isComplete" to true + ) + + val testTodo2 = mapOf( + "title" to "Wash the apples", + "isComplete" to true + ) + + val testTodo3 = mapOf( + "title" to "Cut the apples", + "description" to "Don't forget to pack them in a box", + "isComplete" to false + ) + + databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, UUID.randomUUID().toString(), testTodo1) + databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, UUID.randomUUID().toString(), testTodo2) + databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, UUID.randomUUID().toString(), testTodo3) +} +``` + +{% /section %} +{% section #step-7 step=7 title="Retrieve documents" %} + +Create a function to retrieve the mock todo data. + +```kotlin +fun getTodos() = runBlocking { + val todos = databases.listDocuments(todoDatabase?.id!!, todoCollection?.id!!) + for (todo in todos.documents) { + println("Title: ${todo.data["title"]}\nDescription: ${todo.data["description"]}\nIs Todo Complete: ${todo.data["isComplete"]}\n\n") + } +} + +fun main() { + prepareDatabase() + seedDatabase() + getTodos() +} +``` + +{% /section %} + +{% section #step-8 step=8 title="All set" %} + +Run your project with IntelliJ and view the response in your console. + +{% /section %} \ No newline at end of file From 9feebbc7035c900139d4907956f82e8e7e93bd2b Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Mon, 22 Jan 2024 17:25:42 -0500 Subject: [PATCH 05/17] Update src/routes/docs/quick-starts/kotlin/+page.markdoc Co-authored-by: Damodar Lohani --- src/routes/docs/quick-starts/kotlin/+page.markdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/docs/quick-starts/kotlin/+page.markdoc b/src/routes/docs/quick-starts/kotlin/+page.markdoc index db7df6bee4..db57bfe07b 100644 --- a/src/routes/docs/quick-starts/kotlin/+page.markdoc +++ b/src/routes/docs/quick-starts/kotlin/+page.markdoc @@ -107,7 +107,7 @@ var todoDatabase: DatabaseModel? = null var todoCollection: Collection? = null fun prepareDatabase() = runBlocking { - todoDatabase = databases.create(UUID.randomUUID().toString(), "TodosDB") + todoDatabase = databases.create(ID.unique(), "TodosDB") todoCollection = databases.createCollection(todoDatabase?.id!!, UUID.randomUUID().toString(), "Todos") databases.createStringAttribute(todoDatabase?.id!!, todoCollection?.id!!, "title", 255, true) From daaa259bccf5450f84a304f4be1c40a7c82eb160 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Mon, 22 Jan 2024 17:26:06 -0500 Subject: [PATCH 06/17] Update src/routes/docs/quick-starts/node/+page.markdoc Co-authored-by: Damodar Lohani --- src/routes/docs/quick-starts/node/+page.markdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/docs/quick-starts/node/+page.markdoc b/src/routes/docs/quick-starts/node/+page.markdoc index ec45330d23..dda4237883 100644 --- a/src/routes/docs/quick-starts/node/+page.markdoc +++ b/src/routes/docs/quick-starts/node/+page.markdoc @@ -194,7 +194,7 @@ async function getTodos() { } async function runAllTasks() { - await prepareDatabase(); + await prepareDatabase(); await seedDatabase(); await getTodos(); } From 7562a74273b399abc7ae6dce25731214edb695cf Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Mon, 22 Jan 2024 22:33:43 +0000 Subject: [PATCH 07/17] Fix misuse of UUID instead of ID.unique() --- src/routes/docs/quick-starts/kotlin/+page.markdoc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/routes/docs/quick-starts/kotlin/+page.markdoc b/src/routes/docs/quick-starts/kotlin/+page.markdoc index db57bfe07b..9b22dadcd5 100644 --- a/src/routes/docs/quick-starts/kotlin/+page.markdoc +++ b/src/routes/docs/quick-starts/kotlin/+page.markdoc @@ -84,11 +84,11 @@ Open the file `Main.kt` and initialize the Appwrite Client. Replace `") @@ -103,12 +103,12 @@ Once the Appwrite Client is initialized, create a function to configure a todo c ```kotlin val databases = Databases(client) -var todoDatabase: DatabaseModel? = null +var todoDatabase: Database? = null var todoCollection: Collection? = null fun prepareDatabase() = runBlocking { todoDatabase = databases.create(ID.unique(), "TodosDB") - todoCollection = databases.createCollection(todoDatabase?.id!!, UUID.randomUUID().toString(), "Todos") + todoCollection = databases.createCollection(todoDatabase?.id!!, ID.unique(), "Todos") databases.createStringAttribute(todoDatabase?.id!!, todoCollection?.id!!, "title", 255, true) databases.createStringAttribute(todoDatabase?.id!!, todoCollection?.id!!, "description", 255, false, "This is a test description.") @@ -138,9 +138,9 @@ fun seedDatabase() = runBlocking { "isComplete" to false ) - databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, UUID.randomUUID().toString(), testTodo1) - databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, UUID.randomUUID().toString(), testTodo2) - databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, UUID.randomUUID().toString(), testTodo3) + databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, ID.unique(), testTodo1) + databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, ID.unique(), testTodo2) + databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, ID.unique(), testTodo3) } ``` From b6606f7cfca83612f239b59b2ddfe45decdfe6c6 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 25 Jan 2024 00:53:02 -0500 Subject: [PATCH 08/17] Update src/routes/docs/quick-starts/deno/+page.markdoc Co-authored-by: Jake Barnby --- src/routes/docs/quick-starts/deno/+page.markdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/docs/quick-starts/deno/+page.markdoc b/src/routes/docs/quick-starts/deno/+page.markdoc index b35ff6b542..a5e22a5ccd 100644 --- a/src/routes/docs/quick-starts/deno/+page.markdoc +++ b/src/routes/docs/quick-starts/deno/+page.markdoc @@ -68,7 +68,7 @@ Find your project ID in the **Settings** page. Also, click on the **View API Key ![Project settings screen](/images/docs/quick-starts/project-id.png) {% /only_light %} -Open `mod.ts` in your ID and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. +Open `mod.ts` in your IDE and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. ```ts import { Client, ID, Databases, Models } from "https://deno.land/x/appwrite/mod.ts"; From 27facc4732a3aea8f992f7a3f32a0822bdf3a231 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 25 Jan 2024 00:53:36 -0500 Subject: [PATCH 09/17] Update src/routes/docs/quick-starts/swift/+page.markdoc Co-authored-by: Jake Barnby --- src/routes/docs/quick-starts/swift/+page.markdoc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc index 01e3f7b999..a503d07cc6 100644 --- a/src/routes/docs/quick-starts/swift/+page.markdoc +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -103,7 +103,6 @@ todoDatabase = try? await databases.create(databaseId: ID.unique(), name: "Todos todoCollection = try? await databases.createCollection(databaseId: todoDatabase!.id, collectionId: ID.unique(), name: "Todos") func prepareDatabase() async { - try? await databases.createStringAttribute(databaseId: todoDatabase!.id, collectionId: todoCollection!.id, key: "title", size: 255, xrequired: true) try? await databases.createStringAttribute(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, key: "description", size: 255, xrequired: false, xdefault: "This is a test description.") try? await databases.createBooleanAttribute(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, key: "isComplete", xrequired: true) From cf1b9a7956907de67b73ad2b2c0d0a39ad9bb96a Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 25 Jan 2024 00:56:15 -0500 Subject: [PATCH 10/17] Apply suggestions from code review Co-authored-by: Jake Barnby Co-authored-by: Damodar Lohani --- .../docs/quick-starts/deno/+page.markdoc | 4 +-- .../docs/quick-starts/kotlin/+page.markdoc | 30 ++++++++++--------- .../docs/quick-starts/php/+page.markdoc | 3 +- .../docs/quick-starts/ruby/+page.markdoc | 20 +++++++------ .../docs/quick-starts/swift/+page.markdoc | 6 ++-- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/routes/docs/quick-starts/deno/+page.markdoc b/src/routes/docs/quick-starts/deno/+page.markdoc index a5e22a5ccd..860642e7ff 100644 --- a/src/routes/docs/quick-starts/deno/+page.markdoc +++ b/src/routes/docs/quick-starts/deno/+page.markdoc @@ -73,7 +73,7 @@ Open `mod.ts` in your IDE and initialize the Appwrite Client. Replace ` **New Project** and create a **Kotlin** application. -This quick start will use **Gradle** as the build system, but you can follow with Maven or IntelliJ if you're more comfortable. +This quick start will use **Gradle** as the build system, with the Kotlin DSL. You can follow with Maven or IntelliJ if you're more comfortable. Follow the wizard and open your new project. {% /section %} {% section #step-3 step=3 title="Install Appwrite" %} -Open you `build.gradle.kts` file and implement the following dependency. +Open your `build.gradle.kts` file and implement the following dependency. ```groovy dependencies { @@ -88,11 +88,11 @@ import io.appwrite.ID import io.appwrite.services.Databases import io.appwrite.models.Database as Database import io.appwrite.models.Collection -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.coroutineScope val client = Client() - .SetEndpoint("https://cloud.appwrite.io/v1") - .SetProject("") - .SetKey(""); + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey(""); ``` {% /section %} @@ -106,7 +106,7 @@ val databases = Databases(client) var todoDatabase: Database? = null var todoCollection: Collection? = null -fun prepareDatabase() = runBlocking { +suspend fun prepareDatabase() { todoDatabase = databases.create(ID.unique(), "TodosDB") todoCollection = databases.createCollection(todoDatabase?.id!!, ID.unique(), "Todos") @@ -120,7 +120,7 @@ fun prepareDatabase() = runBlocking { {% section #step-6 step=6 title="Add documents" %} Create a function to add some mock data into your new collection. ```kotlin -fun seedDatabase() = runBlocking { +suspend fun seedDatabase() { val testTodo1 = mapOf( "title" to "Buy apples", "description" to "At least 2KGs", @@ -150,17 +150,19 @@ fun seedDatabase() = runBlocking { Create a function to retrieve the mock todo data. ```kotlin -fun getTodos() = runBlocking { +suspend fun getTodos() { val todos = databases.listDocuments(todoDatabase?.id!!, todoCollection?.id!!) for (todo in todos.documents) { println("Title: ${todo.data["title"]}\nDescription: ${todo.data["description"]}\nIs Todo Complete: ${todo.data["isComplete"]}\n\n") } } -fun main() { - prepareDatabase() - seedDatabase() - getTodos() +suspend fun main() = coroutineScope { + launch { + prepareDatabase() + seedDatabase() + getTodos() + } } ``` diff --git a/src/routes/docs/quick-starts/php/+page.markdoc b/src/routes/docs/quick-starts/php/+page.markdoc index 0019b55de8..958ad7a0d7 100644 --- a/src/routes/docs/quick-starts/php/+page.markdoc +++ b/src/routes/docs/quick-starts/php/+page.markdoc @@ -72,7 +72,7 @@ Create a new file `index.php` and initialize the Appwrite Client. Replace `setEndpoint('https://cloud.appwrite.io/v1') ->setProject('') ->setKey(''); -?> ``` {% /section %} diff --git a/src/routes/docs/quick-starts/ruby/+page.markdoc b/src/routes/docs/quick-starts/ruby/+page.markdoc index 95fef0cd64..c9f7865ec8 100644 --- a/src/routes/docs/quick-starts/ruby/+page.markdoc +++ b/src/routes/docs/quick-starts/ruby/+page.markdoc @@ -54,7 +54,7 @@ bundle init Install the Ruby Appwrite SDK. ```sh -gem install appwrite +bundle add appwrite ``` {% /section %} {% section #step-4 step=4 title="Import Appwrite" %} @@ -68,13 +68,15 @@ Find your project ID in the **Settings** page. Also, click on the **View API Key ![Project settings screen](/images/docs/quick-starts/project-id.png) {% /only_light %} -Create a new file `app.ruby` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. +Create a new file `app.rb` and initialize the Appwrite Client. Replace `` with your project ID and `` with your API key. ```ruby # Initialize the Appwrite client require 'appwrite' -client = Appwrite::Client.new() +include Appwrite + +client = Client.new() client .set_endpoint('https://cloud.appwrite.io/v1') # Your Appwrite Endpoint @@ -88,7 +90,7 @@ client Once the Appwrite Client is initialized, create a function to configure a todo collection. ```ruby -@databases = Databases.new(@client) +databases = Databases.new(client) @todo_database = nil @todo_collection = nil @@ -138,9 +140,9 @@ Create a function to add some mock data into your new collection. ```ruby def seed_database() test_todo1 = { - 'title' => 'Buy apples', - 'description' => 'At least 2KGs', - 'isComplete' => true + title: 'Buy apples', + description: 'At least 2KGs', + isComplete: true } test_todo2 = { @@ -181,7 +183,7 @@ end {% section #step-7 step=7 title="Retrieve documents" %} 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();`. +Run the functions to by calling `run_all_tasks()`. ```ruby def get_todos @@ -207,6 +209,6 @@ run_all_tasks {% section #step-8 step=8 title="All set" %} -Run your project with `ruby app.ruby` and view the response in your console. +Run your project with `ruby app.rb` and view the response in your console. {% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc index a503d07cc6..120480d519 100644 --- a/src/routes/docs/quick-starts/swift/+page.markdoc +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -83,9 +83,9 @@ import Foundation import Appwrite let client = Client() -client.setEndpoint("https://cloud.appwrite.io/v1") -client.setProject("") -client.setKey("") + .setEndpoint("https://cloud.appwrite.io/v1") + .setProject("") + .setKey("") ``` {% /section %} From 4834ffdbeda6f56a75cb28ac2bf10b2940f5d2a5 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 25 Jan 2024 06:50:53 +0000 Subject: [PATCH 11/17] Fix Ruby + Fix permission tables --- src/routes/docs/quick-starts/+page.svelte | 24 ++++++++++++ .../docs/quick-starts/dart/+page.markdoc | 4 +- .../docs/quick-starts/deno/+page.markdoc | 15 +++++--- .../docs/quick-starts/dotnet/+page.markdoc | 4 +- .../docs/quick-starts/kotlin/+page.markdoc | 4 +- .../docs/quick-starts/node/+page.markdoc | 4 +- .../docs/quick-starts/php/+page.markdoc | 4 +- .../docs/quick-starts/python/+page.markdoc | 4 +- .../docs/quick-starts/ruby/+page.markdoc | 38 +++++++++---------- .../docs/quick-starts/swift/+page.markdoc | 4 +- 10 files changed, 67 insertions(+), 38 deletions(-) diff --git a/src/routes/docs/quick-starts/+page.svelte b/src/routes/docs/quick-starts/+page.svelte index e8d89d05f9..bb9e1d826a 100644 --- a/src/routes/docs/quick-starts/+page.svelte +++ b/src/routes/docs/quick-starts/+page.svelte @@ -119,6 +119,30 @@ image: '/images/blog/placeholder.png', href: 'ruby' }, + { + title: 'Deno', + icon: 'icon-deno', + image: '/images/blog/placeholder.png', + href: 'ruby' + }, + { + title: 'PHP', + icon: 'icon-php', + image: '/images/blog/placeholder.png', + href: 'ruby' + }, + { + title: 'Kotlin', + icon: 'icon-kotlin', + image: '/images/blog/placeholder.png', + href: 'ruby' + }, + { + title: 'Swift', + icon: 'icon-swift', + image: '/images/blog/placeholder.png', + href: 'ruby' + }, ] } ]; diff --git a/src/routes/docs/quick-starts/dart/+page.markdoc b/src/routes/docs/quick-starts/dart/+page.markdoc index a289ea48ce..ffb4fbbc64 100644 --- a/src/routes/docs/quick-starts/dart/+page.markdoc +++ b/src/routes/docs/quick-starts/dart/+page.markdoc @@ -24,8 +24,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/deno/+page.markdoc b/src/routes/docs/quick-starts/deno/+page.markdoc index 860642e7ff..ee8d122ed8 100644 --- a/src/routes/docs/quick-starts/deno/+page.markdoc +++ b/src/routes/docs/quick-starts/deno/+page.markdoc @@ -33,8 +33,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. @@ -51,11 +51,16 @@ echo "console.log('Hello, Deno!');" > mod.ts {% /section %} {% section #step-3 step=3 title="Install Appwrite" %} -Install the Deno Appwrite SDK. +Install the Deno Appwrite SDK by importing it `deno.land/x` at the top of your file. -```sh -npm install node-appwrite ``` +// import all as sdk +import * as sdk from "https://deno.land/x/appwrite/mod.ts"; + +// import only what you need +import { Client, ... other imports } from "https://deno.land/x/appwrite/mod.ts"; +``` + {% /section %} {% section #step-4 step=4 title="Import Appwrite" %} diff --git a/src/routes/docs/quick-starts/dotnet/+page.markdoc b/src/routes/docs/quick-starts/dotnet/+page.markdoc index d16f6b4970..15e75b5ac5 100644 --- a/src/routes/docs/quick-starts/dotnet/+page.markdoc +++ b/src/routes/docs/quick-starts/dotnet/+page.markdoc @@ -32,8 +32,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/kotlin/+page.markdoc b/src/routes/docs/quick-starts/kotlin/+page.markdoc index 37756482c9..cb589abe05 100644 --- a/src/routes/docs/quick-starts/kotlin/+page.markdoc +++ b/src/routes/docs/quick-starts/kotlin/+page.markdoc @@ -38,8 +38,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/node/+page.markdoc b/src/routes/docs/quick-starts/node/+page.markdoc index dda4237883..0a4585eb3c 100644 --- a/src/routes/docs/quick-starts/node/+page.markdoc +++ b/src/routes/docs/quick-starts/node/+page.markdoc @@ -33,8 +33,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/php/+page.markdoc b/src/routes/docs/quick-starts/php/+page.markdoc index 958ad7a0d7..925437e65c 100644 --- a/src/routes/docs/quick-starts/php/+page.markdoc +++ b/src/routes/docs/quick-starts/php/+page.markdoc @@ -33,8 +33,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/python/+page.markdoc b/src/routes/docs/quick-starts/python/+page.markdoc index bda9228ede..94cb68c900 100644 --- a/src/routes/docs/quick-starts/python/+page.markdoc +++ b/src/routes/docs/quick-starts/python/+page.markdoc @@ -33,8 +33,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. diff --git a/src/routes/docs/quick-starts/ruby/+page.markdoc b/src/routes/docs/quick-starts/ruby/+page.markdoc index c9f7865ec8..1d56812907 100644 --- a/src/routes/docs/quick-starts/ruby/+page.markdoc +++ b/src/routes/docs/quick-starts/ruby/+page.markdoc @@ -33,8 +33,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. @@ -95,17 +95,17 @@ databases = Databases.new(client) @todo_database = nil @todo_collection = nil -@todo_database = @databases.create( - database_id: ID.unique(), - name: 'TodosDB' -) -@todo_collection = @databases.create_collection( - database_id: @todo_database.id, - collection_id: ID.unique(), - name: 'Todos' -) - def prepare_database + @todo_database = @databases.create( + database_id: ID.unique(), + name: 'TodosDB' + ) + + @todo_collection = @databases.create_collection( + database_id: @todo_database.id, + collection_id: ID.unique(), + name: 'Todos' + ) @databases.create_string_attribute( database_id: @todo_database.id, @@ -146,14 +146,14 @@ def seed_database() } test_todo2 = { - 'title' => 'Wash the apples', - 'isComplete' => true + title: 'Wash the apples', + isComplete: true } test_todo3 = { - 'title' => 'Cut the apples', - 'description' => 'Don\'t forget to pack them in a box', - 'isComplete' => false + title: 'Cut the apples', + description: 'Don\'t forget to pack them in a box', + 'isComplete: false } @databases.create_document( @@ -183,7 +183,7 @@ end {% section #step-7 step=7 title="Retrieve documents" %} Create a function to retrieve the mock todo data and a function to execute the requests in order. -Run the functions to by calling `run_all_tasks()`. +Run the functions to by calling `run_all_tasks()`. ```ruby def get_todos @@ -209,6 +209,6 @@ run_all_tasks {% section #step-8 step=8 title="All set" %} -Run your project with `ruby app.rb` and view the response in your console. +Run your project with `ruby app.rb` and view the response in your console. {% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc index 120480d519..a0be361054 100644 --- a/src/routes/docs/quick-starts/swift/+page.markdoc +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -39,8 +39,8 @@ Then, under **Integrate with your server**, add an **API Key** with the followin | 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). | +| | `documents.read` | Allows API key to read [documents](/docs/products/databases/documents). | +| | `documents.write` | Allows API key to create, update, and delete [documents](/docs/products/databases/documents). | Other scopes are optional. From 7a77930a49a227629d5b4d129eb12d69b63e92c6 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Thu, 25 Jan 2024 23:06:51 +0000 Subject: [PATCH 12/17] Use named params + address review comments --- src/routes/docs/quick-starts/+page.svelte | 8 +-- .../docs/quick-starts/kotlin/+page.markdoc | 64 +++++++++++++++---- .../docs/quick-starts/php/+page.markdoc | 62 ++++++++++-------- .../docs/quick-starts/swift/+page.markdoc | 59 ++++++++++++++--- 4 files changed, 140 insertions(+), 53 deletions(-) diff --git a/src/routes/docs/quick-starts/+page.svelte b/src/routes/docs/quick-starts/+page.svelte index bb9e1d826a..c4509bb4ff 100644 --- a/src/routes/docs/quick-starts/+page.svelte +++ b/src/routes/docs/quick-starts/+page.svelte @@ -123,25 +123,25 @@ title: 'Deno', icon: 'icon-deno', image: '/images/blog/placeholder.png', - href: 'ruby' + href: 'deno' }, { title: 'PHP', icon: 'icon-php', image: '/images/blog/placeholder.png', - href: 'ruby' + href: 'php' }, { title: 'Kotlin', icon: 'icon-kotlin', image: '/images/blog/placeholder.png', - href: 'ruby' + href: 'kotlin' }, { title: 'Swift', icon: 'icon-swift', image: '/images/blog/placeholder.png', - href: 'ruby' + href: 'swift' }, ] } diff --git a/src/routes/docs/quick-starts/kotlin/+page.markdoc b/src/routes/docs/quick-starts/kotlin/+page.markdoc index cb589abe05..95d060ad73 100644 --- a/src/routes/docs/quick-starts/kotlin/+page.markdoc +++ b/src/routes/docs/quick-starts/kotlin/+page.markdoc @@ -110,9 +110,29 @@ suspend fun prepareDatabase() { todoDatabase = databases.create(ID.unique(), "TodosDB") todoCollection = databases.createCollection(todoDatabase?.id!!, ID.unique(), "Todos") - databases.createStringAttribute(todoDatabase?.id!!, todoCollection?.id!!, "title", 255, true) - databases.createStringAttribute(todoDatabase?.id!!, todoCollection?.id!!, "description", 255, false, "This is a test description.") - databases.createBooleanAttribute(todoDatabase?.id!!, todoCollection?.id!!, "isComplete", true) + databases.createStringAttribute( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + key = "title", + size = 255, + required = true + ) + + databases.createStringAttribute( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + key = "description", + size = 255, + required = false, + default = "This is a test description." + ) + + databases.createBooleanAttribute( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + key = "isComplete", + required = true + ) } ``` @@ -138,9 +158,26 @@ suspend fun seedDatabase() { "isComplete" to false ) - databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, ID.unique(), testTodo1) - databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, ID.unique(), testTodo2) - databases.createDocument(todoDatabase?.id!!, todoCollection?.id!!, ID.unique(), testTodo3) + databases.createDocument( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + documentId = ID.unique(), + data = testTodo1 + ) + + databases.createDocument( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + documentId = ID.unique(), + data = testTodo2 + ) + + databases.createDocument( + databaseId = todoDatabase?.id!!, + collectionId = todoCollection?.id!!, + documentId = ID.unique(), + data = testTodo3 + ) } ``` @@ -153,16 +190,19 @@ Create a function to retrieve the mock todo data. suspend fun getTodos() { val todos = databases.listDocuments(todoDatabase?.id!!, todoCollection?.id!!) for (todo in todos.documents) { - println("Title: ${todo.data["title"]}\nDescription: ${todo.data["description"]}\nIs Todo Complete: ${todo.data["isComplete"]}\n\n") + println(""" + Title: ${todo.data["title"]} + Description: ${todo.data["description"]} + Is Todo Complete: ${todo.data["isComplete"]} + + """.trimIndent()) } } suspend fun main() = coroutineScope { - launch { - prepareDatabase() - seedDatabase() - getTodos() - } + prepareDatabase() + seedDatabase() + getTodos() } ``` diff --git a/src/routes/docs/quick-starts/php/+page.markdoc b/src/routes/docs/quick-starts/php/+page.markdoc index 925437e65c..36435c9b3f 100644 --- a/src/routes/docs/quick-starts/php/+page.markdoc +++ b/src/routes/docs/quick-starts/php/+page.markdoc @@ -94,38 +94,42 @@ Once the Appwrite Client is initialized, create a function to configure a todo c ```php $databases = new Databases($client); -$todoDatabase = $databases->create(ID::unique(), 'TodosDB'); - -$todoCollection = $databases->createCollection( - $todoDatabase['$id'], - ID::unique(), - 'Todos' -); +function prepareDatabase($databases) { + $todoDatabase = $databases->create( + databaseId: ID::unique(), + name: 'TodosDB' + ); -function prepareDatabase($databases, $todoDatabase, $todoCollection) { + $todoCollection = $databases->createCollection( + databaseId: $todoDatabase['$id'], + collectionId: ID::unique(), + name: 'Todos' + ); $databases->createStringAttribute( - $todoDatabase['$id'], - $todoCollection['$id'], - 'title', - 255, - true + databaseId: $todoDatabase['$id'], + collectionId: $todoCollection['$id'], + key: 'title', + size: 255, + required: true ); $databases->createStringAttribute( - $todoDatabase['$id'], - $todoCollection['$id'], - 'description', - 255, - false, + databaseId: $todoDatabase['$id'], + collectionId: $todoCollection['$id'], + key: 'description', + size: 255, + required: false, ); $databases->createBooleanAttribute( - $todoDatabase['$id'], - $todoCollection['$id'], - 'isComplete', - true + databaseId: $todoDatabase['$id'], + collectionId: $todoCollection['$id'], + key: 'isComplete', + required: true ); + + return [$todoDatabase, $todoCollection]; } ``` @@ -189,23 +193,25 @@ function getTodos($databases, $todoDatabase, $todoCollection) { ); foreach ($todos['documents'] as $todo) { - echo "Title: {$todo['title']}\nDescription: {$todo['description']}\nIs Todo Complete: {$todo['isComplete']}\n\n"; - } + echo "Title: {$todo['title']}\n" . + "Description: {$todo['description']}\n" . + "Is Todo Complete: {$todo['isComplete']}\n\n"; + } } -function runAllTasks($databases, $todoDatabase, $todoCollection) { - prepareDatabase($databases, $todoDatabase, $todoCollection); +function runAllTasks($databases) { + [$todoDatabase, $todoCollection] = prepareDatabase($databases); seedDatabase($databases, $todoDatabase, $todoCollection); getTodos($databases, $todoDatabase, $todoCollection); } -runAllTasks($databases, $todoDatabase, $todoCollection); +runAllTasks($databases); ``` {% /section %} {% section #step-8 step=8 title="All set" %} -Run your project with `php index.php` and view the response in your console. +Run your project with `php src/index.php` and view the response in your console. {% /section %} \ No newline at end of file diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc index a0be361054..f134f5ecf0 100644 --- a/src/routes/docs/quick-starts/swift/+page.markdoc +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -99,13 +99,38 @@ let databases = Databases(client) var todoDatabase: Database? var todoCollection: Collection? -todoDatabase = try? await databases.create(databaseId: ID.unique(), name: "TodosDB") -todoCollection = try? await databases.createCollection(databaseId: todoDatabase!.id, collectionId: ID.unique(), name: "Todos") +todoDatabase = try? await databases.create( + databaseId: ID.unique(), + name: "TodosDB" +) +todoCollection = try? await databases.createCollection( + databaseId: todoDatabase!.id, + collectionId: ID.unique(), + name: "Todos" +) func prepareDatabase() async { - try? await databases.createStringAttribute(databaseId: todoDatabase!.id, collectionId: todoCollection!.id, key: "title", size: 255, xrequired: true) - try? await databases.createStringAttribute(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, key: "description", size: 255, xrequired: false, xdefault: "This is a test description.") - try? await databases.createBooleanAttribute(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, key: "isComplete", xrequired: true) + try? await databases.createStringAttribute( + databaseId: todoDatabase!.id, + collectionId: todoCollection!.id, + key: "title", + size: 255, + xrequired: true + ) + try? await databases.createStringAttribute( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String, + key: "description", + size: 255, + xrequired: false, + xdefault: "This is a test description." + ) + try? await databases.createBooleanAttribute( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String, + key: "isComplete", + xrequired: true + ) } ``` @@ -131,9 +156,22 @@ func seedDatabase() async { "isComplete": false ] - try? await databases.createDocument(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, documentId: UUID().uuidString, data: testTodo1) - try? await databases.createDocument(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, documentId: UUID().uuidString, data: testTodo2) - try? await databases.createDocument(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String, documentId: UUID().uuidString, data: testTodo3) + try? await databases.createDocument( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String, + documentId: ID.unique(), data: testTodo1 + ) + try? await databases.createDocument( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String, + documentId: ID.unique(), data: testTodo2 + ) + try? await databases.createDocument( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String, + documentId: ID.unique(), + data: testTodo3 + ) } ``` @@ -147,7 +185,10 @@ func getTodos() async { let todos = try? await databases.listDocuments(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String) for document in todos?.documents ?? [] { if let todo = document.data as? [String: Any] { - print("Title: \(todo["title"] ?? "")\nDescription: \(todo["description"] ?? "")\nIs Todo Complete: \(todo["isComplete"] ?? "")\n\n") + print("Title: \(todo["title"] ?? "")\n" + + "Description: \(todo["description"] ?? "")\n" + + "Is Todo Complete: \(todo["isComplete"] ?? "")\n\n" + ) } } } From 8748dc25054ca5af7d25fd278a3756b38b9e44e7 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Fri, 26 Jan 2024 10:08:38 -0500 Subject: [PATCH 13/17] Apply suggestions from code review Co-authored-by: Jake Barnby --- src/routes/docs/quick-starts/deno/+page.markdoc | 2 +- src/routes/docs/quick-starts/kotlin/+page.markdoc | 14 ++++++++------ src/routes/docs/quick-starts/php/+page.markdoc | 2 +- src/routes/docs/quick-starts/swift/+page.markdoc | 1 + 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/routes/docs/quick-starts/deno/+page.markdoc b/src/routes/docs/quick-starts/deno/+page.markdoc index ee8d122ed8..0f8737a6c6 100644 --- a/src/routes/docs/quick-starts/deno/+page.markdoc +++ b/src/routes/docs/quick-starts/deno/+page.markdoc @@ -194,7 +194,7 @@ Run the functions to by calling `runAllTasks();`. ```ts async function getTodos(): Promise { - var todos = await databases.listDocuments( + const todos = await databases.listDocuments( todoDatabase.$id, todoCollection.$id ); diff --git a/src/routes/docs/quick-starts/kotlin/+page.markdoc b/src/routes/docs/quick-starts/kotlin/+page.markdoc index 95d060ad73..894cae8203 100644 --- a/src/routes/docs/quick-starts/kotlin/+page.markdoc +++ b/src/routes/docs/quick-starts/kotlin/+page.markdoc @@ -89,6 +89,7 @@ import io.appwrite.services.Databases import io.appwrite.models.Database as Database import io.appwrite.models.Collection import kotlinx.coroutines.coroutineScope + val client = Client() .setEndpoint("https://cloud.appwrite.io/v1") .setProject("") @@ -190,12 +191,13 @@ Create a function to retrieve the mock todo data. suspend fun getTodos() { val todos = databases.listDocuments(todoDatabase?.id!!, todoCollection?.id!!) for (todo in todos.documents) { - println(""" - Title: ${todo.data["title"]} - Description: ${todo.data["description"]} - Is Todo Complete: ${todo.data["isComplete"]} - - """.trimIndent()) + println( + """ + Title: ${todo.data["title"]} + Description: ${todo.data["description"]} + Is Todo Complete: ${todo.data["isComplete"]} + """.trimIndent() + ) } } diff --git a/src/routes/docs/quick-starts/php/+page.markdoc b/src/routes/docs/quick-starts/php/+page.markdoc index 36435c9b3f..2df153d113 100644 --- a/src/routes/docs/quick-starts/php/+page.markdoc +++ b/src/routes/docs/quick-starts/php/+page.markdoc @@ -196,7 +196,7 @@ function getTodos($databases, $todoDatabase, $todoCollection) { echo "Title: {$todo['title']}\n" . "Description: {$todo['description']}\n" . "Is Todo Complete: {$todo['isComplete']}\n\n"; - } + } } function runAllTasks($databases) { diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc index f134f5ecf0..d856800998 100644 --- a/src/routes/docs/quick-starts/swift/+page.markdoc +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -81,6 +81,7 @@ Open the file `main.swift` and initialize the Appwrite Client. Replace ` Date: Fri, 26 Jan 2024 16:02:07 +0000 Subject: [PATCH 14/17] Fix swift --- .../docs/quick-starts/swift/+page.markdoc | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc index d856800998..b34084f4e9 100644 --- a/src/routes/docs/quick-starts/swift/+page.markdoc +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -97,20 +97,16 @@ Once the Appwrite Client is initialized, create a function to configure a todo c ```swift let databases = Databases(client) -var todoDatabase: Database? -var todoCollection: Collection? - -todoDatabase = try? await databases.create( - databaseId: ID.unique(), - name: "TodosDB" -) -todoCollection = try? await databases.createCollection( - databaseId: todoDatabase!.id, - collectionId: ID.unique(), - name: "Todos" -) - -func prepareDatabase() async { +func prepareDatabase() async -> (Database?, Collection?) { + let todoDatabase = try? await databases.create( + databaseId: ID.unique(), + name: "TodosDB" + ) + let todoCollection = try? await databases.createCollection( + databaseId: todoDatabase!.id, + collectionId: ID.unique(), + name: "Todos" + ) try? await databases.createStringAttribute( databaseId: todoDatabase!.id, collectionId: todoCollection!.id, @@ -132,6 +128,8 @@ func prepareDatabase() async { key: "isComplete", xrequired: true ) + + return (todoDatabase, todoCollection) } ``` @@ -139,7 +137,7 @@ func prepareDatabase() async { {% section #step-6 step=6 title="Add documents" %} Create a function to add some mock data into your new collection. ```swift -func seedDatabase() async { +func seedDatabase(todoDatabase: Database?, todoCollection: Collection?) async { let testTodo1: [String: Any] = [ "title": "Buy apples", "description": "At least 2KGs", @@ -158,18 +156,18 @@ func seedDatabase() async { ] try? await databases.createDocument( - databaseId: todoDatabase!.id as! String, - collectionId: todoCollection!.id as! String, + databaseId: todoDatabase!.id, + collectionId: todoCollection!.id, documentId: ID.unique(), data: testTodo1 ) try? await databases.createDocument( - databaseId: todoDatabase!.id as! String, - collectionId: todoCollection!.id as! String, + databaseId: todoDatabase!.id, + collectionId: todoCollection!.id, documentId: ID.unique(), data: testTodo2 ) try? await databases.createDocument( - databaseId: todoDatabase!.id as! String, - collectionId: todoCollection!.id as! String, + databaseId: todoDatabase!.id, + collectionId: todoCollection!.id, documentId: ID.unique(), data: testTodo3 ) @@ -182,8 +180,11 @@ func seedDatabase() async { Create a function to retrieve the mock todo data. ```swift -func getTodos() async { - let todos = try? await databases.listDocuments(databaseId: todoDatabase!.id as! String, collectionId: todoCollection!.id as! String) +func getTodos(todoDatabase: Database?, todoCollection: Collection?) async { + let todos = try? await databases.listDocuments( + databaseId: todoDatabase!.id as! String, + collectionId: todoCollection!.id as! String + ) for document in todos?.documents ?? [] { if let todo = document.data as? [String: Any] { print("Title: \(todo["title"] ?? "")\n" @@ -194,9 +195,9 @@ func getTodos() async { } } -await prepareDatabase() -await seedDatabase() -await getTodos() +let (todoDatabase, todoCollection) = await prepareDatabase() +await seedDatabase(todoDatabase: todoDatabase, todoCollection: todoCollection) +await getTodos(todoDatabase: todoDatabase, todoCollection: todoCollection) ``` {% /section %} From 5b5812d408d5d29ef146c4af1ca266b7111e1183 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Fri, 26 Jan 2024 16:02:53 +0000 Subject: [PATCH 15/17] Linebreak the data param --- src/routes/docs/quick-starts/swift/+page.markdoc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/routes/docs/quick-starts/swift/+page.markdoc b/src/routes/docs/quick-starts/swift/+page.markdoc index b34084f4e9..675a75c7cc 100644 --- a/src/routes/docs/quick-starts/swift/+page.markdoc +++ b/src/routes/docs/quick-starts/swift/+page.markdoc @@ -158,12 +158,14 @@ func seedDatabase(todoDatabase: Database?, todoCollection: Collection?) async { try? await databases.createDocument( databaseId: todoDatabase!.id, collectionId: todoCollection!.id, - documentId: ID.unique(), data: testTodo1 + documentId: ID.unique(), + data: testTodo1 ) try? await databases.createDocument( databaseId: todoDatabase!.id, collectionId: todoCollection!.id, - documentId: ID.unique(), data: testTodo2 + documentId: ID.unique(), + data: testTodo2 ) try? await databases.createDocument( databaseId: todoDatabase!.id, From a8c62c25bc31bf9a4722df0a5e6c7a75f019af68 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Fri, 26 Jan 2024 16:11:43 +0000 Subject: [PATCH 16/17] Change variables in ruby --- .../docs/quick-starts/ruby/+page.markdoc | 72 ++++++++++--------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/src/routes/docs/quick-starts/ruby/+page.markdoc b/src/routes/docs/quick-starts/ruby/+page.markdoc index 1d56812907..2df80647cb 100644 --- a/src/routes/docs/quick-starts/ruby/+page.markdoc +++ b/src/routes/docs/quick-starts/ruby/+page.markdoc @@ -92,44 +92,45 @@ Once the Appwrite Client is initialized, create a function to configure a todo c ```ruby databases = Databases.new(client) -@todo_database = nil -@todo_collection = nil +todo_database = nil +todo_collection = nil -def prepare_database - @todo_database = @databases.create( +def prepare_database(databases) + todo_database = databases.create( database_id: ID.unique(), name: 'TodosDB' ) - @todo_collection = @databases.create_collection( - database_id: @todo_database.id, + todo_collection = databases.create_collection( + database_id: todo_database.id, collection_id: ID.unique(), name: 'Todos' ) - @databases.create_string_attribute( - database_id: @todo_database.id, - collection_id: @todo_collection.id, + databases.create_string_attribute( + database_id: todo_database.id, + collection_id: todo_collection.id, key: 'title', size: 255, required: true ) - @databases.create_string_attribute( - database_id: @todo_database.id, - collection_id: @todo_collection.id, + databases.create_string_attribute( + database_id: todo_database.id, + collection_id: todo_collection.id, key: 'description', size: 255, required: false ) - @databases.create_boolean_attribute( - database_id: @todo_database.id, - collection_id: @todo_collection.id, + databases.create_boolean_attribute( + database_id: todo_database.id, + collection_id: todo_collection.id, key: 'isComplete', required: false, default: false ) + return todo_database, todo_collection end ``` @@ -138,7 +139,7 @@ end Create a function to add some mock data into your new collection. ```ruby -def seed_database() +def seed_database(databases, todo_database, todo_collection) test_todo1 = { title: 'Buy apples', description: 'At least 2KGs', @@ -153,26 +154,26 @@ def seed_database() test_todo3 = { title: 'Cut the apples', description: 'Don\'t forget to pack them in a box', - 'isComplete: false + isComplete: false } - @databases.create_document( - database_id: @todo_database.id, - collection_id: @todo_collection.id, + databases.create_document( + database_id: todo_database.id, + collection_id: todo_collection.id, document_id: ID.unique(), data: test_todo1 ) - @databases.create_document( - database_id: @todo_database.id, - collection_id: @todo_collection.id, + databases.create_document( + database_id: todo_database.id, + collection_id: todo_collection.id, document_id: ID.unique(), data: test_todo2 ) - @databases.create_document( - database_id: @todo_database.id, - collection_id: @todo_collection.id, + databases.create_document( + database_id: todo_database.id, + collection_id: todo_collection.id, document_id: ID.unique(), data: test_todo3 ) @@ -186,10 +187,10 @@ Create a function to retrieve the mock todo data and a function to execute the r Run the functions to by calling `run_all_tasks()`. ```ruby -def get_todos - todos = @databases.list_documents( - database_id: @todo_database.id, - collection_id: @todo_collection.id +def get_todos(databases, todo_database, todo_collection) + todos = databases.list_documents( + database_id: todo_database.id, + collection_id: todo_collection.id ) todos.documents.each do |todo| @@ -197,12 +198,13 @@ def get_todos end end -def run_all_tasks - prepare_database - seed_database - get_todos +def run_all_tasks(databases) + todo_database, todo_collection = prepare_database(databases) + seed_database(databases, todo_database, todo_collection) + get_todos(databases, todo_database, todo_collection) end -run_all_tasks + +run_all_tasks(databases) ``` {% /section %} From 7d39791ff4fbdc3a47dc426bdf377cc8ba875cd7 Mon Sep 17 00:00:00 2001 From: "Vincent (Wen Yu) Ge" Date: Mon, 29 Jan 2024 10:44:30 -0500 Subject: [PATCH 17/17] Update src/routes/docs/quick-starts/kotlin/+page.markdoc Co-authored-by: Damodar Lohani --- src/routes/docs/quick-starts/kotlin/+page.markdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/docs/quick-starts/kotlin/+page.markdoc b/src/routes/docs/quick-starts/kotlin/+page.markdoc index 894cae8203..a7cc031cc9 100644 --- a/src/routes/docs/quick-starts/kotlin/+page.markdoc +++ b/src/routes/docs/quick-starts/kotlin/+page.markdoc @@ -86,7 +86,7 @@ Open the file `Main.kt` and initialize the Appwrite Client. Replace `