-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPostgreSqlDialectBuilder.cs
More file actions
37 lines (32 loc) · 1.25 KB
/
PostgreSqlDialectBuilder.cs
File metadata and controls
37 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.Text;
using PhenX.EntityFrameworkCore.BulkInsert.Dialect;
using PhenX.EntityFrameworkCore.BulkInsert.Metadata;
using PhenX.EntityFrameworkCore.BulkInsert.Options;
namespace PhenX.EntityFrameworkCore.BulkInsert.PostgreSql;
internal class PostgreSqlDialectBuilder : SqlDialectBuilder
{
protected override string OpenDelimiter => "\"";
protected override string CloseDelimiter => "\"";
public override string CreateTableCopySql(string tempNameName, TableMetadata tableInfo, IReadOnlyList<ColumnMetadata> columns)
{
return $"CREATE TEMPORARY TABLE {tempNameName} AS TABLE {tableInfo.QuotedTableName} WITH NO DATA;";
}
protected override void AppendConflictMatch<T>(StringBuilder sql, TableMetadata target, OnConflictOptions<T> conflict)
{
if (conflict.Match != null)
{
base.AppendConflictMatch(sql, target, conflict);
}
else if (target.PrimaryKey.Length > 0)
{
sql.Append(' ');
sql.AppendLine("(");
sql.AppendColumns(target.PrimaryKey);
sql.AppendLine(")");
}
else
{
throw new InvalidOperationException("Table has no primary key that can be used for conflict detection.");
}
}
}