mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
84 changed files with 412 additions and 255 deletions
@ -0,0 +1,29 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.EntityFrameworkCore; |
|||
using PhenX.EntityFrameworkCore.BulkInsert.Extensions; |
|||
using PhenX.EntityFrameworkCore.BulkInsert.Options; |
|||
using Squidex.Events.EntityFramework; |
|||
using Squidex.Flows.EntityFramework; |
|||
|
|||
namespace Squidex.Infrastructure; |
|||
|
|||
public sealed class BulkInserter : IDbFlowsBulkInserter, IDbEventStoreBulkInserter |
|||
{ |
|||
public Task BulkInsertAsync<T>(DbContext dbContext, IEnumerable<T> entities, |
|||
CancellationToken ct = default) where T : class |
|||
{ |
|||
return dbContext.ExecuteBulkInsertAsync(entities, cancellationToken: ct); |
|||
} |
|||
|
|||
public Task BulkUpsertAsync<T>(DbContext dbContext, IEnumerable<T> entities, |
|||
CancellationToken ct = default) where T : class |
|||
{ |
|||
return dbContext.ExecuteBulkInsertAsync(entities, o => { }, new OnConflictOptions<T> { Update = e => e }, ct); |
|||
} |
|||
} |
|||
@ -1,47 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using EFCore.BulkExtensions.SqlAdapters; |
|||
using EFCore.BulkExtensions.SqlAdapters.MySql; |
|||
using EFCore.BulkExtensions.SqlAdapters.PostgreSql; |
|||
using EFCore.BulkExtensions.SqlAdapters.SqlServer; |
|||
using Squidex.Providers.MySql.Content; |
|||
using Squidex.Providers.Postgres.Content; |
|||
using Squidex.Providers.SqlServer.Content; |
|||
|
|||
namespace Squidex.EntityFramework.TestHelpers; |
|||
|
|||
public static class BulkHelper |
|||
{ |
|||
private static readonly IDbServer MySql = new MySqlDbServer(); |
|||
private static readonly IDbServer PostgreSql = new PostgreSqlDbServer(); |
|||
private static readonly IDbServer SqlServer = new SqlServerDbServer(); |
|||
|
|||
public static void Configure() |
|||
{ |
|||
SqlAdaptersMapping.Provider = context => |
|||
{ |
|||
switch (context) |
|||
{ |
|||
case MySqlContentDbContext: |
|||
return MySql; |
|||
case PostgresContentDbContext: |
|||
return PostgreSql; |
|||
case SqlServerContentDbContext: |
|||
return SqlServer; |
|||
case TestDbContextMySql: |
|||
return MySql; |
|||
case TestDbContextPostgres: |
|||
return PostgreSql; |
|||
case TestDbContextSqlServer: |
|||
return SqlServer; |
|||
} |
|||
|
|||
throw new ArgumentException("Not supported.", nameof(context)); |
|||
}; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue