public static void BulkWriteToDatabase <TEntity>(IPostgreSQLCopyHelper <TEntity> bulkPostgreSqlCopyHelper, IEnumerable <TEntity> entities) { using (NpgsqlConnection dbConnection = new NpgsqlConnection(PostgreSqlConnectionString)) { dbConnection.Open(); bulkPostgreSqlCopyHelper.SaveAll(dbConnection, entities); } }
private async Task InsertItemsAsync <T>(IEnumerable <T> items, IPostgreSQLCopyHelper <T> copyHelper) { using (var connection = new NpgsqlConnection(_connectionString)) { await connection.OpenAsync(); copyHelper.SaveAll(connection, items); } }
private async Task ImportFileAsync <T>(string filePath, IPostgreSQLCopyHelper <T> copyHelper, Action <CsvReader> configureReader = null) { using (var textReader = File.OpenText(filePath)) { using (var csvReader = new CsvReader(textReader)) { csvReader.Configuration.CultureInfo = CultureInfo.InvariantCulture; configureReader?.Invoke(csvReader); var items = csvReader.GetRecords <T>(); await InsertItemsAsync(items, copyHelper); } } }
public LocalWeatherDataBatchProcessor(string connectionString, IPostgreSQLCopyHelper <LocalWeatherData> processor) { this.processor = processor; this.connectionString = connectionString; }