bitemyapp / esqueleto

New home of Esqueleto, please file issues so we can get things caught up!
BSD 3-Clause "New" or "Revised" License
370 stars 107 forks source link

Interval support #263

Open parsonsmatt opened 3 years ago

parsonsmatt commented 3 years ago

We should support postgres interval notation.

belevy commented 3 years ago

What does this look like? Would this be captured by a phantom type Interval?

parsonsmatt commented 3 years ago

persistent-postgresql has PgInterval type, so I think we'd just want some functions for building them from various numeric types. LIke interval_ :: IntervalType -> SqlExpr (Value Int) -> SqlExpr (Value PgInterval), so you can write interval_ Days (val 3) or whatever

belevy commented 3 years ago

How does one handle the "1 day" case if the number is a SqlExpr?

codygman commented 2 years ago

I had a need for this today in:

generate_series(date_trunc('week', current_date - interval '13 weeks'), date_trunc('week', current_date - interval '1 week'), interval '1 week') {{weekly}} ) d
belevy commented 2 years ago

responding to my earlier question we would always use the singular form and then multiply so interval_ Days (val 3) would become ("? * interval '1 day'", [PersistInt64 3])