assoc method
Implementation
String assoc(MP attr) {
final pre = name;
return attr.entries.map((w) {
String key = '"$pre"."${w.key}"';
final attr = attributes.firstWhere((a) => a.name == w.key);
return switch (w.value) {
Iterable l => '$key IN(${l.map(
(s) => _str(s),
).join(',')})',
Map m => m.entries
.map((e) => switch (e.key) {
'gt' => '$key > ${_str(e.value)}',
'gte' => '$key >= ${_str(e.value)}',
'lt' => '$key < ${_str(e.value)}',
'lte' => '$key <= ${_str(e.value)}',
'in' => '$key IN(${e.value.map(
(s) => _str(s),
).join(',')})',
'nin' => '$key NOT IN(${e.value.map(
(s) => _str(s),
).join(',')})',
_ => '',
})
.join(' AND '),
bool b => switch (attr.format) {
'TEXT' => "$key ${b ? '!' : ''}= ''",
_ => '$key IS ${b ? 'NOT ' : ''}NULL',
},
String s when s.isNotEmpty && s[0] == '%' => '$key LIKE ${_str(s)}',
var s when s is String || s is num => '$key = ${_str(s)}',
_ => '',
};
}).join(' AND ');
}