Kamirus / purescript-selda

A type-safe, high-level SQL library for PureScript
MIT License
90 stars 3 forks source link

Simplify PG query constraints #35

Open Kamirus opened 4 years ago

Kamirus commented 4 years ago

Change the internal FFI query function in pg-client to return an object instead of an array. It would allow simpler parsing the output into the result record (e.g. use ReadForeign or codecs)

Kamirus commented 3 years ago

Let's elaborate what needs to be done.

Motivation

selda uses heavy generic programming on type classes and it proves difficult for the user when something does not type check - error messages might not be helpful (as a workaround it is advised to break down a problematic query into smaller top-level declarations so that type checker might have a better chance for providing a helpful error message)

Improvement

Executing a query for PG backend is complicated for now

Solutions

paluh commented 3 years ago

make postgresql-client support records (might be problematic: see this forum topic)

We can be nearly sure that this won't apply to other backends but real research is needed. Additionally I'm not sure if we want to rely on the js query parsing layer at the end. Given these two issues I think that we shouldn't take this path.

implement the conversion mentioned above on the value-level and use more primitive API that postgresql-client exposes (e.g. use Array Foreign instead of tuples of types like Int /\ String /\ Boolean)

If this transition from nested tuples to untyped arrays is going to simplify selda db interaction then I'm all for it. I'm just not sure if it won't cause some code duplication because you still have to parse ordered tuples but from untyped form like we do in the postgersql-client. We won't probably know if we don't try :-)