typelevel / typelevel/doobie

Record names not checked with column names

Open
#277 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
2.2k
Forks
379
Avg merge
14m
Merged PRs (30d)
8

Description

When mapping multi-column queries to a shapeless record, only the positions of the columns are taken into account. That is to say, the first column from the query is mapped to the first record entry, etc. This is a bit unfortunate as it's all too common to mix up the order of columns or records and if they're not the same type, then errors would be produced even though the types corresponding to the record name are correct. This is especially devious when queries select all columns via "SELECT *". Conversely, if you mix up the order and the entries are of the same type, then no error would be produced. This is hardly type-safe...

For contrast, the now abandoned sqltyped project did this the "right" way- records were constructed from the column name and type directly: https://github.com/jonifreeman/sqltyped/blob/master/core/src/main/scala/jdbc.scala

I know there are some things which can't be done at runtime (as opposed to compile-time), but on analysis (via the check method) it should be possible in doobie to check the record name with the db column name.

Is there any technical difficulty in doing this? Or is this something which is not a good design idea? After a brief look at the code, it wouldn't work using the zipped columnAlignment tuple list and it would be a bit harder to check if the number of columns is the same, but I think it would make the code safer.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the analysis check method and the columnAlignment tuple list mentioned in the issue, then compare the approach with the linked sqltyped implementation. Determine how record names, database column names, and column counts should be validated; done means the design is agreed and mismatched names cannot be silently accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.