Вопрос

I'd like to get the row data given to me by sqlJocky in my Dart Server application and convert it (with column names) to a Map. Ie. row['email'] == "somename".

The row data is a "_BinaryDataPacket" which is an extension of Row type. Right now the method recommended by the sqlJocky developer to access the data involves either knowing the column name of what your accessing in the database:

row.email == "somename"

or just ignoring the column name all together:

row[0] == "somename"

I've tried a few hacks to get at the column data and even edited the original sqlJockey code to get at _BinaryDataPacket._fieldIndex to made it public. While that did give me access to Symbol instances of the Column titles to build a map with, I would like to avoid modifying the developers stable code if at all possible. I assume there has to be an easy way to get the column names and put them in a Map with the row data.

TLDR: I want to Convert alpha.brava == "charle" into alpha["bravo"] == "charle".

Thanks

Это было полезно?

Решение

In your results, you have a fields list attribute.

So you could do this :

.then((Results results) {
    results.forEach((Row row) {
        Map r = new Map();
        for(int i=0; i<results.fields.length; i++) {
            r[results.fields[i].name] = row[i];
        }
    });
});

This will map the data from a row to the map

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top