containedBy method
Finds all rows whose json, array, or range value on the stated column
is contained by the specified 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('classes')
.select('name')
.containedBy('days', ['monday', 'tuesday', 'wednesday', 'friday']);
// On range columns
// Finds rows where the `during` column is contained between
// `2000-01-01 00:00` inclusive and `2000-01-01 23:59` exclusive
final data = await supabase
.from('reservations')
.select()
.containedBy('during', '[2000-01-01 00:00, 2000-01-01 23:59)');
// On jsonb columns
final data = await supabase
.from('users')
.select('name')
.containedBy('address', {'postcode': 90210});
Implementation
PostgrestFilterBuilder<T> containedBy(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, 'cd.$value');
} else if (value is List) {
// array
url = appendSearchParams(column, 'cd.{${_cleanFilterArray(value)}}');
} else {
// json
url = appendSearchParams(column, 'cd.${json.encode(value)}');
}
return copyWithUrl(url);
}