Collections
data class Post(val title: String, val body: String)
val posts = client.collection("posts", Post::class.java)import com.bunbase.sdk.ListQueryimport 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 pageCursor pagination
Section titled “Cursor pagination”var cursor: String? = nulldo { val page = posts.list(ListQuery(limit = 50, after = cursor)) // process page.items cursor = page.nextCursor} while (cursor != null)Get by ID
Section titled “Get by ID”val post = posts.get("post_id")
// Expand related recordsval post = posts.get("post_id", expand = listOf("author"))Create
Section titled “Create”data class NewPost(val title: String, val body: String)val post = posts.create(NewPost("Hello", "World"))println(post) // returns Post decoded from responseUpdate (patch)
Section titled “Update (patch)”val updated = posts.update("post_id", mapOf("title" to "Updated title"))Delete (soft)
Section titled “Delete (soft)”posts.delete("post_id")Restore
Section titled “Restore”posts.restore("post_id")val total = posts.count()
// With filterval published = posts.count(filter = mapOf("status" to FilterValue.Str("published")))
// Include soft-deletedval all = posts.count(includeDeleted = true)Batch create
Section titled “Batch create”val items = listOf(NewPost("A", "..."), NewPost("B", "..."))val created = posts.createMany(items)Filter operators
Section titled “Filter operators”// EqualityFilterValue.Str("published")FilterValue.Int(42)FilterValue.Bool(true)
// Array (IN)FilterValue.StrList(listOf("draft", "published"))
// Comparison operatorsFilterValue.Op(mapOf("gte" to FilterValue.Int(18)))FilterValue.Op(mapOf("lt" to FilterValue.Dbl(100.0)))FilterValue.Op(mapOf("neq" to FilterValue.Str("deleted")))Channel helpers (for realtime)
Section titled “Channel helpers (for realtime)”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)