Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

ferhatwi/supabase-database-kt

Repository files navigation

Library for Supabase Database with Realtime

Install

With BOM

Maven Central

dependencies {  
 implementation platform("io.github.ferhatwi:supabase-kt-bom:{BOM_VERSION}")
 implementation "io.github.ferhatwi:supabase-database-kt"
}  

Without BOM

Maven Central

NOTICE: BOM is strongly recommended to prevent conflicts.

dependencies {  
 implementation "io.github.ferhatwi:supabase-database-kt:{DATABASE_VERSION}"
}  

How to use?

REMINDER

Supabase should be initialized before using this library. Instructions are here.

val db = Supabase.database()  

RPC

db.rpc.request<List<SomeDataClass>>(
    schema = SCHEMA,
    function = FUNCTION,
    selections = listOf(SELECTION, SELECTION2),
    count = COUNT,
    filters = listOf(FILTER, FILTER2),
    orders = listOf(ORDER, ORDER2),
    range = FROM to TO,
    data = DATA
).catch {

}.collect {

}

Get

db.get.request<List<SomeDataClass>>(
    schema = SCHEMA,
    table = FUNCTION,
    selections = listOf(SELECTION, SELECTION2),
    count = COUNT,
    filters = listOf(FILTER, FILTER2),
    orders = listOf(ORDER, ORDER2),
    range = FROM to TO
).catch {

}.collect {

}

Delete

db.delete.request<List<SomeDataClass>>(
    schema = SCHEMA,
    table = FUNCTION,
    selections = listOf(SELECTION, SELECTION2),
    count = COUNT,
    filters = listOf(FILTER, FILTER2),
    orders = listOf(ORDER, ORDER2),
    range = FROM to TO
).catch {

}.collect {

}

Update

db.update.request<List<SomeDataClass>>(
    schema = SCHEMA,
    table = FUNCTION,
    selections = listOf(SELECTION, SELECTION2),
    count = COUNT,
    filters = listOf(FILTER, FILTER2),
    orders = listOf(ORDER, ORDER2),
    range = FROM to TO,
    data = DATA,
).catch {

}.collect {

}

Insert

db.insert.request<List<SomeDataClass>>(
    schema = SCHEMA,
    table = FUNCTION,
    selections = listOf(SELECTION, SELECTION2),
    count = COUNT,
    orders = listOf(ORDER, ORDER2),
    range = FROM to TO,
    data = DATA
).catch {

}.collect {

}

Upsert

db.upsert.request<List<SomeDataClass>>(
    schema = SCHEMA,
    table = FUNCTION,
    selections = listOf(SELECTION, SELECTION2),
    count = COUNT,
    orders = listOf(ORDER, ORDER2),
    range = FROM to TO,
    data = DATA
).catch {

}.collect {

}

Listen

db.listen.request<List<SomeDataClass>>(
    schema = SCHEMA,
    table = FUNCTION,
    events = listOf(Event.INSERT, Event.UPDATE, Event.DELETE),
    filter = Filter.EqualTo(COLUMN, VALUE)
).cancellable()
    .catch {

    }
    .collect {

    }

Improvements and Bugs

Feel free to improve, upgrade, fix or report bugs!