morphismtech / squeal

Squeal, a deep embedding of SQL in Haskell
350 stars 32 forks source link

A couple builtins we can include #259

Closed khwarizmii closed 2 years ago

khwarizmii commented 4 years ago

From working with this library, here are some additions:

jsonbArrayElementsText :: null 'PGjsonb -|-> ("jsonb_array_elements_text" ::: '["value" ::: 'NotNull 'PGtext])
jsonbArrayElementsText = unsafeSetFunction "jsonb_array_elements_text"

replace :: '[ null 'PGtext, null 'PGtext, null 'PGtext ] ---> null 'PGtext
replace = unsafeFunctionN "replace"

(hopefully we can see a PR soon!)

khwarizmii commented 4 years ago

Here's another one:

dateTruncTimestamp :: '[ null 'PGtext, null 'PGtimestamp ] ---> null 'PGtimestamp
dateTruncTimestamp = unsafeFunctionN "date_trunc"

Credit for these goes to @simfleischman !

So while I know the official postgres docs gives the above as the signature for date_trunc, the text argument can only take on certain values, specified in § 9.9.2 of the postgres docs:

Perhaps we want a simple sum type for the allowed values?

echatav commented 4 years ago

@khwarizmii You mean like TimeUnit?

echatav commented 3 years ago

Being addressed in #284