How to select a dynamic list of fields generated on the fly?

18 views
Skip to first unread message

john dimm

unread,
Jul 15, 2019, 10:42:06 PM7/15/19
to lovefield-users
The SELECT query builder takes a variable number of arguments, 

  db.select(a1, a2, a3)...

But I don't know how many fields will be requested.  The schema is determined at runtime.

Is there a way to pass an array or comma-separated list of fields to db.select?

Demetrios Papadopoulos

unread,
Jul 16, 2019, 1:28:54 PM7/16/19
to lovefield-users
IIUC your question, this can be done with simple JS features, and does not need any special feature from Lovefield.

Using ES6 spread operator "...":
let myDynamicFieldList = calculateList(); // Returns an array of Lovefield columns at runtime.
db
.select(...myDynamicFieldList).from(myTable).exec();


let myDynamicFieldList = calculateList(); // Returns an array of Lovefield columns.
db
.select.apply(db, myDynamicFieldList).from(myTable).exec();

Hope this helps,
Thanks
Reply all
Reply to author
Forward
0 new messages