contains method
Finds all rows whose json, array, or range value on the stated column
contains the values specified in value
.
Pass an array or use brackets in a string for an inclusive range and use parenthesis in a string for an exclusive range:
// On array columns
final data = await supabase
.from('issues')
.select()
.contains('tags', ['is:open', 'priority:low']);
// On range columns
// Finds rows where the `during` column contains the range between
// `2000-01-01 00:00` inclusive and `2000-01-01 23:59` exclusive
final data = await supabase
.from('reservations')
.select()
.contains('during', '[2000-01-01 13:00, 2000-01-01 13:30)');
//On jsonb columns
final data = await supabase
.from('users')
.select('name')
.contains('address', { 'street': 'Melrose Place' });
Implementation
PostgrestFilterBuilder<T> contains(String column, Object value) {
final Uri url;
if (value is String) {
// range types can be inclusive '[', ']' or exclusive '(', ')' so just
// keep it simple and accept a string
url = appendSearchParams(column, 'cs.$value');
} else if (value is List) {
// array
url = appendSearchParams(column, 'cs.{${_cleanFilterArray(value)}}');
} else {
// json
url = appendSearchParams(column, 'cs.${json.encode(value)}');
}
return copyWithUrl(url);
}