Convert "Instance of QueryRow" to a List or Map

1.5k views Asked by At

I have an asset database holding reference data. I'm trying to create another table (in this case list of maps) based on this table like;

var data = db.execute("SELECT * FROM customers");

data > [{1, George, male}, {2, Michael, male}, {3, Lucy, female} ...]

myList = data.where(..condition); >> filtered by gender

myList > [{1, George}, {2, Michael} ...]

So a new list of maps will have more key/value pairs that will be filled in runtime, like "counter" for example.

I'm not using an object in the background instead of using runtime list variables. (maybe this is the root cause of my problem, I really don't know)

So when I try to read record like myList[0] I can reach but when I try to add this particular record to another list of maps compiler returns an error:

Tried calling: add(Instance of QueryRow)

I'll be appreciated if someone help me about this. Thank you in advance.

1

There are 1 answers

0
talpaz On

I've solved in this way:

map = {};
results.forEach((key, value) => map[key] = value);

Now map is a real map and you can add new key-value pairs or you can use in other ways.