You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/routes/docs/tutorials/nuxt/step-6/+page.markdoc
+15-8Lines changed: 15 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: Add database
4
4
description: Add databases and queries for ideas in your Nuxt project.
5
5
step: 6
6
6
---
7
-
# Create collection {% #create-collection %}
7
+
8
8
In Appwrite, data is stored as a collection of documents. Create a collection in the [Appwrite Console](https://cloud.appwrite.io/) to store our ideas.
9
9
10
10
{% only_dark %}
@@ -21,11 +21,14 @@ Create a new collection with the following attributes:
21
21
| title | String | Yes |
22
22
| description | String | No |
23
23
24
-
Change the collection's permissions settings to give any role access to it.
24
+
Change the collection's permissions in the settings to give access.
25
+
First, add an "Any" role and check the `READ` box.
26
+
Next, add a "Users" role and give them access to create, update and delete.
25
27
26
28
# Query methods {% #query-methods %}
27
-
Now that you have a collection to hold ideas, we can read and write to it from our app.
28
-
Create a new file in the composables directory, `src/composables/useIdeas.js` and add the following code to it.
29
+
Now that you have a collection to hold ideas, we can use it to get, add and remove data from our app.
30
+
We will create a new composable to manage the data fetching and their global state.
31
+
Create a new file in the composables directory, `src/composables/useIdeas.js` and add the following code.
29
32
30
33
```js
31
34
import { ID, Query } from "appwrite";
@@ -35,9 +38,12 @@ import { ref } from "vue";
35
38
const IDEAS_DATABASE_ID = "YOUR_DATABASE_ID";
36
39
const IDEAS_COLLECTION_ID = "YOUR_COLLECTION_ID";
37
40
38
-
const current = ref(null);
41
+
const current = ref(null); //Reference for the fetched data
39
42
40
43
export const useIdeas = () => {
44
+
45
+
/* Fetch the 10 most recent ideas from the database
46
+
and passes the list to the current reference object */
41
47
const init = async () => {
42
48
const response = await database.listDocuments(
43
49
IDEAS_DATABASE_ID,
@@ -46,6 +52,9 @@ export const useIdeas = () => {
46
52
);
47
53
current.value = response.documents;
48
54
};
55
+
56
+
/* Add new idea to the database, add it to the current
57
+
object and remove the last to still have 10 ideas */
0 commit comments