Skip to content
BunBase BunBase BunBase Docs Alpha v0.1.0

Collections

data class Post(val title: String, val body: String)
val posts = client.collection("posts", Post::class.java)
import com.bunbase.sdk.ListQuery
import com.bunbase.sdk.FilterValue
val result = posts.list(
ListQuery(
sort = "-_created_at",
limit = 20,
filter = mapOf("status" to FilterValue.Str("published")),
)
)
result.items.forEach { println(it.title) }
println(result.nextCursor) // null = last page
var cursor: String? = null
do {
val page = posts.list(ListQuery(limit = 50, after = cursor))
// process page.items
cursor = page.nextCursor
} while (cursor != null)
val post = posts.get("post_id")
// Expand related records
val post = posts.get("post_id", expand = listOf("author"))
data class NewPost(val title: String, val body: String)
val post = posts.create(NewPost("Hello", "World"))
println(post) // returns Post decoded from response
val updated = posts.update("post_id", mapOf("title" to "Updated title"))
posts.delete("post_id")
posts.restore("post_id")
val total = posts.count()
// With filter
val published = posts.count(filter = mapOf("status" to FilterValue.Str("published")))
// Include soft-deleted
val all = posts.count(includeDeleted = true)
val items = listOf(NewPost("A", "..."), NewPost("B", "..."))
val created = posts.createMany(items)
// Equality
FilterValue.Str("published")
FilterValue.Int(42)
FilterValue.Bool(true)
// Array (IN)
FilterValue.StrList(listOf("draft", "published"))
// Comparison operators
FilterValue.Op(mapOf("gte" to FilterValue.Int(18)))
FilterValue.Op(mapOf("lt" to FilterValue.Dbl(100.0)))
FilterValue.Op(mapOf("neq" to FilterValue.Str("deleted")))
posts.channel // "collection:posts"
posts.mineChannel // "collection:posts:mine" (current user's records)
posts.recordChannel("id") // "record:posts:id"
posts.recordsChannel // "records:posts" (multi-record subscriptions)