Package-level declarations

import com.kqlite.column.Bind
import com.kqlite.column.CURRENT_TIMESTAMP
import com.kqlite.column.notNull
import com.kqlite.cursor.KQLiteCursor
import com.kqlite.demo.contacts.model.Contact
import com.kqlite.demo.contacts.model.ContactType
import com.kqlite.demo.contacts.utils.toDateString
import com.kqlite.demo.contacts.utils.toInstant
import com.kqlite.functions.DATE
import com.kqlite.functions.JSON_ARRAY
import com.kqlite.table.KQLiteAdapter
import com.kqlite.table.KQLiteTable

object TblContact : KQLiteTable("contacts"), KQLiteAdapter<Contact> {
val id = intColumn("id").notNull().primaryKey().autoIncrement()
val firstName = textColumn("first_name").notNull()
val lastName = textColumn("last_name")
val phone = jsonArrayColumn("phone").notNull()
val birthDate = dateColumn("birth_date")
val email = textColumn("email").check { (it IS null) OR (it LIKE "%_@__%.__%") }
val image = blobColumn("image")
val type = enumColumn("type", ContactType.entries).notNull()
val deleted = booleanColumn("deleted").notNull().default(false)
val lastModified = dateTimeColumn("last_modified")

override fun binder(
bind: Bind,
item: Contact
) {
bind.apply {
firstName.bind(item.firstName)
lastName.bind(item.lastName)
phone.bind(JSON_ARRAY(*item.phone.toTypedArray()))
if (item.birthDate != null) birthDate.bind(DATE(item.birthDate.toDateString()))
else birthDate.bind(null)
email.bind(item.email)
image.bind(item.image)
type.bind(item.type)
lastModified.bind(CURRENT_TIMESTAMP)
}
}

override fun mapper(cursor: KQLiteCursor): Contact {
return Contact(
id = cursor[id],
firstName = cursor[firstName],
lastName = cursor[lastName],
phone = cursor[phone].getText().trim('[', ']').split(',').map { it.trim('"', '"') },
birthDate = cursor[birthDate]?.getText()?.toInstant(),
email = cursor[email],
image = cursor[image],
type = cursor[type],
deleted = cursor[deleted]
)
}
}

Types

Link copied to clipboard
enum Action : Enum<Action>

Specifies the ON CONFLICT action to be taken when a constraint violation occurs.

Link copied to clipboard
sealed class AliasTable(original: KQLiteTable, tblAlias: String) : KQLiteTable

Represents a table with an alias in a SQL query.

Link copied to clipboard

Specifies the COLLATE sequence to be used for text comparisons in a column.

Link copied to clipboard

Represents the set of actions that can be specified for an ON DELETE or ON UPDATE clause of a foreign key constraint in a database. These actions determine how the database should behave when a referenced key is deleted or updated.

Link copied to clipboard
enum JoinOp : Enum<JoinOp>

Represents the comparison operators used in a JOIN clause in SELECT statement.

Link copied to clipboard
class JSON_EACH @JvmOverloads constructor(json: KQLiteColumn<*>, path: String? = null) : JsonColumns

Represents the SQLite json_each() table-valued function.

Link copied to clipboard
class JSON_TREE @JvmOverloads constructor(json: KQLiteColumn<*>, path: String? = null) : JsonColumns

Represents the SQLite json_tree() table-valued function.

Link copied to clipboard
sealed class JsonColumns(name: String, alias: KQLiteColumn<String>) : KQLiteTable

Represents the structure of the virtual table returned by SQLite's JSON table-valued functions, specifically json_each() and json_tree(). This sealed class defines the common columns available in the result set of these functions.

Link copied to clipboard
interface KQLiteAdapter<T>

An adapter responsible for converting between a database row and a Kotlin object of type T.

Link copied to clipboard
abstract class KQLiteTable @JvmOverloads constructor(name: String, temp: Boolean = false, ifNotExists: Boolean = true, strict: Boolean = false, withoutRowId: Boolean = false)

Represents a database table definition in KQLite.

Link copied to clipboard
sealed class MasterColumns(name: String) : KQLiteTable

Represents the schema of the special SQLite master tables (sqlite_schema, sqlite_master, etc.). These tables are read-only and contain the schema for all other tables and indices in the database.

Link copied to clipboard
class SQLiteMaster @JvmOverloads constructor(temp: Boolean = false) : MasterColumns

Represents the sqlite_master table in a SQLite database.

Link copied to clipboard
class SQLiteSchema @JvmOverloads constructor(temp: Boolean = false) : MasterColumns

Represents the sqlite_schema table in a SQLite database.

Link copied to clipboard

Represents the internal sqlite_sequence table in SQLite.