findByUUID<T extends Model> static method

Future<T?> findByUUID<T extends Model>(
  1. String uuid
)

Finds record by uuid.

Implementation

static Future<T?> findByUUID<T extends Model>(String uuid) async {
  final constructor = _jsonConstructors[T];
  if (constructor == null) return null;

  try {
    final maps = await _database.query(
      _getTableName<T>(),
      where: 'uuid = ?',
      whereArgs: [uuid],
      limit: 1,
    );

    if (maps.isNotEmpty) {
      return constructor(maps.first) as T;
    }
    return null;
  } catch (e) {
    print('SQLite findByUUID error: $e');
    return null;
  }
}