getLogin<T> method

Future<T?> getLogin<T>(
  1. Object tableEntityInstance,
  2. String identifierColumnName,
  3. String identifierValue,
  4. String passwordColumnName,
  5. String passwordValue,
)

Authenticates a user by matching identifierColumnName=identifierValue and passwordColumnName=passwordValue against the entity table T.

Returns the matching entity instance or null if no row matches.

Throws DatabaseException if the entity table does not exist. Wrap the call in try/catch if you are not sure that the table was created.

Implementation

Future<T?> getLogin<T>(
  Object tableEntityInstance,
  String identifierColumnName,
  String identifierValue,
  String passwordColumnName,
  String passwordValue,
) async {
  final List<Map<String, Object?>> rows = await (await db).transaction(
    (txn) => txn.rawQuery(
      'SELECT * FROM ${T.toString()} '
      'WHERE $identifierColumnName = ? AND $passwordColumnName = ?',
      <String>[identifierValue, passwordValue],
    ),
  );
  if (rows.isEmpty) return null;
  return (tableEntityInstance as dynamic).fromMap(rows.first) as T;
}