Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update Kotlin tutorials to be aligned with supabase-kt v2.0.0 (#19998)

Hieu Vuc09caa317aa8
diff --git a/apps/docs/pages/guides/getting-started/tutorials/with-kotlin.mdx b/apps/docs/pages/guides/getting-started/tutorials/with-kotlin.mdx
index d409e27c670..399fc1deaec 100644
--- a/apps/docs/pages/guides/getting-started/tutorials/with-kotlin.mdx
+++ b/apps/docs/pages/guides/getting-started/tutorials/with-kotlin.mdx
@@ -269,7 +269,9 @@ class ProductRepositoryImpl @Inject constructor(
override suspend fun getProduct(id: String): ProductDto {
return withContext(Dispatchers.IO) {
postgrest.from("products").select {
- eq("id", id)
+ filter {
+ eq("id", id)
+ }
}.decodeSingle<ProductDto>()
}
}
@@ -277,7 +279,9 @@ class ProductRepositoryImpl @Inject constructor(
override suspend fun deleteProduct(id: String) {
return withContext(Dispatchers.IO) {
postgrest.from("products").delete {
- eq("id", id)
+ filter {
+ eq("id", id)
+ }
}
}
}
diff --git a/examples/product-sample-supabase-kt/app/build.gradle b/examples/product-sample-supabase-kt/app/build.gradle
index 124dca673ac..c7aae5c480b 100644
--- a/examples/product-sample-supabase-kt/app/build.gradle
+++ b/examples/product-sample-supabase-kt/app/build.gradle
@@ -74,12 +74,12 @@ dependencies {
implementation "androidx.compose.material:material:1.1.1"
// Supabase setup
- implementation "io.github.jan-tennert.supabase:gotrue-kt:1.0.0"
- implementation "io.github.jan-tennert.supabase:postgrest-kt:1.0.0"
- implementation "io.github.jan-tennert.supabase:storage-kt:1.0.0"
- implementation "io.ktor:ktor-client-android:2.3.0"
- implementation "io.ktor:ktor-utils:2.3.0"
- implementation "io.ktor:ktor-client-core:2.3.0"
+ implementation "io.github.jan-tennert.supabase:gotrue-kt:$supabase_version"
+ implementation "io.github.jan-tennert.supabase:postgrest-kt:$supabase_version"
+ implementation "io.github.jan-tennert.supabase:storage-kt:$supabase_version"
+ implementation "io.ktor:ktor-client-android:$ktor_version"
+ implementation "io.ktor:ktor-utils:$ktor_version"
+ implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.coil-kt:coil-compose:1.3.2"
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/AuthenticationRepositoryImpl.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/AuthenticationRepositoryImpl.kt
index 4decea8877e..d02685f0497 100644
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/AuthenticationRepositoryImpl.kt
+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/AuthenticationRepositoryImpl.kt
@@ -1,16 +1,17 @@
package com.example.manageproducts.data.repository.impl
import com.example.manageproducts.data.repository.AuthenticationRepository
-import io.github.jan.supabase.gotrue.GoTrue
+import io.github.jan.supabase.gotrue.Auth
+import io.github.jan.supabase.gotrue.providers.Google
import io.github.jan.supabase.gotrue.providers.builtin.Email
import javax.inject.Inject
class AuthenticationRepositoryImpl @Inject constructor(
- private val goTrue: GoTrue
+ private val auth: Auth,
) : AuthenticationRepository {
override suspend fun signIn(email: String, password: String): Boolean {
return try {
- goTrue.loginWith(Email) {
+ auth.signInWith(Email) {
this.email = email
this.password = password
}
@@ -22,7 +23,7 @@ class AuthenticationRepositoryImpl @Inject constructor(
override suspend fun signUp(email: String, password: String): Boolean {
return try {
- goTrue.signUpWith(Email) {
+ auth.signUpWith(Email) {
this.email = email
this.password = password
}
@@ -34,7 +35,7 @@ class AuthenticationRepositoryImpl @Inject constructor(
override suspend fun signInWithGoogle(): Boolean {
return try {
- goTrue.loginWith(Google)
+ auth.signInWith(Google)
true
} catch (e: Exception) {
false
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/ProductRepositoryImpl.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/ProductRepositoryImpl.kt
index 7e052507057..be482e9c3d6 100644
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/ProductRepositoryImpl.kt
+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/ProductRepositoryImpl.kt
@@ -34,13 +34,17 @@ class ProductRepositoryImpl @Inject constructor(
override suspend fun getProduct(id: String): ProductDto {
return postgrest["products"].select {
- eq("id", id)
+ filter {
+ eq("id", id)
+ }
}.decodeSingle<ProductDto>()
}
override suspend fun deleteProduct(id: String) {
postgrest["products"].delete {
- eq("id", id)
+ filter {
+ eq("id", id)
+ }
}
}
@@ -63,14 +67,18 @@ class ProductRepositoryImpl @Inject constructor(
set("price", price)
set("image", buildImageUrl(imageFileName = imageUrl))
}) {
- eq("id", id)
+ filter {
+ eq("id", id)
+ }
}
} else {
postgrest["products"].update({
set("name", name)
set("price", price)
}) {
- eq("id", id)
+ filter {
+ eq("id", id)
+ }
}
}
}
diff --git a/examples/product-sample-supabase-kt/build.gradle b/examples/product-sample-supabase-kt/build.gradle
index 6a13fa6f511..8e13b3b4a9f 100644
--- a/examples/product-sample-supabase-kt/build.gradle
+++ b/examples/product-sample-supabase-kt/build.gradle
@@ -1,13 +1,14 @@
buildscript {
ext {
- compose_version = '1.2.0'
- hilt_version = '2.44.2'
+ compose_version = '1.3.0'
+ hilt_version = '2.48'
+ ktor_version = '2.3.0'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
- id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
+ id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
id("com.google.dagger.hilt.android") version "2.44" apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.0'
}
\ No newline at end of file