public static void BulkWriteToDatabase <TEntity>(IPostgreSQLCopyHelper <TEntity> bulkPostgreSqlCopyHelper, IEnumerable <TEntity> entities)
 {
     using (NpgsqlConnection dbConnection = new NpgsqlConnection(PostgreSqlConnectionString))
     {
         dbConnection.Open();
         bulkPostgreSqlCopyHelper.SaveAll(dbConnection, entities);
     }
 }
Beispiel #2
0
        private async Task InsertItemsAsync <T>(IEnumerable <T> items, IPostgreSQLCopyHelper <T> copyHelper)
        {
            using (var connection = new NpgsqlConnection(_connectionString))
            {
                await connection.OpenAsync();

                copyHelper.SaveAll(connection, items);
            }
        }
Beispiel #3
0
        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;
 }