Run executions
Supastash queries must be finalized with .execute()
, .run()
, or .go()
β all of which trigger the actual operation after your query is fully constructed.
These methods are interchangeable aliases, but .execute()
is the primary one. The others are provided for convenience, readability in different contexts, or simply as shorter alternatives.
π§ How .execute()
Worksβ
When .execute()
is called:
-
Supastash validates the query.
-
The local operation is run first (insert, select, update, etc.).
-
If
viewRemoteResult
is true:- Supabase is queried for the remote payload, which is then returned.
- If remote fails, it retries with exponential backoff based on the retry config.
-
The result is returned based on the mode and visibility settings.
β‘ Supastash will reject
.execute()
if no valid method was set (e.g., no.select()
,.insert()
, etc.).
π Retry Behaviorβ
-
Retries are only triggered when
viewRemoteResult: true
. -
Retry uses exponential backoff
-
Default retry config:
remoteRetry
:0
(no retries unless explicitly set)remoteRetryDelay
:500ms
You can override with:
.run({
viewRemoteResult: true,
remoteRetry: 3,
remoteRetryDelay: 1000,
debug: true,
});
π§Ύ Return Typesβ
The return format depends on the query method and viewRemoteResult
:
If viewRemoteResult: false
(default):β
{
data: [... or object],
error: null,
success: true
}
If viewRemoteResult: true
:β
{
local: [... or object],
remote: SupabaseResult,
success: true
}
π When to Use Eachβ
Method | Purpose |
---|---|
.execute() | Clear and explicit β ideal for programmatic or formal use |
.run() | Simple and common β great for examples and everyday usage |
.go() | Expressive and readable β fits well in fluent chains |
All three do the same thing under the hood. Usage depends on your taste.
β
When to Use .run()
or .execute()
β
Use it anytime you want to:
- Finalize and execute a query
- Control sync behavior with
viewRemoteResult
- Enable retries and debugging
- Retrieve both local and remote data when needed
That concludes the core Supastash query lifecycle.