Skip to content

Commit

Permalink
数据库实体模型bool类型创建
Browse files Browse the repository at this point in the history
  • Loading branch information
noberumotto committed Nov 12, 2023
1 parent a841d1a commit de527e5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Core/Librarys/SQLite/SQLiteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public enum DbType
INTEGER,
datetime,
nvarchar,
@int
@int,
bit
}

/// <summary>
Expand Down Expand Up @@ -309,11 +310,18 @@ private bool IsHandleDb()
private string GetCreateColumnSQL(string tableName, IModelProperties properties)
{
string typeDefault = !properties.PK ? properties.Type == DbType.@int ? "NULL DEFAULT 0" : "NULL DEFAULT ''" : "";

if(properties.Type == DbType.bit)
{
typeDefault = " DEFAULT 0";
properties.Type = DbType.INTEGER;
}

if (properties.PK)
{
properties.Type = DbType.INTEGER;
}

return $"ALTER table {tableName} ADD COLUMN [{properties.Name}] {properties.Type} {typeDefault}";
}
#endregion
Expand All @@ -332,6 +340,13 @@ private string GetCreateTableSQL(IModelInfo model, string tableName = null)
foreach (var p in model.Properties)
{
string typeDefault = p.Type == DbType.@int ? " NULL DEFAULT 0" : " NULL DEFAULT ''";

if (p.Type == DbType.bit)
{
typeDefault = " DEFAULT 0";
p.Type = DbType.INTEGER;
}

if (p.PK)
{
typeDefault = "";
Expand Down

0 comments on commit de527e5

Please sign in to comment.