Appwrite Database Tutorial #5 - Deleting Documents
Skills:
Database Integration80%
Key Takeaways
Deletes documents from an Appwrite database using a delete action
Full Transcript
okay then my friends so now we can add new note documents and we can fetch them all as well when the page first loads the next thing I'd like to show you is how we can delete documents from the database when we click on these notes in the browser so just like with the other two database interactions we'll be making an action to delete documents inside this no actions file and then we'll be invoking that action from inside the notel list component whenever a user clicks on a note so then in the note actions file let's export another async function fun and this time we're going to call that function delete note now as an argument to this function I want to pass in the ID of the note that we want to delete so that app right can find that document in the collection to delete it so we'll call this argument note ID and that's going to be a string and that document ID by the way is going to be the one that aight generated for us when we created new documents anyway we're not going to explicitly return a value from this action so we won't add the return typon and then it's going to default to a promise that resolves to void and we can see that if we hover over the function name so then now we need to perform this delete request in here and it's really simple to do we can just say await and then we're going to use the databases instance which we already imported into this file and we're going to use a method on that called delete documents and invoke it and this method takes in three arguments the first is the database ID as a string which which in my case is just Notes app the second is the collection ID as a string which is just notes and the third is the ID of the document that we want to delete within that collection and we accept that as an argument to this function note ID so we can just pass that in as the third argument right here and that's pretty much it my friends now when we invoke this action it's going to go ahead and delete a document from the notes collection so then if we go back to the not list components you're going to see that when we output the list of notes we do two things first we assign an ID attribute to each list item for each notes and the value of that is the ID of that note using the dollar sign ID property second we attach a click event to each list item which fires a handle delete function and passes in the ID of the not we clicked on as an argument so then inside that handle delete function we accept that no ID but we don't really do anything with it yet now the first thing I'm going to do in here is paste in a tiny bit of code for stylistic purposes when we delete a notes and what this bit of code does is grab the element we clicked on by finding the element in the Dom using the get element by ID method and we just pass in the ID of the note because remember we appli the ID attribute down here on the LI tag once we have the element we check it actually exists and then we add a class to the element called cross outs and in the CSS file that class adds a strike through to the note so it looks like we're crossing it out now after we've done that we also want to invoke the delete note action to go ahead and delete the note from the database so let's say await and then we're going to invoke the delete note function and when you click on this it should Auto Import the action for you if not make sure you import it at the top of the file otherwise this ain't going to work all right cool now we just need to pass the notes ID as an argument to the action which we can do and now I think that's pretty much everything so we can save this and try it out in a browser all right so now if I click on one of these like sleep more then it's going to cross it out and that's the CSS um because we applied that conditional class that crossed out class when we tried to delete something it's not gone from the page but that's because we're not updating the state within the component the page itself but we are still deleting the document from aight I can demo that by coming over here and you can see it was which one was it buy some milk or sleep more that I crossed out sleep more so this document right here whenever refresh should be gone which it is and also when I refresh over here then it should be gone as well because remember when we first load the page we fetch the documents from scratch and since it doesn't exist over here anymore then we're not fetching that document we don't see it on the page anymore so we are successfully deleting those documents now and this is the same kind of thing as when we added some documents right if we Tred to add something then although it gets added over here we don't see it straight away over here we have to refresh to refetch those documents and then we see so we are going to combat this using real time uh subscriptions in the next lesson whereby when we make changes to the database the database notifies us of those changes and we can update the state locally within the component to reflect that change in the browser as well
Original Description
Appwrite is a backend-as-a-service platform, that provides database, authentication, storage, cloud functions and other services. In this Appwrite tutorial, we'll be exploring how to set up and use an Appwrite database.
🔥🥷🏼Sign up to Appwrite for free here - https://apwr.dev/netninja50
🧠🥷🏼Appwrite docs - https://appwrite.io/docs
📂🥷🏼 Access the course files on GitHub:
https://github.com/iamshaunjp/appwrite-tutorial
📂🥷🏼 Starter project on GitHub:
https://github.com/iamshaunjp/appwrite-tutorial/tree/starter-project
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: Database Integration
View skill →Related Reads
📰
📰
📰
📰
TCP vs UDP, Explained — Part 1: Building a TCP Server in C++
Medium · Programming
The Session ID That Wouldn't Stop Changing
Dev.to · Michał Iżewski
Stop Data Leaks: Tenant Scopes in Laravel 🛡️
Dev.to · Prajapati Paresh
Base64 Encoding in JavaScript: A Practical Guide with Real Examples
Dev.to · jiebang-tools
🎓
Tutor Explanation
DeepCamp AI