How to: Create a Thing

A deep dive how we create new entries in the Database. To make sure everything happens smoothly let's go through a few things:

  • Each query or table should have it's own Supabase Data element

  • These Data elements have their own Element Actions so creating a new thing in a table, you should use the action which belongs to that Supabase Data element.

  • This needed because certain actions or functions are dependent on the Elements own properties which you setup initially, and when you refresh the query it's gonna take the initial query setup.

Let's see a use case based on our Auth setup. Once a User has signed up, we want to create a new entry in our "user" table to track the user's metadata like First Name or Phone Number.

See how the Auth part of this have been setup

How to: Sign Up

And how the Database have been setup:

How to: Fetch Data

To make sure we have the data available we use the User Signed Up event. In the example we create a new entry for the user, where we attach the to the created_by column and the email address to the email field.

Now what about Row Level Security? Since we've setup RLS based on the created_by field which is not yet available for us yet, so how can we so the insert.

You can do the API call server-side to bypass the RLS or with functions, or you can setup a simple RLS for just INSERT:

There's a field "Refresh Data" (true/false) this is a separate feature which allow better control. Here's the breakdown:

  • Enable Realtime is true and Refresh Data is false: Data will be returned via Realtime.

  • Enable Realtime is true and Refresh Data is true: Data will be returned via Realtime and not via the Refresh Data function

  • Enable Realtime is false and Refresh Data is false: Query will not be refreshed

Once the entry have been successfully added you can reference that within the plugin's state "New Thing". That's why it's also important to use the related Supabase Data element for the action.

Since Bubble is a bit unreliable with client side data retrieval, use a pause between the actions when referencing the state, or use the event "New Thing have been created".

Last updated