-
Notifications
You must be signed in to change notification settings - Fork 19
Supabase error handling #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
72c2bbb
Add in-memory database for tests
simolus3 9550630
Fix in-memory tests
simolus3 321e95e
Allow customizing error handling
simolus3 3eece50
Supabase connector: Allow error handling
simolus3 75a3a35
Move supabase connector to integrations folder
simolus3 eab8a9d
Move to integration test
simolus3 99d5f1a
Make core extension available
simolus3 025c79f
Bad merge
simolus3 2104fd9
Fix formatting
simolus3 8843612
Review suggestions
simolus3 0b7ae20
Fix reconnect race in test
simolus3 a55c9c9
Improve room test reliability
simolus3 f1dfa25
Try catching closed pool message
simolus3 9c44d0b
Format
simolus3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
core/src/commonIntegrationTest/kotlin/com/powersync/DatabaseTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
# PowerSync Backend Connectors | ||
# PowerSync Supabase connector | ||
|
||
Convenience implementations of backend connectors that provide the connection between your application backend and the PowerSync managed database. | ||
Convenience implementation of a backend connector that provide the connection between your application backend and the PowerSync managed database | ||
by delegating to Supabase. | ||
|
||
It is used to: | ||
1. Retrieve a token to connect to the PowerSync service. | ||
2. Apply local changes on your backend application server (and from there, to your backend database). | ||
|
||
The connector is fairly basic, and also serves as an example for getting started. | ||
|
||
## Provided Connectors | ||
|
||
### Supabase (Postgres) | ||
|
||
A basic implementation of a PowerSync Backend Connector for Supabase, that serves as getting started example. | ||
|
||
See a step-by-step tutorial for connecting to Supabase, [here](https://docs.powersync.com/integration-guides/supabase-+-powersync). | ||
See a step-by-step tutorial for connecting to Supabase, [here](https://docs.powersync.com/integration-guides/supabase-+-powersync). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
67 changes: 67 additions & 0 deletions
67
...rc/commonIntegrationTest/kotlin/com/powersync/connector/supabase/SupabaseConnectorTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.powersync.connector.supabase | ||
|
||
import com.powersync.PowerSyncDatabase | ||
import com.powersync.db.crud.CrudEntry | ||
import com.powersync.db.crud.CrudTransaction | ||
import com.powersync.db.schema.Column | ||
import com.powersync.db.schema.Schema | ||
import com.powersync.db.schema.Table | ||
import io.kotest.matchers.collections.shouldHaveSize | ||
import io.kotest.matchers.equals.shouldBeEqual | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
|
||
class SupabaseConnectorTest { | ||
@Test | ||
fun errorHandling() = | ||
runTest { | ||
val db = | ||
PowerSyncDatabase.inMemory( | ||
scope = this, | ||
schema = | ||
Schema( | ||
Table( | ||
"users", | ||
listOf( | ||
Column.text("name"), | ||
), | ||
), | ||
), | ||
) | ||
|
||
try { | ||
db.writeTransaction { tx -> | ||
tx.execute("INSERT INTO users (id, name) VALUES (uuid(), ?)", listOf("a")) | ||
tx.execute("INSERT INTO users (id, name) VALUES (uuid(), ?)", listOf("b")) | ||
tx.execute("INSERT INTO users (id, name) VALUES (uuid(), ?)", listOf("c")) | ||
} | ||
|
||
var calledErrorHandler = false | ||
val connector = | ||
object : SupabaseConnector("", "", "") { | ||
override suspend fun uploadCrudEntry(entry: CrudEntry): Unit = | ||
throw Exception("Expected exception, failing in uploadCrudEntry") | ||
|
||
override suspend fun handleError( | ||
tx: CrudTransaction, | ||
entry: CrudEntry, | ||
exception: Exception, | ||
errorCode: String?, | ||
) { | ||
calledErrorHandler = true | ||
|
||
tx.crud shouldHaveSize 3 | ||
entry shouldBeEqual tx.crud[0] | ||
exception.message shouldBe "Expected exception, failing in uploadCrudEntry" | ||
tx.complete(null) | ||
} | ||
} | ||
|
||
connector.uploadData(db) | ||
calledErrorHandler shouldBe true | ||
} finally { | ||
db.close() | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.