mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-03-24 10:19:10 +00:00
32 lines
826 B
C#
32 lines
826 B
C#
|
using Dapper;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data.Common;
|
|||
|
|
|||
|
namespace FSO.Server.Database.DA.Utils
|
|||
|
{
|
|||
|
public static class BufferedInsert
|
|||
|
{
|
|||
|
public static void ExecuteBufferedInsert(this DbConnection connection, string query, IEnumerable<object> param, int batches)
|
|||
|
{
|
|||
|
var buffer = new List<object>();
|
|||
|
var enumerator = param.GetEnumerator();
|
|||
|
|
|||
|
while (enumerator.MoveNext())
|
|||
|
{
|
|||
|
buffer.Add(enumerator.Current);
|
|||
|
|
|||
|
if(buffer.Count >= batches)
|
|||
|
{
|
|||
|
connection.Execute(query, buffer);
|
|||
|
buffer.Clear();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if(buffer.Count > 0)
|
|||
|
{
|
|||
|
connection.Execute(query, buffer);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|