Dzoukr / Dapper.FSharp

Lightweight F# extension for StackOverflow Dapper with support for MSSQL, MySQL, PostgreSQL, and SQLite
MIT License
365 stars 35 forks source link

Batch insert support #98

Closed 64J0 closed 8 months ago

64J0 commented 9 months ago

Description:

Is there any support for batch insert?

I was thinking about passing a sequence of the items to be added to the database instead of a single item.

For instance, I'm looking for a way to replicate this -> https://github.com/andr3marra/rinha-de-backend-2023-q3-csharp/blob/main/src/InsercaoRegistrosPessoas.cs#L54

Dzoukr commented 8 months ago

Hi @64J0, you can insert more at the same time, but not in a batch manner. But I am open to discussing addition / PR.

64J0 commented 8 months ago

The syntax I have in mind:

let listOfPerson : Person list = [personA; personB; personC]

insert {
   into personTable
   value listOfPerson
}

Where we pass a list of person instead of a single element.

Dzoukr commented 8 months ago

You mean... something like this?

https://github.com/Dzoukr/Dapper.FSharp/blob/34fb244d6088c26a36ad7da6d5f4bd28bfa8d323/tests/Dapper.FSharp.Tests/MSSQL/InsertTests.fs#L106C1-L122C10

64J0 commented 8 months ago

You mean... something like this?

Yes, that is it. I think this is enough to cover my use case. Thanks for sharing it @Dzoukr.

Just to clarify, why you don't consider this approach to be a batch insertion?

Dzoukr commented 8 months ago

Because I am not sure, how it would scale for hundreds of thousands of rows. AFAIK you cannot have more than 1000 rows in a single query it may require splitting before running. But for relatively reasonable numbers it's good enough.

64J0 commented 8 months ago

Got it. Thanks for the detailed replies. I'm going to close this issue now.