selectJsonColumns function
Given a list of columns, return an expression extracting the columns from a list of JSON-encoded objects.
This call:
selectJsonColumns(['name', 'email'])('?')
Produces the equivalent of:
"SELECT json_each.value ->> 'name' as name, json_each.value ->> 'email' as email FROM json_each(?)"
Implementation
PlaceholderQueryFragment selectJsonColumns(List<String> columns) {
String extract = columns.map((e) {
return "json_extract(json_each.value, ${quoteJsonPath(e)}) as ${quoteIdentifier(e)}";
}).join(', ');
return PlaceholderQueryFragment._("SELECT $extract FROM json_each(", ")");
}