Skip to content

Commit 38b3419

Browse files
committed
Add some docs
1 parent 6bf5441 commit 38b3419

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

KSP/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Supabase KSP compiler
2+
3+
Currently only supports generating columns for `@Selectable` types.
4+
5+
To install it, add the KSP Gradle plugin to your project:
6+
7+
```kotlin
8+
plugins {
9+
id("com.google.devtools.ksp") version "2.0.21-1.0.25" //kotlinVersion-kspVersion
10+
}
11+
```
12+
13+
Then add the Supabase KSP compiler to your dependencies:
14+
15+
> [!NOTE]
16+
> `VERSION` is the same as the Supabase-kt version.
17+
18+
**JVM**:
19+
20+
```kotlin
21+
depdencies {
22+
ksp("io.github.jan-tennert.supabase:ksp-compiler:VERSION")
23+
}
24+
```
25+
26+
**Multiplatform**:
27+
28+
```kotlin
29+
kotlin {
30+
//...
31+
jvm()
32+
androidTarget()
33+
iosX64()
34+
//...
35+
}
36+
37+
dependencies {
38+
//Advised to use Gradle Version Catalogs
39+
add("kspCommonMainMetadata", "io.github.jan-tennert.supabase:ksp-compiler:VERSION")
40+
add("kspJvm", "io.github.jan-tennert.supabase:ksp-compiler:VERSION")
41+
add("kspAndroid", "io.github.jan-tennert.supabase:ksp-compiler:VERSION")
42+
add("kspIosX64", "io.github.jan-tennert.supabase:ksp-compiler:VERSION")
43+
}

KSP/src/main/kotlin/io/github/jan/supabase/ksp/SelectableSymbolProcessor.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import com.google.devtools.ksp.symbol.KSFile
1111
import com.google.devtools.ksp.symbol.KSNode
1212
import com.google.devtools.ksp.symbol.KSValueParameter
1313
import com.google.devtools.ksp.symbol.Modifier
14+
import com.squareup.kotlinpoet.AnnotationSpec
15+
import com.squareup.kotlinpoet.ClassName
1416
import com.squareup.kotlinpoet.FileSpec
1517
import com.squareup.kotlinpoet.FunSpec
18+
import io.github.jan.supabase.annotations.SupabaseInternal
1619
import io.github.jan.supabase.postgrest.Postgrest
1720
import io.github.jan.supabase.postgrest.annotations.ApplyFunction
1821
import io.github.jan.supabase.postgrest.annotations.Cast
@@ -61,9 +64,10 @@ class SelectableSymbolProcessor(
6164
columns: Map<String, String>,
6265
sources: List<KSFile>
6366
) {
64-
//Maybe add comments and SupabaseInternal annotations
6567
val function = FunSpec.builder("addSelectableTypes")
6668
.addKdoc(COMMENT)
69+
.addAnnotation(AnnotationSpec.builder(ClassName.bestGuess("kotlin.OptIn")).addMember("%T::class",
70+
SupabaseInternal::class).build())
6771
.receiver(Postgrest.Config::class)
6872
columns.forEach { (qualifiedName, columns) ->
6973
function.addStatement("columnRegistry.registerColumns(\"$qualifiedName\", \"$columns\")")

Postgrest/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ val supabase = createSupabaseClient(
5959
}
6060
```
6161

62+
> [!NOTE]
63+
> Generating columns for `@Selectable` requires the [KSP compiler](/KSP) to be installed.
64+
6265
# Usage
6366

6467
See [Postgrest documentation](https://supabase.com/docs/reference/kotlin/select) for usage

Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/ColumnRegistry.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.github.jan.supabase.postgrest
22

3+
import io.github.jan.supabase.annotations.SupabaseInternal
34
import kotlin.reflect.KClass
45

6+
@SupabaseInternal
57
class ColumnRegistry(
68
private val map: MutableMap<String, String> = mutableMapOf()
79
) {

Postgrest/src/commonMain/kotlin/io/github/jan/supabase/postgrest/Postgrest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package io.github.jan.supabase.postgrest
22

33
import io.github.jan.supabase.SupabaseClient
44
import io.github.jan.supabase.SupabaseSerializer
5-
import io.github.jan.supabase.exceptions.HttpRequestException
5+
import io.github.jan.supabase.annotations.SupabaseInternal
6+
import io.github.jan.supabase.exceptions.RestException
67
import io.github.jan.supabase.logging.SupabaseLogger
78
import io.github.jan.supabase.plugins.CustomSerializationConfig
89
import io.github.jan.supabase.plugins.CustomSerializationPlugin
@@ -101,7 +102,7 @@ interface Postgrest : MainPlugin<Postgrest.Config>, CustomSerializationPlugin {
101102
data class Config(
102103
var defaultSchema: String = "public",
103104
var propertyConversionMethod: PropertyConversionMethod = PropertyConversionMethod.CAMEL_CASE_TO_SNAKE_CASE,
104-
var columnRegistry: ColumnRegistry = ColumnRegistry()
105+
@property:SupabaseInternal var columnRegistry: ColumnRegistry = ColumnRegistry()
105106
): MainConfig(), CustomSerializationConfig {
106107

107108
override var serializer: SupabaseSerializer? = null

0 commit comments

Comments
 (0)