-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: sqlx sqlite expose de/serialize #3745
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):
serialize
deserialize
I've tried to follow what @abonander suggested #192 (comment)
Related docs
Serialize
serialize_nocopy
usessqlite3_serialize
with the flagSQLITE_SERIALIZE_NOCOPY
enabled so no new buffer is allocated. It is implemented onLockedHandle
so that we're sure the buffer does not outlive the handle lifetime as noted in the sqlite docs:I've then implemented the
serialize
function onSqliteConnection
that basically locks the handle and copies the buffer returned byserialize_nocopy
into an owned typeVec<u8>
that will be returned to the caller.Deserialize
deserialize
requires a bit more work. First of all I've created a wrapper typeSqliteOwnedBuf
for a buffer allocated withsqlite3_malloc
. That buffer is useful insqlite3_deserialize
since it enables us to use theSQLITE_DESERIALISE_FREEONCLOSE
flag that will notifysqlite3_deserialize
to 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
Err
I've implemented are correct, I'd need some guidance on how we should handle those failuresLooking forward to your feedback, thanks!