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

Better type inference for insert #47

Open
Kamirus opened this issue Feb 7, 2021 · 0 comments
Open

Better type inference for insert #47

Kamirus opened this issue Feb 7, 2021 · 0 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, ...)

Comments

@Kamirus
Copy link
Owner

Kamirus commented Feb 7, 2021

insert (as well as insert_) has a meaningless type for a user, thus it is hard to start using it.
motivation: #40 has more background on this issue.

insert_ 
   m t r.
  GenericInsert BackendPGClass m t r 
  MonadSeldaPG m 
  Table t  Array { | r }  m Unit

Say we have the following table definition:

employees 
  Table
    ( id  Auto Int
    , name  String
    , salary  Default Int
    )
employees = Table { name: "employees" }

We should be able to apply insert_ to employees and let type inference figure out the rest.
But this is not currently the case as salary is a default column, thus we can assign two different types to insert_ employees

insertEmployees1
    m
  . MonadSeldaPG m
   Array
      { nameString   -- required
      , salaryInt    -- optional
      -- , id ∷ Int     -- illegal to insert
      }
   m Unit
insertEmployees1 = insert_ employees

insertEmployees2
    m
  . MonadSeldaPG m
   Array
      { nameString
      }
   m Unit
insertEmployees2 = insert_ employees

Potential Solution

Change (or provide an alternative) insert to allow only one type once a table is provided (type parameter t should uniquely determine r from the type of insert_).
Types of optional columns should get wrapped with Maybe.

Then definition

insertEmployees = insert_ employees

Should be inferred to

insertEmployees
    m
  . MonadSeldaPG m
   Array
      { nameString
      , salaryMaybe Int -- wrapped with additional Maybe
      }
   m Unit
@Kamirus Kamirus added enhancement error message Refers to compilation errors (unclear, misleading, ...) labels Feb 7, 2021
@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, ...)
Projects
None yet
Development

No branches or pull requests

1 participant