A lightweight Kotlin multiplatform library that turns Google Sheets into a remote mini-database.
- Basic database functions: CRUD
- Type safe
- Fast and light
- Multiplatform (soon)
Sheets-DB is published on Maven Central
repositories {
mavenCentral()
}
Include the dependency. Latest version
implementation("io.github.cherrio-llc:sheets-db:<version>")
Init Sheets DB
val sheetDb = SheetsDb {
bearerToken = "your_token"
sheetId = "google_sheet_id" //it is always embedded in the URL
}
Create a data class that will map to a sheet column names. This data class must be annotated with
@Serializable
from the kotlinx.serialization library. You can map the Google sheet column names to
the created data class, or you can provide @SerialName()
@Serializable
data class User(
@SerialName("firstName")
val name: String,
val id: Int,
val email: String?
)
NOTE: The class name must match the sheet's name on the spreadsheet. In this example, the class
User
is a name of a sheet. Check the image below. Also your first column of a row should be anid
for better queries.
val table = sheetDb.getTable<User>()
This getTable
function returns a SheetTable<T>
that you will subsequently use for CRUD ops
Read your table
val table = sheetDb.get() //returns List<User>
Query your table
val result = table.find(User::id eq 1) //returns a List or empty list if no match
Add data to your table.
val user = User("Guy Merve", 11, "guy@email.com")
val result = table.create(user)
Update a specific row using its id
you have to pass in the id.
You can pass in the only fields that needs updating. Here we don't want to update the email
val user = User("Capt Marvel", 5, null)
val result = table.create(user)
There's a lot of updates to come.
- Delete api
- More platforms
- E.t.c
Copyright 2022 Ayodele Kehinde
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
http://www.apache.org/licenses/LICENSE-2.0
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.