Commit ac2cd4a
committed
improvement: support the Duration form of ago, from_now, datetime_add and date_add
`Ash.Query.Function.Ago`, `FromNow`, `DateTimeAdd` and `DateAdd` each accept a
`Duration` as well as an integer/interval-name pair, and evaluate it in Elixir, but
only the interval form was rendered here. The Duration form reached
`default_dynamic_expr/6`, matched nothing, and raised `Unsupported expression`, so it
worked on data layers that evaluate expressions at runtime and failed on every
SQL-backed one.
Adds a clause per function, rendering the duration as an interval parameter. Ecto has
a native `:duration` type and Postgres accepts a `%Duration{}` directly, so no
interval-name string building is needed, and multi-unit durations work.
The datetime operand is cast, as Ecto's own `datetime_add/3` does with
`type_unless_typed`; without it Postgres resolves `? - ?::interval` as interval
arithmetic. `date_add` casts back to `::date` for the same reason Ecto's does.
`from_now/1` is uncallable until the corresponding ash change releases, so its clause
is untestable downstream until then.1 parent 4804739 commit ac2cd4a
1 file changed
Lines changed: 104 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
308 | 329 | | |
309 | 330 | | |
310 | 331 | | |
| |||
446 | 467 | | |
447 | 468 | | |
448 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
449 | 491 | | |
450 | 492 | | |
451 | 493 | | |
| |||
478 | 520 | | |
479 | 521 | | |
480 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
481 | 553 | | |
482 | 554 | | |
483 | 555 | | |
| |||
509 | 581 | | |
510 | 582 | | |
511 | 583 | | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
512 | 616 | | |
513 | 617 | | |
514 | 618 | | |
| |||
0 commit comments