Skip to content

.values() Only Affects First Row in Multi-row Insert — Bug or Intended? #138

Description

@RosendoStyer

Dear maintainers,

Thank you for creating and maintaining sql-bricks — it's a concise and flexible SQL builder that we’ve enjoyed using in our project.

We’ve encountered what appears to be a bug when using .values() to append fields after an initial multi-row insert. Specifically, the appended field is only applied to the first row, while subsequent rows receive null for that field.

Reproduction Example

const sql = SqlBricks
  .insert('test', [{ type: 'cat' }, { type: 'dog' }])
  .values({ create_time: 3 })
  .toString();

Result:

INSERT INTO test (type, create_time) VALUES ('cat', 3), ('dog', null)

Expected:

INSERT INTO test (type, create_time) VALUES ('cat', 3), ('dog', 3)

In our use case, this causes inconsistent data and runtime errors. Based on the chaining design of sql-bricks, it would be reasonable to expect .values() to apply to all rows uniformly.

Questions

  1. Is this behavior considered a bug or working as designed?
  2. If it’s a bug, is there a recommended workaround or fix?
  3. Are there any plans to publish a new release that addresses this issue?

We’d be happy to contribute or assist in debugging this further if needed. Thank you again for the great tool!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions