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

createMany operation #1550

Merged
merged 21 commits into from
Jan 28, 2021
Merged

createMany operation #1550

merged 21 commits into from
Jan 28, 2021

Conversation

dpetrick
Copy link
Contributor

@dpetrick dpetrick commented Jan 25, 2021

Related issue: prisma/prisma#4998
Adds createMany top level and nested operations for creating many records at once. Returns the number of inserted rows.

Supported databases:

  • SQL Server
  • MySql
  • Postgres

Input type for the operation is compatible with unchecked scalar inputs:

  • All scalar fields are writable including foreign keys. Notable exceptions:
    • Autoincrement scalar fields are excluded on SQL Server.
    • Foreign key scalars are excluded when writing nested records (the foreign key scalar is implicitly set by the nested createMany).
  • No relation field support.

Other constraints:

  • Nested createMany is only available on 1:m relations where the many side is on the child.
  • skipDuplicates is available for Postgres and MySQL to ignore unique key violations on bulk insert, but is unavailable on SQL server.

Examples:

mutation {
  createManyTest(skipDuplicates: true, data: [
    { id: 1, a: "a1", b: null },
    { id: 2, a: "a2", b: "b2" },
    { id: 1, a: "a", b: null } # skipped
  ]) {
    count
  }
}
mutation {
  createOneTest(data: {
    id: 1
    related: {
      createMany: {
        skipDuplicates: true,
        data: [{ id: 1 }, { id: 2 }]
      }
    }
  }) {
    related {
       id
    }
  }
}

@pimeys
Copy link
Contributor

pimeys commented Jan 26, 2021 via email

@dpetrick dpetrick added this to the 2.16.0 milestone Jan 28, 2021
@dpetrick dpetrick merged commit 010a061 into master Jan 28, 2021
@dpetrick dpetrick deleted the query-engine/createMany branch January 28, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants