A thin wrapper library for android.database.sqlite.SQLiteOpenHelper
, providing enhanced database operation capabilities through the use of Kotlin Coroutines.
val liteSQLite = LiteSQLite(context, "TestDatabase.db", 1)
liteSQLite.execSQL(
"""
DROP TABLE IF EXISTS user;
""",
"""
CREATE TABLE user (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
gender TEXT NOT NULL
)
""",
"""INSERT INTO user (id, name, gender) VALUES (0, 'John Doe', 'Male');""",
"""INSERT INTO user (id, name, gender) VALUES (1, 'Sam Smith', 'Male');""",
"""INSERT INTO user (id, name, gender) VALUES (2, 'Jane Doe', 'Female');""",
"""INSERT INTO user (id, name, gender) VALUES (3, 'Emma Brown', 'Female');"""
)
data class User(val id: Int, val name: String, val gender: String)
val records = liteSQLite.rawQuery("SELECT * FROM user ORDER BY id", null) { cursor ->
User(
id = cursor["id"] ?: 0,
name = cursor["name"] ?: "",
gender = cursor["gender"] ?: "",
)
}