tndrle / node-sqlite3-wasm

WebAssembly port of SQLite3 for Node.js with file system access
MIT License
55 stars 8 forks source link

Add raw method to database and statement classes #68

Open mikeburgh opened 1 month ago

mikeburgh commented 1 month ago

A first pass at closing #67

I changed the way column names are resolved so they don't get resolved for each row, however for some reason the column_type method only works when in the query row method, so I had to still do a lookup for the type there, but it now only does it once.

mikeburgh commented 4 weeks ago

Giving this one a bump.. I was going to do some more for the interupt and exec commands, but wanted to see if you had any issues with this first..

tndrle commented 4 weeks ago

Hi, thanks for the PR and sorry for the late reply. I didn't have too much time recently. I hope I can look into it soon. Looks promising though, even with docs and tests already :)

mikeburgh commented 3 weeks ago

I know how that goes!

I will work on interrupt and the exec method over the next week or so and send the PRs when ready.

tndrle commented 3 weeks ago

I added PR #74 for querying rows as arrays. I prefer extending the existing methods like get() and all() with an asArray option instead of adding a new raw() method. This seems a little more consistent to me, design-wise.

Column metadata is not yet included in the PR, but it will probably be a separate method, like in better's API.

mikeburgh commented 3 weeks ago

Looks, good I will try and follow that model with exec method; not sure if it will have the column metadata available since it won’t use prepared statements

tndrle commented 3 weeks ago

About the column meta data: there is sqlite3_column_decltype() and sqlite3_column_type(). You use the latter and assume the first row's column types apply to all returned rows, correct? Better-sqlite uses the former, I think, which would have been also be my first guess. The actual type can be different from the declared type, so it depends on what you want to do with the type information. What are your thoughts on this?

mikeburgh commented 3 weeks ago

Correct, I assume first row matches the rest... and it was only through working with this, that I discovered SQLite's approach to datatypes is, well flexible and actually can change between rows for the same column.

My issues with declared type is that it will be null in the case of computed columns, so you don't get any type information at all for those.

Maybe the best solution is use declared type, and if it's null use the column_type ?

My use case is to basically hint the datatype for display purposes, editing data, but I still check individual values (it's being used in https://dbcode.io)