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

Support `diesel_manage_updated_at` on SQLite #1871

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
1 participant
@sgrif
Member

sgrif commented Oct 3, 2018

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.

Support `diesel_manage_updated_at` on SQLite
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 sgrif requested a review from diesel-rs/reviewers Oct 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment