Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@
"tutorials/client/performance/overview",
"tutorials/client/performance/supabase-connector-performance"
]
},
{
"group": "Data Management",
"pages": [
"tutorials/client/data/overview",
"tutorials/client/data/cascading-delete"
]
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions tutorials/client/attachments-and-files/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: "A collection of tutorials exploring storage strategies."
---

<CardGroup>
<Card title="AWS S3 Storage" icon="server" href="/tutorials/client/attachments-and-files/aws-s3-storage-adapter" horizontal/>
<Card title="PDF Attachments" icon="server" href="/tutorials/client/attachments-and-files/pdf-attachment" horizontal/>
<Card title="AWS S3 Storage" icon="paperclip" href="/tutorials/client/attachments-and-files/aws-s3-storage-adapter" horizontal/>
<Card title="PDF Attachments" icon="paperclip" href="/tutorials/client/attachments-and-files/pdf-attachment" horizontal/>
</CardGroup>
41 changes: 41 additions & 0 deletions tutorials/client/data/cascading-delete.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "Cascading Delete"
description: "In this tutorial we will show you how to perform a cascading delete on the client."
keywords: ["data", "cascade", "delete"]
---

# Introduction

Since PowerSync utilizes SQLite views instead of standard tables, SQLite features like constraints, foreign keys, or cascading deletes are not available.
Currently, there is no direct support for cascading deletes on the client. However, you can achieve this by either:
1. Manually deleting all the relevant tables within a **single transaction**, OR
<Note>
Every local mutation performed against SQLite via the PowerSync SDK will be returned in `uploadData`. So as long as you are using `.execute()` for the mutation,
the operation will be present in the upload queue.
</Note>
2. Implementing triggers (which is more complex)
<Note>
You create triggers on the [internal tables](https://docs.powersync.com/architecture/client-architecture#schema) (not the views defined by the client schema), similar to what is
done [here](https://github.com/powersync-ja/powersync-js/blob/e77b1abfbed91988de1f4c707c24855cd66b2219/demos/react-supabase-todolist/src/app/utils/fts_setup.ts#L50)
</Note>

# Example

The following example is taken from the [React Native To-Do List example app](https://github.com/powersync-ja/powersync-js/tree/main/demos/react-native-supabase-todolist).
It showcases how to delete a `list` and all its associated `todos` in a single transaction.

```typescript
const deleteList = async (id: string) => {
await system.powersync.writeTransaction(async (tx) => {
// Delete associated todos
await tx.execute(`DELETE FROM ${TODO_TABLE} WHERE list_id = ?`, [id]);
// Delete list record
await tx.execute(`DELETE FROM ${LIST_TABLE} WHERE id = ?`, [id]);
});
};
```

<Note>
An important thing to note is that the local SQLite database will always match the backend database, as long as the tables are in the publication, when online.
For example, if you delete a record from the local `lists` table and Supabase cascade deletes a record from the `todo` table, PowerSync will also delete the local `todo` record when online.
</Note>
8 changes: 8 additions & 0 deletions tutorials/client/data/overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: "Overview"
description: "A collection of tutorials showcasing various data management strategies and use cases."
---

<CardGroup>
<Card title="Cascading Delete" icon="database" href="/tutorials/client/data/cascading-delete" horizontal/>
</CardGroup>
2 changes: 1 addition & 1 deletion tutorials/client/performance/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ description: "A collection of tutorials exploring performance strategies."
---

<CardGroup>
<Card title="Improve Supabase Connector Performance" icon="server" href="/tutorials/client/performance/supabase-connector-performance" horizontal/>
<Card title="Improve Supabase Connector Performance" icon="gauge" href="/tutorials/client/performance/supabase-connector-performance" horizontal/>
</CardGroup>
5 changes: 3 additions & 2 deletions tutorials/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: "A collection of tutorials showcasing various storage attachment an
---

<CardGroup>
<Card title="Attachments/Files tutorials" icon="server" href="/tutorials/client/attachments-and-files/overview" horizontal/>
<Card title="Performance tutorials" icon="server" href="/tutorials/client/performance/overview" horizontal/>
<Card title="Attachments/Files tutorials" icon="paperclip" href="/tutorials/client/attachments-and-files/overview" horizontal/>
<Card title="Performance tutorials" icon="gauge" href="/tutorials/client/performance/overview" horizontal/>
<Card title="Data Management tutorials" icon="database" href="/tutorials/client/data/overview" horizontal/>
</CardGroup>
Loading