feat: sqlx sqlite expose de/serialize#3745
Conversation
- pass non-owned byte slice to deserialize - `SqliteBufError` and better error handling - more impl for `SqliteOnwedBuf` so it can be used as a slice - default serialize for `SqliteConnection`
d46771b to
ee4d3fc
Compare
|
I've implemented the It would be cool to have a single |
|
Update: I've moved I had to introduce two new
plus, I've implemented I've also removed the |
This implements `Command::Serialize` and `Command::Deserialize` and moves the serialize and deserialize logic to the worker thread. `Serialize` will need some more iterations as it's not clear whether it would need to wait for other write transactions before running.
f7f5d7c to
782952a
Compare
- Merged deserialize module with serialize module - Moved `SqliteOwnedBuf` into serialize module - Fixed rustdocs
|
@mattrighetti on further review, there were a lot of things I wanted to change and it would have been unwieldy to do it all in review comments. I took the liberty of pushing a commit with the changes:
Take a look and let me know what you think. |
|
lgtm! Not 100% convinced about the In the future we could introduce a new function |
This PR exposes two new functions for sqlite (#192):
serializedeserializeI've tried to follow what @abonander suggested #192 (comment)
Related docs
Serialize
serialize_nocopyusessqlite3_serializewith the flagSQLITE_SERIALIZE_NOCOPYenabled so no new buffer is allocated. It is implemented onLockedHandleso that we're sure the buffer does not outlive the handle lifetime as noted in the sqlite docs:I've then implemented the
serializefunction onSqliteConnectionthat basically locks the handle and copies the buffer returned byserialize_nocopyinto an owned typeVec<u8>that will be returned to the caller.Deserialize
deserializerequires a bit more work. First of all I've created a wrapper typeSqliteOwnedBuffor a buffer allocated withsqlite3_malloc. That buffer is useful insqlite3_deserializesince it enables us to use theSQLITE_DESERIALISE_FREEONCLOSEflag that will notifysqlite3_deserializeto manage the buffer and free the allocation when it's done with it.Notes
This still needs testing, but I wanted to first understand if there are other changes needed for this implementation.
Also, I really doubt that the
ErrI've implemented are correct, I'd need some guidance on how we should handle those failuresLooking forward to your feedback, thanks!