Skip to content

Generated code for insert query isn't using pog.nullable() for nullable parameters #78

@Rentfunk

Description

@Rentfunk

Steps to reproduce:

Table:

create table books (id uuid primary key, name varchar(100));

Query:

insert into books values ($1, $2);

This is how the generated code looks like:

pub fn create_book(db, arg_1, arg_2) {
  let decoder = decode.map(decode.dynamic, fn(_) { Nil })

  "insert into books values ($1, $2);
"
  |> pog.query
  |> pog.parameter(pog.text(uuid.to_string(arg_1)))
  |> pog.parameter(pog.text(arg_2))
  |> pog.returning(decoder)
  |> pog.execute(db)
}

With the name column being nullable i would expect the parameter for arg_2 to look like this:

  |> pog.parameter(pog.nullable(pog.text, arg_2))

From looking through the code, it seems that the check if column is nullable happens only if the query returns something, which doesn't happen for insert queries. So when they are parsed we get only the types of columns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions