Support `diesel_manage_updated_at` on SQLite #1871
Closed
Conversation
There's a little bit of funkiness required to make this work. The first piece is that we need to modify the function registration to provide access to the connection for our internal functions. This isn't *strictly* necessary, we could `transmute` the `&self` to be `&'static self`, since the function will never be called after `self` is dropped. That felt like it would add some unneccessary unsafety though. The second bit of funkiness is that we have to have *some* return type, so we can't just return `()`. I think I want to fix this in the future by providing a `Null` SQL type, which provides `ToSql` and `FromSql` impls only for `()`. This requires adding a variant to `SqliteType` and `MysqlType` though, so it will have to be done in 2.0. The function itself is subtly different from the PostgreSQL version, since it runs even if no values were actually changed (we can't do something like `NEW IS DISTINCT FROM OLD` here). This also cannot be run on tables without ROWIDs. I think we should probably declare this as a SQL function in code somewhere for documentation purposes, but I want to wait until our docs are building again to follow up with that.
@sgrif Needs rebase. |
weiznich
added a commit
that referenced
this pull request
Jan 14, 2019
Rebase of #1871: Support `diesel_manage_updated_at` on SQLite
Closed by #1955 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
There's a little bit of funkiness required to make this work. The first
piece is that we need to modify the function registration to provide
access to the connection for our internal functions. This isn't
strictly necessary, we could
transmute
the&self
to be&'static self
, since the function will never be called afterself
is dropped.That felt like it would add some unneccessary unsafety though.
The second bit of funkiness is that we have to have some return type,
so we can't just return
()
. I think I want to fix this in the futureby providing a
Null
SQL type, which providesToSql
andFromSql
impls only for
()
. This requires adding a variant toSqliteType
andMysqlType
though, so it will have to be done in 2.0.The function itself is subtly different from the PostgreSQL version,
since it runs even if no values were actually changed (we can't do
something like
NEW IS DISTINCT FROM OLD
here). This also cannot be runon tables without ROWIDs. I think we should probably declare this as a
SQL function in code somewhere for documentation purposes, but I want to
wait until our docs are building again to follow up with that.