Skip to content
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

Remove nightly labels #8

Merged
merged 3 commits into from
Sep 4, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Start Surreal
run: docker run -d -p 8000:8000 surrealdb/surrealdb:nightly start --user root --pass root -- "memory"
run: docker run -d -p 8000:8000 surrealdb/surrealdb:latest start --user root --pass root -- "memory"
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
Expand Down
5 changes: 0 additions & 5 deletions src/commonMain/kotlin/uk/gibby/driver/Surreal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import kotlinx.serialization.json.*
import uk.gibby.driver.annotation.SurrealDbNightlyOnlyApi
import uk.gibby.driver.exception.LiveQueryKilledException
import uk.gibby.driver.model.rpc.*
import uk.gibby.driver.rpc.kill
Expand Down Expand Up @@ -103,25 +102,21 @@ class Surreal(private val host: String, private val port: Int = 8000) {
return channel.receive()
}

@SurrealDbNightlyOnlyApi
fun subscribeAsJson(liveQueryId: String): Flow<LiveQueryAction<JsonElement>> {
val channel = liveQueries.getOrPut(liveQueryId) { Channel() }
return channel.receiveAsFlow()
}

@SurrealDbNightlyOnlyApi
inline fun <reified T> subscribe(liveQueryId: String): Flow<LiveQueryAction<T>> {
return subscribeAsJson(liveQueryId).map { it.asType() }
}

@SurrealDbNightlyOnlyApi
fun unsubscribe(liveQueryId: String) {
val channel = liveQueries[liveQueryId]
channel?.cancel(LiveQueryKilledException)
liveQueries.remove(liveQueryId)
}

@SurrealDbNightlyOnlyApi
internal fun triggerKill(liveQueryId: String) {
context.launch { kill(liveQueryId) }
}
Expand Down
2 changes: 0 additions & 2 deletions src/commonMain/kotlin/uk/gibby/driver/api/LiveQueryFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.ktor.utils.io.core.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import uk.gibby.driver.Surreal
import uk.gibby.driver.annotation.SurrealDbNightlyOnlyApi
import uk.gibby.driver.model.rpc.LiveQueryAction

/**
Expand All @@ -18,7 +17,6 @@ import uk.gibby.driver.model.rpc.LiveQueryAction
* @property connection The connection to the database
* @constructor Creates a new live query flow
*/
@SurrealDbNightlyOnlyApi
class LiveQueryFlow<T>(
private val flow: Flow<LiveQueryAction<T>>,
val id: String,
Expand Down
3 changes: 0 additions & 3 deletions src/commonMain/kotlin/uk/gibby/driver/api/Observe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package uk.gibby.driver.api

import kotlinx.serialization.json.JsonElement
import uk.gibby.driver.Surreal
import uk.gibby.driver.annotation.SurrealDbNightlyOnlyApi
import uk.gibby.driver.rpc.live
import uk.gibby.driver.model.rpc.asType
import kotlin.jvm.JvmName
Expand All @@ -16,7 +15,6 @@ import kotlin.jvm.JvmName
* @return A [LiveQueryFlow] of [JsonElement]s
*/
@JvmName("observeJson")
@SurrealDbNightlyOnlyApi
suspend fun Surreal.observeLiveQueryAsJson(table: String): LiveQueryFlow<JsonElement> {
val liveQueryId = live(table)
return LiveQueryFlow(
Expand All @@ -36,7 +34,6 @@ suspend fun Surreal.observeLiveQueryAsJson(table: String): LiveQueryFlow<JsonEle
* @param table Name of the table to 'LIVE SELECT' from
* @return A [LiveQueryFlow] of [T]s
*/
@SurrealDbNightlyOnlyApi
suspend inline fun <reified T>Surreal.observeLiveQuery(table: String): LiveQueryFlow<T> {
val jsonFlow = observeLiveQueryAsJson(table)
return jsonFlow.map { it.asType<T>() }
Expand Down
2 changes: 0 additions & 2 deletions src/commonMain/kotlin/uk/gibby/driver/rpc/Kill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package uk.gibby.driver.rpc
import kotlinx.serialization.json.add
import kotlinx.serialization.json.buildJsonArray
import uk.gibby.driver.Surreal
import uk.gibby.driver.annotation.SurrealDbNightlyOnlyApi

/**
* Kill
Expand All @@ -12,7 +11,6 @@ import uk.gibby.driver.annotation.SurrealDbNightlyOnlyApi
*
* @param liveQueryId The id of the live query to kill
*/
@SurrealDbNightlyOnlyApi
suspend fun Surreal.kill(liveQueryId: String) {
sendRequest("kill", buildJsonArray { add(liveQueryId) })
}
Expand Down
2 changes: 0 additions & 2 deletions src/commonMain/kotlin/uk/gibby/driver/rpc/Live.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import kotlinx.serialization.json.add
import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.decodeFromJsonElement
import uk.gibby.driver.Surreal
import uk.gibby.driver.annotation.SurrealDbNightlyOnlyApi
import uk.gibby.driver.surrealJson


Expand All @@ -16,7 +15,6 @@ import uk.gibby.driver.surrealJson
* @param table Name of the table to 'LIVE SELECT' from
* @return The id of the live query
*/
@SurrealDbNightlyOnlyApi
suspend fun Surreal.live(table: String): String {
val response = sendRequest("live", buildJsonArray { add(table) })
return surrealJson.decodeFromJsonElement(response)
Expand Down
2 changes: 2 additions & 0 deletions src/commonMain/kotlin/uk/gibby/driver/rpc/Update.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class UpdateBuilder(private val table: String, private val db: Surreal) {
val response = db.sendRequest("patch", buildJsonArray {
add(table)
add(surrealJson.encodeToJsonElement(builder.build()))
add(true)
})
return surrealJson.decodeFromJsonElement(response)
}
Expand Down Expand Up @@ -267,6 +268,7 @@ class UpdateIdBuilder(private val id: String, private val db: Surreal) {
val result = db.sendRequest("patch", buildJsonArray {
add(id)
add(surrealJson.encodeToJsonElement(builder.build()))
add(true)
})
return surrealJson.decodeFromJsonElement(result)
}
Expand Down
2 changes: 0 additions & 2 deletions src/commonTest/kotlin/KillTest.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import kotlinx.coroutines.test.runTest
import uk.gibby.driver.Surreal
import uk.gibby.driver.annotation.SurrealDbNightlyOnlyApi
import uk.gibby.driver.rpc.kill
import uk.gibby.driver.rpc.live
import uk.gibby.driver.rpc.signin
import uk.gibby.driver.rpc.use
import utils.cleanDatabase
import kotlin.test.Test

@OptIn(SurrealDbNightlyOnlyApi::class)
class KillTest {
@Test
fun testKill() = runTest {
Expand Down
2 changes: 0 additions & 2 deletions src/commonTest/kotlin/LiveQueryTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import uk.gibby.driver.Surreal
import uk.gibby.driver.annotation.SurrealDbNightlyOnlyApi
import uk.gibby.driver.api.observeLiveQuery
import uk.gibby.driver.exception.LiveQueryKilledException
import uk.gibby.driver.model.rpc.LiveQueryAction
Expand All @@ -11,7 +10,6 @@ import uk.gibby.driver.rpc.*
import utils.cleanDatabase
import kotlin.test.*

@OptIn(SurrealDbNightlyOnlyApi::class)
class LiveQueryTest {
@Test
fun testObserve() = runTest {
Expand Down