Skip to content

Kotlin library for developing applications using Turso Platform API

License

Notifications You must be signed in to change notification settings

Jeliuc-Labs/turso-sdk

Repository files navigation

Turso Platform SDK

Turso Platform SDK is a Kotlin library for developing applications using Turso Platform API.

The SDK covers all Platform API resources and provides statically typed classes.

Learn more about the Turso.

Checkout what libSQL can do for you at https://turso.tech/libsql.

Reference Turso SDK in your project

Define version variables

Add package versions in gradle.properties

Example:

ktorVersion=2.3.9
dateTimeVersion=0.6.0-RC.2
logbackVersion=1.5.1
tursoSdkVersion=0.2.0 // currently published version

Add dependencies

Add dependencies to build.gradle.kts

// define version variables
val ktorVersion: String by project
val dateTimeVersion: String by project
val logbackVersion: String by project
val tursoSdkVersion: String by project

// add maven central to repositories
repositories {
    // other repositories
    mavenCentral()
}

dependencies {
    // ...
    implementation("io.ktor:ktor-client-core:$ktorVersion")
    implementation("io.ktor:ktor-client-cio:$ktorVersion")
    implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
    implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
    implementation("org.jetbrains.kotlinx:kotlinx-datetime-jvm:$dateTimeVersion")
    implementation ("ch.qos.logback:logback-classic:$logbackVersion")
    implementation("com.jeliuc:turso-sdk-jvm:$tursoSdkVersion")
    // ...
}

Create Turso auth token

Generate auth token. And copy it somewhere.

turso auth api-tokens mint quickstart

See official documentation.

Use client

Create TursoClient.

val token = "you-api-access-token"

val client = TursoClient.using(CIO.create(), token)

Make your first call

Example: listing databases for an organization.

val organization = "myorg"
val databases = client.databases.list(organization)

Example: creating new database.

val createDatabase = CreateDatabase("databaseName", "databaseGroup")

val databaseCreationResponse = client.databases.create(organization, createDatabase)

Free resources

Don't forget to close the client to free resources when you are done.

client.close()

For full list of examples, check tests.

Future Plans

  • Use kotlinx.datetime for date and time handling
  • Transform into a multiplatform library (KMP) - and support JVM, JS, and Native
  • HRANA3 protocol implementation (WIP)
  • libSQL JDBC driver (WIP)

Contribution

If you've found an error in this sample, please file an issue.
Feel free to help out by sending a pull request ❤️.

Code of Conduct

Disclaimer

Turso and it's logo are trademarks of CHISELSTRIKE INC. All other trademarks are the property of their respective owners.

License

Copyright 2024 Jeliuc.com S.R.L.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0.txt

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Kotlin library for developing applications using Turso Platform API

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages