@limited-pencil-78283
You know how in a proper SQL database like Supabase, we link tables together using Foreign Keys? We're doing the exact same conceptual thing in Botpress, we just have to build the relationship ourselves since Botpress doesn't enforce it for us.
Let me break it down with an example.
1. The Supabase Way (For Comparison)
In Supabase, if we have a users table and an orders table, we'd define a relationship like this:
路 users table
路 id (UUID, Primary Key) | name (Text)
路 a1b2-c3d4... | Alice
路 e5f6-g7h8... | Bob
路 orders table
路 id (UUID, Primary Key) | product_name (Text) | user_id (UUID, Foreign Key)
路 o1o2-o3o4... | Super Widget | a1b2-c3d4... (This links to Alice)
路 o5o6-o7o8... | Mega Gizmo | e5f6-g7h8... (This links to Bob)
路 o9o0-p1p2... | Mini Thingy | a1b2-c3d4... (This is also Alice's order)
The user_id in the orders table points to the id in the users table. This is a foreign key. To get all of Alice's orders, we'd run a JOIN query.
2. The Botpress Way (my Vision - It's the Same Concept!)
In Botpress, we don't have automatic foreign key constraints, but we can emulate the pattern 100%. We use the UUID Integration card to generate a unique ID for a user and then treat that ID as our primary key.
Step 1: Create the "Users" Table (or equivalent) You have a flow where a user signs up.You use the UUID Integration card to generate a unique user_id for them (e.g., a1b2-c3d4...). You save this ID along with their info in Botpress's native database (key-value store).
路 Key: user/a1b2-c3d4...
路 Value:
json
{
"name": "Alice",
"email": "alice@example.com",
"user_id": "a1b2-c3d4..."
}
Step 2: Create the "Orders" Table and Use the user_id as a Foreign Key Now,when Alice buys something, you create a new record for her order. The crucial part is that you store her user_id with the order.
路 Key: order/o1o2-o3o4... (you can generate another UUID for the order ID)