Repository navigation
chore: sync main into dev after re-cut 0.10.0 #160
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
Changes from all commits
1691e1a
3f18700
dca5d62
c40275c
dd252a3
42b1803
3977d7d
b0767da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| %{ | ||
| "libecto_libsql-v0.10.0-nif-2.15-aarch64-apple-darwin.so.tar.gz" => "sha256:662cfc8e7f69edb8571c8eeaae6a6cc3a0b14b8739d280fba8508131c806dec6", | ||
| "libecto_libsql-v0.10.0-nif-2.15-aarch64-unknown-linux-gnu.so.tar.gz" => "sha256:94b294de0c86380893839aa03151832d47274b3e3e92341d1b7c8cf733c16ede", | ||
| "libecto_libsql-v0.10.0-nif-2.15-aarch64-unknown-linux-musl.so.tar.gz" => "sha256:2ad43e6ac85cbfdb79ef53557a08084d99f66a6965be5a06853b39859d597439", | ||
| "libecto_libsql-v0.10.0-nif-2.15-x86_64-apple-darwin.so.tar.gz" => "sha256:6b3061e16e277f21eb048c7780e4b8855e2711a7913d849335590389e503bfa1", | ||
| "libecto_libsql-v0.10.0-nif-2.15-x86_64-unknown-linux-gnu.so.tar.gz" => "sha256:fede8407f76212130473ccc8512a9db5a7ff50652dc201c9adc05f714c4b80a2", | ||
| "libecto_libsql-v0.10.0-nif-2.15-x86_64-unknown-linux-musl.so.tar.gz" => "sha256:126cbc4a11866338044e321e72a28339ecf1fe4c26906e4a6b517054ea833091", | ||
| "libecto_libsql-v0.10.0-nif-2.15-aarch64-apple-darwin.so.tar.gz" => "sha256:3ad3e7e0a485779f7e5c9f3e71152783cbc1a6f5de52e5c5d63652c070fff8ca", | ||
| "libecto_libsql-v0.10.0-nif-2.15-aarch64-unknown-linux-gnu.so.tar.gz" => "sha256:20ff544becc770cb93070e9fba16f715db9932d0a1950dcaee71eadbdfe4c0fb", | ||
| "libecto_libsql-v0.10.0-nif-2.15-aarch64-unknown-linux-musl.so.tar.gz" => "sha256:4df2b9ef3d5450abd69f5a3965a2a17ea61b8e4d3b5fdd14e3e869d48c1035e5", | ||
| "libecto_libsql-v0.10.0-nif-2.15-x86_64-apple-darwin.so.tar.gz" => "sha256:cdbf277abe1bd62cad5f78f9067061414d1da725ae6b47ee319e72b417d59f32", | ||
| "libecto_libsql-v0.10.0-nif-2.15-x86_64-unknown-linux-gnu.so.tar.gz" => "sha256:599a2343b70ec953d7a9db46ce49de14f167ba600976355ecb5403cda7859e0b", | ||
| "libecto_libsql-v0.10.0-nif-2.15-x86_64-unknown-linux-musl.so.tar.gz" => "sha256:2def82b3b570c55518385364879fe1b29d107fd99d570b57a5e0c36170c7d597", | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1246,35 +1246,23 @@ defmodule Ecto.Adapters.LibSql.Connection do | |
| end | ||
|
|
||
| # Comparison operations | ||
| defp expr({:==, _, [left, right]}, sources, query) do | ||
| reject_unsupported_datetime_precision!(left, right, sources) | ||
| [expr(left, sources, query), " = ", expr(right, sources, query)] | ||
| end | ||
| defp expr({:==, _, [left, right]}, sources, query), | ||
| do: comparison(left, " = ", right, sources, query) | ||
|
|
||
| defp expr({:!=, _, [left, right]}, sources, query) do | ||
| reject_unsupported_datetime_precision!(left, right, sources) | ||
| [expr(left, sources, query), " != ", expr(right, sources, query)] | ||
| end | ||
| defp expr({:!=, _, [left, right]}, sources, query), | ||
| do: comparison(left, " != ", right, sources, query) | ||
|
|
||
| defp expr({:<, _, [left, right]}, sources, query) do | ||
| reject_unsupported_datetime_precision!(left, right, sources) | ||
| [expr(left, sources, query), " < ", expr(right, sources, query)] | ||
| end | ||
| defp expr({:<, _, [left, right]}, sources, query), | ||
| do: comparison(left, " < ", right, sources, query) | ||
|
|
||
| defp expr({:>, _, [left, right]}, sources, query) do | ||
| reject_unsupported_datetime_precision!(left, right, sources) | ||
| [expr(left, sources, query), " > ", expr(right, sources, query)] | ||
| end | ||
| defp expr({:>, _, [left, right]}, sources, query), | ||
| do: comparison(left, " > ", right, sources, query) | ||
|
|
||
| defp expr({:<=, _, [left, right]}, sources, query) do | ||
| reject_unsupported_datetime_precision!(left, right, sources) | ||
| [expr(left, sources, query), " <= ", expr(right, sources, query)] | ||
| end | ||
| defp expr({:<=, _, [left, right]}, sources, query), | ||
| do: comparison(left, " <= ", right, sources, query) | ||
|
|
||
| defp expr({:>=, _, [left, right]}, sources, query) do | ||
| reject_unsupported_datetime_precision!(left, right, sources) | ||
| [expr(left, sources, query), " >= ", expr(right, sources, query)] | ||
| end | ||
| defp expr({:>=, _, [left, right]}, sources, query), | ||
| do: comparison(left, " >= ", right, sources, query) | ||
|
|
||
| # Parenthesised so precedence survives nesting: `(s.count + 2) * 2` has to keep | ||
| # its grouping rather than being reassociated. | ||
|
|
@@ -1439,15 +1427,8 @@ defmodule Ecto.Adapters.LibSql.Connection do | |
| # is rendered the same way to compare correctly as text. The two formats agree to | ||
| # the second, so a value carrying sub-second precision can land on the wrong side | ||
| # of a bound when it ties the cutoff to that exact second - see issue #128. | ||
| defp expr({:datetime_add, _, [datetime, count, interval]}, sources, query) do | ||
| [ | ||
| "strftime('%Y-%m-%dT%H:%M:%SZ', ", | ||
| expr(datetime, sources, query), | ||
| ", ", | ||
| interval_modifier(count, interval, sources, query), | ||
| ?) | ||
| ] | ||
| end | ||
| defp expr({:datetime_add, _, [datetime, count, interval]}, sources, query), | ||
| do: datetime_add("%Y-%m-%dT%H:%M:%SZ", datetime, count, interval, sources, query) | ||
|
|
||
| defp expr({:date_add, _, [date, count, interval]}, sources, query) do | ||
| [ | ||
|
|
@@ -1467,6 +1448,42 @@ defmodule Ecto.Adapters.LibSql.Connection do | |
| message: "unsupported expression #{inspect(expr)}" | ||
| end | ||
|
|
||
| defp datetime_add(format, datetime, count, interval, sources, query) do | ||
| [ | ||
| "strftime('", | ||
| format, | ||
| "', ", | ||
| expr(datetime, sources, query), | ||
| ", ", | ||
| interval_modifier(count, interval, sources, query), | ||
| ?) | ||
| ] | ||
| end | ||
|
|
||
| defp comparison(left, operator, right, sources, query) do | ||
| reject_unsupported_datetime_precision!(left, right, sources) | ||
|
|
||
| [ | ||
| comparison_side(left, right, sources, query), | ||
| operator, | ||
| comparison_side(right, left, sources, query) | ||
| ] | ||
| end | ||
|
|
||
| # `datetime_encode/1` stores a naive datetime without the trailing Z, so a cutoff | ||
| # compared against one drops it too. Otherwise a value on the cutoff second sorts | ||
| # before it as text and `>=` and `==` miss the row. | ||
| defp comparison_side({:datetime_add, _, [datetime, count, interval]}, other, sources, query) do | ||
| format = | ||
| if field_type(other, sources) == :naive_datetime, | ||
| do: "%Y-%m-%dT%H:%M:%S", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve fractional cutoffs when removing If a row stores Keep non-zero fractional seconds in the cutoff. Normalise an all-zero fractional suffix so the new zero-offset equality still works.
|
||
| else: "%Y-%m-%dT%H:%M:%SZ" | ||
|
|
||
| datetime_add(format, datetime, count, interval, sources, query) | ||
| end | ||
|
|
||
| defp comparison_side(side, _other, sources, query), do: expr(side, sources, query) | ||
|
|
||
| # Builds a SQLite time modifier such as '-14 days'. The count stays an expression | ||
| # rather than being interpolated, so an interpolated `ago(^n, "day")` still binds | ||
| # as a parameter. SQLite has no week/millisecond/microsecond modifiers, so those | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve source column names to their logical fields before choosing the comparison format.
The adapter receives database column names, not logical field names. A field declared with
source:appears under that column name, andfield_type/2looks up the type by that name. If another field uses the column name as its logical name, the lookup returns that other field's type. For example,field :at, :utc_datetime, source: :at_naivecombined withfield :at_naive, :naive_datetime, source: :other_atmakese.atreceive the:naive_datetimetype. The comparison then dropsZfrom the cutoff while the stored UTC value keeps it. An equality check that matched before can miss that row.Map the column name back to its logical field before reading the schema type. Identity mappings must keep their current behaviour. A
:naive_datetimefield whose source name has no matching logical field also keeps theZformat, so the naive-format fix does not reach it. Apply the same logical-field lookup to that case.