select static method
TODO ... select need to completely support all the following parameters: Select using the assembled SQL, return List<Map<String, Object?>> or Map<String, Object?> or Object?
Implementation
// distinct
// columns
// where
// whereArgs
// groupBy
// having
// orderBy
// limit
// offset
/// Select using the assembled SQL, return List<Map<String, Object?>> or Map<String, Object?> or Object?
static Future<Object?> select(DatabaseExecutor db, String tableName, List<String> columns,
{String? where, List<Object?>? whereArgs, bool isUnique = false}) async {
// ignore: non_constant_identifier_names
String __SEPARATOR__ = ", ";
String fields = columns.join(__SEPARATOR__);
if (fields.isEmpty) fields = "*";
String sql = "SELECT $fields FROM $tableName";
/// Assemble where clause
if (where != null && (where = where.trim()).isNotEmpty) {
if (!where.startsWith("WHERE")) where = "WHERE " + where;
sql = sql + " " + where;
}
/// Execute the sql
List<Map<String, Object?>> result = await db.rawQuery(sql, whereArgs);
/// If just want only one field value
if (isUnique) {
/// return T is Map<String, Object?> or Object?
return fields.contains(__SEPARATOR__) ? result.firstSafe : result.firstSafe?.values.firstSafe;
} else {
/// return T is List<Map<String, Object?>>
return result;
}
}