
A versatile SDK offers seamless integration with Pocketbase, enabling full type safety, coroutine support, real-time subscriptions, DSL for queries, and comprehensive API access for CRUD operations and authentication.
A multiplatform Kotlin SDK for Pocketbase designed to work seamlessly across multiple platforms with full type safety and coroutine support.
| Platform | Support |
|---|---|
| Android | β |
| iOS (ARM64) | β |
| iOS (x64) | β |
| iOS Simulator (ARM64) | β |
Add the dependency to your build.gradle.kts:
dependencies {
implementation("dev.abd3lraouf:pocketbase-kotlin:1.0.0")
}Note: This library requires the Kotlinx Serialization plugin.
import dev.abd3lraouf.libs.pocketbase.kotlin.PocketbaseClient
import io.ktor.http.*
val client = PocketbaseClient(
baseUrl = {
protocol = URLProtocol.HTTP
host = "localhost"
port = 8090
}
)import dev.abd3lraouf.libs.pocketbase.kotlin.dsl.login
import dev.abd3lraouf.libs.pocketbase.kotlin.models.AuthRecord
// Authenticate with email and password
val authResponse = client.records.authWithPassword<AuthRecord>(
collection = "users",
email = "user@example.com",
password = "password123"
)
// Login with the received token
client.login {
token = authResponse.token
}import dev.abd3lraouf.libs.pocketbase.kotlin.models.Record
import kotlinx.serialization.Serializable
// Define your record model
@Serializable
data class Task(
val title: String,
val completed: Boolean = false,
val description: String? = null
) : Record()
// Create a record
val newTask = Task(title = "Learn Pocketbase Kotlin", completed = false)
val createdTask = client.records.create<Task>(
collection = "tasks",
body = newTask
)
// Get records with filtering
val tasks = client.records.getList<Task>(
collection = "tasks",
page = 1,
perPage = 20,
filter = Filter("completed = false")
)
// Update a record
val updatedTask = client.records.update<Task>(
collection = "tasks",
id = createdTask.id,
body = createdTask.copy(completed = true)
)import dev.abd3lraouf.libs.pocketbase.kotlin.dsl.query.*
// Advanced querying with DSL
val results = client.records.getList<Task>(
collection = "tasks",
page = 1,
perPage = 10,
filter = Filter("title ~ 'Learn' && completed = false"),
sort = Sort("-created", "title"),
expand = Expand("user", "category"),
fields = ShowFields("id", "title", "completed", "user.name")
)// Subscribe to real-time changes
client.realtime.subscribe("tasks") { event ->
when (event.action) {
"create" -> println("New task created: ${event.record}")
"update" -> println("Task updated: ${event.record}")
"delete" -> println("Task deleted: ${event.record}")
}
}import dev.abd3lraouf.libs.pocketbase.kotlin.dsl.BatchRequestBuilder
// Perform multiple operations in a single request
val results = client.batch.send {
create("tasks", Task("Task 1", false))
create("tasks", Task("Task 2", true))
update("tasks", "RECORD_ID", Task("Updated Task", true))
delete("tasks", "RECORD_ID_TO_DELETE")
}import dev.abd3lraouf.libs.pocketbase.kotlin.FileUpload
@Serializable
data class Post(
val title: String,
val content: String,
val image: String? = null
) : Record()
// Upload file with record
val post = client.records.create<Post>(
collection = "posts",
body = mapOf(
"title" to "My Post".toJsonPrimitive(),
"content" to "Post content".toJsonPrimitive()
),
files = listOf(
FileUpload(
fieldName = "image",
data = imageByteArray,
fileName = "image.jpg"
)
)
)@Serializable
data class User(val name: String, val email: String) : Record()
@Serializable
data class Post(
val title: String,
val content: String,
val author: String // User ID
) : ExpandRecord<User>()
// Get posts with expanded user data
val posts = client.records.getList<Post>(
collection = "posts",
expandRelations = ExpandRelations("author")
)
// Access expanded data
val authorName = posts.items.first().expand?.get("author")?.name// OAuth2 authentication
val oauthResponse = client.records.authWithOauth2<AuthRecord>(
collection = "users",
provider = "google",
code = "oauth_code",
codeVerifier = "code_verifier",
redirectUrl = "https://your-app.com/callback"
)records - CRUD operations for records and authenticationcollections - Collection managementfiles - File operationsrealtime - Real-time subscriptionshealth - Health check endpointsettings - Server settingsbackups - Backup operationslogs - Log managementbatch - Batch operationsRecord - Base record modelAuthRecord - Authenticated record modelCollection - Collection schema modelUser - User modelAdmin - Admin modelFilter - Query filteringSort - Result sortingExpand - Relation expansionShowFields - Field selectionBatchRequestBuilder - Batch operationsCheck out the examples directory for more detailed usage examples:
We welcome contributions! Please see our Contributing Guide for details.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
A multiplatform Kotlin SDK for Pocketbase designed to work seamlessly across multiple platforms with full type safety and coroutine support.
| Platform | Support |
|---|---|
| Android | β |
| iOS (ARM64) | β |
| iOS (x64) | β |
| iOS Simulator (ARM64) | β |
Add the dependency to your build.gradle.kts:
dependencies {
implementation("dev.abd3lraouf:pocketbase-kotlin:1.0.0")
}Note: This library requires the Kotlinx Serialization plugin.
import dev.abd3lraouf.libs.pocketbase.kotlin.PocketbaseClient
import io.ktor.http.*
val client = PocketbaseClient(
baseUrl = {
protocol = URLProtocol.HTTP
host = "localhost"
port = 8090
}
)import dev.abd3lraouf.libs.pocketbase.kotlin.dsl.login
import dev.abd3lraouf.libs.pocketbase.kotlin.models.AuthRecord
// Authenticate with email and password
val authResponse = client.records.authWithPassword<AuthRecord>(
collection = "users",
email = "user@example.com",
password = "password123"
)
// Login with the received token
client.login {
token = authResponse.token
}import dev.abd3lraouf.libs.pocketbase.kotlin.models.Record
import kotlinx.serialization.Serializable
// Define your record model
@Serializable
data class Task(
val title: String,
val completed: Boolean = false,
val description: String? = null
) : Record()
// Create a record
val newTask = Task(title = "Learn Pocketbase Kotlin", completed = false)
val createdTask = client.records.create<Task>(
collection = "tasks",
body = newTask
)
// Get records with filtering
val tasks = client.records.getList<Task>(
collection = "tasks",
page = 1,
perPage = 20,
filter = Filter("completed = false")
)
// Update a record
val updatedTask = client.records.update<Task>(
collection = "tasks",
id = createdTask.id,
body = createdTask.copy(completed = true)
)import dev.abd3lraouf.libs.pocketbase.kotlin.dsl.query.*
// Advanced querying with DSL
val results = client.records.getList<Task>(
collection = "tasks",
page = 1,
perPage = 10,
filter = Filter("title ~ 'Learn' && completed = false"),
sort = Sort("-created", "title"),
expand = Expand("user", "category"),
fields = ShowFields("id", "title", "completed", "user.name")
)// Subscribe to real-time changes
client.realtime.subscribe("tasks") { event ->
when (event.action) {
"create" -> println("New task created: ${event.record}")
"update" -> println("Task updated: ${event.record}")
"delete" -> println("Task deleted: ${event.record}")
}
}import dev.abd3lraouf.libs.pocketbase.kotlin.dsl.BatchRequestBuilder
// Perform multiple operations in a single request
val results = client.batch.send {
create("tasks", Task("Task 1", false))
create("tasks", Task("Task 2", true))
update("tasks", "RECORD_ID", Task("Updated Task", true))
delete("tasks", "RECORD_ID_TO_DELETE")
}import dev.abd3lraouf.libs.pocketbase.kotlin.FileUpload
@Serializable
data class Post(
val title: String,
val content: String,
val image: String? = null
) : Record()
// Upload file with record
val post = client.records.create<Post>(
collection = "posts",
body = mapOf(
"title" to "My Post".toJsonPrimitive(),
"content" to "Post content".toJsonPrimitive()
),
files = listOf(
FileUpload(
fieldName = "image",
data = imageByteArray,
fileName = "image.jpg"
)
)
)@Serializable
data class User(val name: String, val email: String) : Record()
@Serializable
data class Post(
val title: String,
val content: String,
val author: String // User ID
) : ExpandRecord<User>()
// Get posts with expanded user data
val posts = client.records.getList<Post>(
collection = "posts",
expandRelations = ExpandRelations("author")
)
// Access expanded data
val authorName = posts.items.first().expand?.get("author")?.name// OAuth2 authentication
val oauthResponse = client.records.authWithOauth2<AuthRecord>(
collection = "users",
provider = "google",
code = "oauth_code",
codeVerifier = "code_verifier",
redirectUrl = "https://your-app.com/callback"
)records - CRUD operations for records and authenticationcollections - Collection managementfiles - File operationsrealtime - Real-time subscriptionshealth - Health check endpointsettings - Server settingsbackups - Backup operationslogs - Log managementbatch - Batch operationsRecord - Base record modelAuthRecord - Authenticated record modelCollection - Collection schema modelUser - User modelAdmin - Admin modelFilter - Query filteringSort - Result sortingExpand - Relation expansionShowFields - Field selectionBatchRequestBuilder - Batch operationsCheck out the examples directory for more detailed usage examples:
We welcome contributions! Please see our Contributing Guide for details.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.