|
|
@@ -2,6 +2,8 @@ package dev.inmo.micro_utils.repos
|
|
|
|
|
|
|
|
|
|
|
|
import android.database.Cursor
|
|
|
|
import android.database.Cursor
|
|
|
|
import android.database.sqlite.SQLiteDatabase
|
|
|
|
import android.database.sqlite.SQLiteDatabase
|
|
|
|
|
|
|
|
import androidx.core.database.*
|
|
|
|
|
|
|
|
import dev.inmo.micro_utils.repos.getLongOrNull
|
|
|
|
|
|
|
|
|
|
|
|
fun createTableQuery(
|
|
|
|
fun createTableQuery(
|
|
|
|
tableName: String,
|
|
|
|
tableName: String,
|
|
|
@@ -32,6 +34,11 @@ fun SQLiteDatabase.createTable(
|
|
|
|
fun Cursor.getString(columnName: String): String = getString(
|
|
|
|
fun Cursor.getString(columnName: String): String = getString(
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
fun Cursor.getStringOrNull(columnName: String): String? {
|
|
|
|
|
|
|
|
return getStringOrNull(
|
|
|
|
|
|
|
|
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
* @throws IllegalArgumentException
|
|
|
@@ -39,6 +46,11 @@ fun Cursor.getString(columnName: String): String = getString(
|
|
|
|
fun Cursor.getShort(columnName: String): Short = getShort(
|
|
|
|
fun Cursor.getShort(columnName: String): Short = getShort(
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
fun Cursor.getShortOrNull(columnName: String): Short? {
|
|
|
|
|
|
|
|
return getShortOrNull(
|
|
|
|
|
|
|
|
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
* @throws IllegalArgumentException
|
|
|
@@ -46,6 +58,11 @@ fun Cursor.getShort(columnName: String): Short = getShort(
|
|
|
|
fun Cursor.getLong(columnName: String): Long = getLong(
|
|
|
|
fun Cursor.getLong(columnName: String): Long = getLong(
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
fun Cursor.getLongOrNull(columnName: String): Long? {
|
|
|
|
|
|
|
|
return getLongOrNull(
|
|
|
|
|
|
|
|
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
* @throws IllegalArgumentException
|
|
|
@@ -53,6 +70,23 @@ fun Cursor.getLong(columnName: String): Long = getLong(
|
|
|
|
fun Cursor.getInt(columnName: String): Int = getInt(
|
|
|
|
fun Cursor.getInt(columnName: String): Int = getInt(
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
fun Cursor.getIntOrNull(columnName: String): Int? {
|
|
|
|
|
|
|
|
return getIntOrNull(
|
|
|
|
|
|
|
|
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
fun Cursor.getFloat(columnName: String): Float = getFloat(
|
|
|
|
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
fun Cursor.getFloatOrNull(columnName: String): Float? {
|
|
|
|
|
|
|
|
return getFloatOrNull(
|
|
|
|
|
|
|
|
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @throws IllegalArgumentException
|
|
|
|
* @throws IllegalArgumentException
|
|
|
@@ -60,6 +94,11 @@ fun Cursor.getInt(columnName: String): Int = getInt(
|
|
|
|
fun Cursor.getDouble(columnName: String): Double = getDouble(
|
|
|
|
fun Cursor.getDouble(columnName: String): Double = getDouble(
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
getColumnIndexOrThrow(columnName)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
fun Cursor.getDoubleOrNull(columnName: String): Double? {
|
|
|
|
|
|
|
|
return getDoubleOrNull(
|
|
|
|
|
|
|
|
getColumnIndex(columnName).takeIf { it != -1 } ?: return null
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun SQLiteDatabase.select(
|
|
|
|
fun SQLiteDatabase.select(
|
|
|
|
table: String,
|
|
|
|
table: String,
|
|
|
|