Skip to content

Commit

Permalink
为 PostgreSQL 增加 BuildDeleteSql 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Soar360 committed Jun 4, 2024
1 parent f2d429d commit c78f5ba
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions XCode/DataAccessLayer/Database/PostgreSQL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ public override String FormatName(String name)
return $"\"{name}\"";
}

/// <inheritdoc/>
public override String? BuildDeleteSql(String tableName, String where, Int32 batchSize)
{
if (batchSize <= 0) return base.BuildDeleteSql(tableName, where, 0);
var xWhere = string.Empty;
var xTable = this.FormatName(tableName);
if (!string.IsNullOrWhiteSpace(where)) xWhere = " Where " + where;
var sql = $"WITH to_delete AS (SELECT ctid FROM {xTable} {xWhere} LIMIT {batchSize}) ";
sql += $"DELETE FROM {xTable} where ctid in (SELECT ctid from to_delete)";
return sql;
}
#endregion 数据库特性

#region 分页
Expand Down

0 comments on commit c78f5ba

Please sign in to comment.