Skip to content
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

Simplify PG query constraints #35

Open
Kamirus opened this issue May 25, 2020 · 2 comments
Open

Simplify PG query constraints #35

Kamirus opened this issue May 25, 2020 · 2 comments
Labels
backend-integration Interop code between DSL and some db backend, e.g. generate SQL, execute, [de]serialize results error message Refers to compilation errors (unclear, misleading, ...) pg Related with the PG backend

Comments

@Kamirus
Copy link
Owner

Kamirus commented May 25, 2020

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 Kamirus added enhancement pg Related with the PG backend labels May 25, 2020
@Kamirus
Copy link
Owner Author

Kamirus commented Feb 4, 2021

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

  • current PG backend uses postgresql-client which accepts typed tuples as input/output of the query
  • selda utilises records
  • integration code must translate records into typed tuples in order to execute a query and then parse the output tuple back into a record - this translation is performed on the type-level using type classes
  • example: user wants to insert/select record { name :: String, age :: Int, b :: Boolean }, but pg backend accepts tuples of type Int /\ String /\ Boolean

Solutions

  • make postgresql-client support records (might be problematic: see this forum topic)
  • 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)

@Kamirus Kamirus added the error message Refers to compilation errors (unclear, misleading, ...) label Feb 4, 2021
@paluh
Copy link
Collaborator

paluh commented Feb 5, 2021

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 :-)

@Kamirus Kamirus added backend-integration Interop code between DSL and some db backend, e.g. generate SQL, execute, [de]serialize results and removed enhancement labels Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-integration Interop code between DSL and some db backend, e.g. generate SQL, execute, [de]serialize results error message Refers to compilation errors (unclear, misleading, ...) pg Related with the PG backend
Projects
None yet
Development

No branches or pull requests

2 participants