dbhub.io icon indicating copy to clipboard operation
dbhub.io copied to clipboard

[Suggestion] Query resultset includes column info once

Open PJOttCanHome opened this issue 2 years ago • 2 comments

Why? A much-less verbose query result. Since each "cell" returned via "Query" currently includes ColumnName and ColumnType and CellValue it can become bytes-expensive for the transfer. This proposal should make it better, I hope.

New Parameter for Query Function: format=default|colheaders format=colheaders would return a JSON string like this:

{
   "columns": [{"name":"col0","type":1},{"name":"col1","type":2},{"name":"col2","type":0}]
   "data": [
       [val0,val1,val2],
       [val0,val1,val2],
       [val0,val1,val2]
    ]
}

Each "col#" object could have the info from the "Columns" query as related to the results of this query (or at least ColName,ColType) This returns a MUCH smaller resultset, as far as bytes transferred back.

I thank you for your time.

PJOttCanHome avatar Dec 18 '23 07:12 PJOttCanHome

The concept sounds pretty sensible. We'd probably also need a field to indicate which data format is being used too.

One of the err... features (heh) of SQLite is that cell data doesn't need to be what the table definition declares.

So it's totally possible (and happens) for a column to be declared as one data type... but when reading results from a query to occasionally be given back a field with a mismatching data type.

Along the lines of the Peter row here:

Name Completed
Fred true
Joe false
Nancy true
Peter 33
Henry true

Note that doesn't mean we're randomly changing data types on callers for the heck of it, the API is instead returning whatever is in the database.


Your idea makes good sense for the happy path though, where there aren't any mismatches between the column definition and any individual fields in the returned data.

justinclift avatar Dec 21 '23 02:12 justinclift

And it at least give the column name just once. Even if the column type ends up being more of a mere "suggestion" in the end.

PJOttCanHome avatar Dec 21 '23 02:12 PJOttCanHome