Add Kotlin snippets to postgres docs (#20974)
add kotlin snippets to postgres docs Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
This commit is contained in:
@@ -85,6 +85,13 @@ select function_name();
|
||||
const { data, error } = supabase.rpc('function_name')
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.postgrest.rpc("function_name")
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
|
||||
@@ -141,6 +141,25 @@ await supabase.from('restaurants').insert([
|
||||
]);
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
@Serializable
|
||||
data class Restaurant(
|
||||
val name: String,
|
||||
val location: String //you could also use a custom type with a custom serializer for more type safety
|
||||
)
|
||||
```
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("restaurants").insert(listOf(
|
||||
Restaurant("Supa Burger", "POINT(-73.946823 40.807416)"),
|
||||
Restaurant("Supa Pizza", "POINT(-73.94581 40.807475)"),
|
||||
Restaurant("Supa Taco", "POINT(-73.945826 40.80629)"),
|
||||
))
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -198,6 +217,19 @@ final data = await supabase.rpc('nearby_restaurants',params: {
|
||||
});
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.postgrest.rpc(
|
||||
function = "nearby_restaurants",
|
||||
parameters = buildJsonObject { //You can put here any serializable object including your own classes
|
||||
put("lat", 40.807313)
|
||||
put("lon", -73.946713)
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="result" label="Result">
|
||||
|
||||
@@ -284,6 +316,21 @@ final data = await supabase.rpc('restaurants_in_view', params: {
|
||||
});
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.postgrest.rpc(
|
||||
function = "restaurants_in_view",
|
||||
parameters = buildJsonObject { //You can put here any serializable object including your own classes
|
||||
put("min_lat", 40.807)
|
||||
put("min_lon", -73.946)
|
||||
put("max_lat", 40.808)
|
||||
put("max_lon", -73.945)
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="result" label="Result">
|
||||
|
||||
|
||||
@@ -136,6 +136,17 @@ final result = await client
|
||||
.eq('title', 'Harry');
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
eq("title", "Harry")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -174,6 +185,17 @@ final result = await client
|
||||
.textSearch('title', "'Harry'");
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("title", "'Harry'", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -219,6 +241,17 @@ final result = await client
|
||||
.textSearch('description', "'big'");
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("description", "'big'", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="data" label="Data">
|
||||
|
||||
@@ -287,6 +320,23 @@ final result = await client
|
||||
.textSearch('title_description', "little")
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```sql
|
||||
create function title_description(books) returns text as $$
|
||||
select $1.title || ' ' || $1.description;
|
||||
$$ language sql immutable;
|
||||
```
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("title_description", "title", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="data" label="Data">
|
||||
|
||||
@@ -341,6 +391,17 @@ final result = await client
|
||||
.textSearch('description', "'little' & 'big'");
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("description", "'title' & 'big'", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="data" label="Data">
|
||||
|
||||
@@ -394,6 +455,17 @@ final result = await client
|
||||
.textSearch('description', "'little' | 'big'");
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("description", "'title' | 'big'", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="data" label="Data">
|
||||
|
||||
@@ -494,6 +566,17 @@ final result = await client
|
||||
.textSearch('fts', "'little' & 'big'");
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("fts", "'title' & 'big'", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="data" label="Data">
|
||||
|
||||
@@ -552,6 +635,17 @@ final result = await client
|
||||
.textSearch('description', "'big' <-> 'dreams'");
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("description", "'big' <-> 'dreams'", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -595,6 +689,17 @@ final result = await client
|
||||
.textSearch('description', "'year' <2> 'school'");
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("description", "'year' <2> 'school'", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -641,6 +746,17 @@ final result = await client
|
||||
.textSearch('description', "'big' & !'little'");
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select {
|
||||
filter {
|
||||
textSearch("description", "'big' & !'little'", TextSearchType.NONE)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
|
||||
@@ -96,6 +96,15 @@ final data = await supabase
|
||||
|
||||
Reference: [rpc()](../../reference/dart/rpc)
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.postgrest.rpc("hello_world")
|
||||
```
|
||||
|
||||
Reference: [rpc()](../../reference/kotlin/rpc)
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -209,6 +218,17 @@ final data = await supabase
|
||||
.eq('id', 1);
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.postgrest.rpc("get_planets") {
|
||||
filter {
|
||||
eq("id", 1)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -263,6 +283,18 @@ final data = await supabase
|
||||
.rpc('add_planet', params: { 'name': 'Jakku' });
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.postgrest.rpc(
|
||||
function = "add_planet",
|
||||
parameters = buildJsonObject { //You can put here any serializable object including your own classes
|
||||
put("name", "Jakku")
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
|
||||
@@ -137,6 +137,13 @@ const countriesWithCities: CountriesWithCities = data
|
||||
final data = await supabase.from('countries').select('id, name, cities(id, name)');
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("countries").select(Columns.raw("id, name, cities(id, name)"))
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="graphql" label="GraphQL">
|
||||
|
||||
@@ -217,6 +224,13 @@ const { data, error } = await supabase.from('teams').select(`
|
||||
final data = await supabase.from('teams').select('id, team_name, users(id, name)');
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("teams").select(Columns.raw("id, team_name, users(id, name)"));
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="graphql" label="GraphQL">
|
||||
|
||||
|
||||
@@ -179,6 +179,35 @@ const { data, error } = await supabase.from('books').insert([
|
||||
])
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
@Serializable
|
||||
data class BookMetadata(
|
||||
val description: String,
|
||||
val price: Double,
|
||||
val ages: List<Int>
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Book(
|
||||
val title: String,
|
||||
val author: String,
|
||||
val metadata: BookMetadata
|
||||
)
|
||||
```
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").insert(listOf(
|
||||
Book("The Poky Little Puppy", "Janette Sebring Lowrey", BookMetadata("Puppy is slower than other, bigger animals.", 5.95, listOf(3, 6))),
|
||||
Book("Tale of Peter Rabbit", "Beatrix Potter", BookMetadata("Rabbit eats some vegetables.", 4.49, listOf(2, 5))),
|
||||
Book("Tootle", "Gertrude Crampton", BookMetadata("Little toy train has big dreams.", 3.99, listOf(2, 5))),
|
||||
Book("Green Eggs and Ham", "Dr. Seuss", BookMetadata("Sam has changing food preferences and eats unusually colored food.", 7.49, listOf(4, 8))),
|
||||
Book("Harry Potter and the Goblet of Fire", "J.K. Rowling", BookMetadata("Fourth year of school starts, big drama ensues.", 24.95, listOf(10, 99)))
|
||||
))
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
@@ -220,6 +249,19 @@ const { data, error } = await supabase.from('books').select(`
|
||||
`)
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
val data = supabase.from("books").select(Columns.raw("""
|
||||
title,
|
||||
description: metadata->description,
|
||||
price: metadata->price,
|
||||
low_age: metadata->ages->0,
|
||||
high_age: metadata->ages->1
|
||||
""".trimIndent()))
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="result" label="Result">
|
||||
|
||||
|
||||
@@ -202,22 +202,25 @@ values
|
||||
</TabPanel>
|
||||
<TabPanel id="js" label="JavaScript">
|
||||
|
||||
```sql
|
||||
const { data, error } = await supabase
|
||||
.from('movies')
|
||||
.insert([{
|
||||
```js
|
||||
const { data, error } = await supabase.from('movies').insert([
|
||||
{
|
||||
name: 'The Empire Strikes Back',
|
||||
description: 'After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda.'
|
||||
}, {
|
||||
description:
|
||||
'After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda.',
|
||||
},
|
||||
{
|
||||
name: 'Return of the Jedi',
|
||||
description: 'After a daring mission to rescue Han Solo from Jabba the Hutt, the Rebels dispatch to Endor to destroy the second Death Star.'
|
||||
}])
|
||||
description:
|
||||
'After a daring mission to rescue Han Solo from Jabba the Hutt, the Rebels dispatch to Endor to destroy the second Death Star.',
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="dart" label="Dart">
|
||||
|
||||
```sql
|
||||
```dart
|
||||
await supabase
|
||||
.from('movies')
|
||||
.insert([{
|
||||
@@ -229,6 +232,26 @@ await supabase
|
||||
}]);
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
<TabPanel id="kotlin" label="Kotlin">
|
||||
|
||||
```kotlin
|
||||
@Serializable
|
||||
data class Movie(
|
||||
val name: String,
|
||||
val description: String
|
||||
)
|
||||
```
|
||||
|
||||
```kotlin
|
||||
supabase
|
||||
.from("movies")
|
||||
.insert(listOf(
|
||||
Movie("The Empire Strikes Back", "After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda."),
|
||||
Movie("Return of the Jedi", "After a daring mission to rescue Han Solo from Jabba the Hutt, the Rebels dispatch to Endor to destroy the second Death Star."),
|
||||
))
|
||||
```
|
||||
|
||||
</TabPanel>
|
||||
</Tabs>
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
- [x] Veritabanı Fonksiyonları. [Dokümanlar](https://supabase.com/docs/guides/database/functions)
|
||||
- [x] Kenar İşlevleri [Dokümanlar](https://supabase.com/docs/guides/functions)
|
||||
- [x] Dosya Depolama. [Docs](https://supabase.com/docs/guides/storage)
|
||||
- [X] AI + Vektör / Gömme Araçları. [Dokümanlar](https://supabase.com/docs/guides/ai)
|
||||
- [x] AI + Vektör / Gömme Araçları. [Dokümanlar](https://supabase.com/docs/guides/ai)
|
||||
- [x] Gösterge Tablosu
|
||||
|
||||

|
||||
|
||||
Reference in New Issue
Block a user