Skip to content

How to implement ToSql for a new type in Sqlite? #4258

Answered by weiznich
LennDG asked this question in Q&A
Discussion options

You must be logged in to vote

From the docs it seems that another way to get this to work would be

That's the correct way to go in this case

but that seems strange when I am pretty sure the ToSql<Text, Sqlite> should exist for String.

It exists bit it requires that &self (== the string you pass in) outlives the output passed into the function as second argument. That's not the case for your value v as it only is valid for the scope of the current function, so shorter than Output. The main reason for this behavior is that we don't want to clone strings provided from a higher level at at all, we just hand out a pointer to sqlite at some point, but for this we must ensure that the string is not dropped until then (wh…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by LennDG
Comment options

You must be logged in to vote
1 reply
@weiznich
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants