khibino / haskell-relational-record

This repository includes a joined query generator based on typefull relational algebra, and mapping tools between SQL values list and Haskell record type.
233 stars 36 forks source link

(WIP) (RFC) Safer placeholders #70

Closed igrep closed 5 years ago

igrep commented 5 years ago

Better solution for https://github.com/khibino/haskell-relational-record/pull/67.

Problem

Users must refer placeholders by exactly same order as the record fields are defined, and must refer every field exactly once. Otherwise, the parameter values are bind at unintentional placeholders when executing the SQL.

Solution

  1. To Relation and Record, add fields for lists containing indices of every record field.
    • Called placeholderOffsets in Record.
    • The indices for the record fiels are obtained from Pi object generated by makeRelationalRecord.
  2. Concatenate the placeholderOffsets of Records by any operators for Records.
  3. Accumulate the placeholderOffsets of Records by the new monad transformer: ReferredPlaceholders.
  4. Sort parameters by placeholderOffsets before binding to the placeholders of the SQL.

Left problems

igrep commented 5 years ago

Current implementation can't properly handle the cases that the order of the placeholders referred in the monad stack differs from the order of the placeholders referred in the composed SQL.

Decided by oral discussion with @khibino:

igrep commented 5 years ago

I'm not sure how to handle the cases that the parameter types are composed by using the placeholder function several times.

Decided by oral discussion with @khibino:

igrep commented 5 years ago

New task:

I'm going to rewrite this patch to send a separate pull request again! 😰