-
Notifications
You must be signed in to change notification settings - Fork 1
Sort keys of objects returned by SELECT * FROM table
by creation order instead of dictionary order
#5
Comments
More context on why I need this: I was wrapping Drizzle around sqliterg and encountered a strange error where Drizzle would not map the returned values correctly. After messing around a bit, I found that for |
Hi! I agree with you that this should be corrected. The code is this: Some(row) => {
let mut map: JsonMap<String, JsonValue> = JsonMap::new();
for (i, col_name) in column_names.iter().enumerate() {
let value: Value = row.get_unwrap(i);
map.insert(col_name.to_string(), val_db2val_json(value));
}
response.push(JsonValue::Object(map));
} where I cannot give you a ETA for this, it's not a good period, but as soon as I manage I'll take a look at it. Thanks!
|
I found that the JSON specification says that (emphasis mine):
So, Not easy to circumvent that; but something similar to this PR may be a way forward Would it be helpful to present the values in a list (of lists)? And the headers in another list? |
To expand a bit more: the request may be:
with values of
|
Many thanks for your answers!
On "fixing" the current code, I was thinking about I'm only using sqliterg in a side project, so there is no rush! Please take your time! |
I wish I could use a linked hash map! Unfortunately for how the code is done, it must be used something from the serde "realm" so to speak, not just any map. 🙁 Besides, the fact that a js object is unordered opens the possibility that some additional "layer" that one may use scrambles the ordering. It is just not the right structure. I have actually no issues in adding a parameter, if it's useful, sane and has a decent preset that doesn't break anything. 😉 Just have a bit of patience. Thanks! |
Hi @proofrock. Do you think that there is any workaround for this issue? It has became a major blocker for my side project. I tried |
I put down a quick (and dirty!) implementation for ws4sqlite, in a feature branch https://github.com/proofrock/ws4sqlite/tree/feature/list-response-format There's no choice, only the "new" schema is implemented. Request: {
"transaction": [
{
"statement": "CREATE TABLE IF NOT EXISTS `folders` (`id` text PRIMARY KEY NOT NULL,`name` text NOT NULL,`position` real DEFAULT 1 NOT NULL,`updated_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL);"
},
{
"statement": "INSERT INTO `folders`(id, name, position) VALUES ('default', 'Default', 0) ON CONFLICT(id) DO NOTHING;"
},
{
"query": "SELECT * FROM folders"
}
]
} Response: {
"results": [
{
"success": true,
"rowsUpdated": 0
},
{
"success": true,
"rowsUpdated": 1
},
{
"success": true,
"resultHeaders": [
"id",
"name",
"position",
"updated_at",
"created_at"
],
"resultSet": [
[
"default",
"Default",
0,
"2024-02-11 08:01:39",
"2024-02-11 08:01:39"
]
]
}
]
} So maybe you can experiment a little bit? If you are not able to compile it, please tell me your arch and I'll get you some binaries. |
Thanks for the quick response! I have been tinkering |
Hi Thanh! Please take a look at proofrock/ws4sqlite#44 and contribute if you want! |
Hi!
Suppose I have this table:
And this data:
SELECT * FROM folders
would return:I think it should follow creation order`, which returns:
id
name
position
updated_at
created_at
It is the behavior of the behavior of
sqlite3
as well:Thanks!
The text was updated successfully, but these errors were encountered: