selectJsonColumnMap function
Similar to selectJsonColumns, but allows specifying different output columns. This is useful for using on a List of Lists, instead of a List of Objects.
Example:
selectJsonColumnMap({0: 'name', 1: 'email'})('?')
Implementation
PlaceholderQueryFragment selectJsonColumnMap(Map<Object, String>? columnMap) {
String extract;
if (columnMap != null) {
extract = columnMap.entries.map((e) {
final key = e.key;
if (key is int) {
return "json_extract(json_each.value, ${quoteJsonIndex(key)}) as ${quoteIdentifier(e.value)}";
} else if (key is String) {
return "json_extract(json_each.value, ${quoteJsonPath(key)}) as ${quoteIdentifier(e.value)}";
} else {
throw ArgumentError('Key must be an int or String');
}
}).join(', ');
} else {
extract = "json_each.value as value";
}
return PlaceholderQueryFragment._("SELECT $extract FROM json_each(", ")");
}