aboutsummaryrefslogtreecommitdiff
path: root/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-12-05 16:36:00 +0800
committercrupest <crupest@outlook.com>2022-12-20 20:32:52 +0800
commitdb0932004e2d7462288044e4dd9c353d9b534793 (patch)
treedb58c85b14ed5939fb421f266c9374d7deb82dc9 /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs
parent875a3863cf009cf3521f5cbb06548b1de22536e2 (diff)
downloadcrupest-db0932004e2d7462288044e4dd9c353d9b534793.tar.gz
crupest-db0932004e2d7462288044e4dd9c353d9b534793.tar.bz2
crupest-db0932004e2d7462288044e4dd9c353d9b534793.zip
Develop secret api. v9
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs')
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs22
1 files changed, 21 insertions, 1 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs
index 660cd4d..38daa3f 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/TableInfo.cs
@@ -1,3 +1,4 @@
+using System.Text;
using Dapper;
using Microsoft.Data.Sqlite;
@@ -78,7 +79,21 @@ public class TableInfo
}
}
- public string GenerateCreateTableSql()
+ public string GenerateCreateIndexSql()
+ {
+ var sb = new StringBuilder();
+
+ foreach (var column in ColumnInfos)
+ {
+ if (column.IndexType == ColumnIndexType.None) continue;
+
+ sb.Append($"CREATE {(column.IndexType == ColumnIndexType.Unique ? "UNIQUE" : "")} INDEX {TableName}_{column.SqlColumnName}_index ON {TableName} ({column.SqlColumnName});\n");
+ }
+
+ return sb.ToString();
+ }
+
+ public string GenerateCreateTableSql(bool createIndex = true)
{
var tableName = TableName;
var columnSql = string.Join(",\n", ColumnInfos.Select(c => c.GenerateCreateTableColumnString()));
@@ -89,6 +104,11 @@ CREATE TABLE {tableName}(
);
";
+ if (createIndex)
+ {
+ sql += GenerateCreateIndexSql();
+ }
+
return sql;
}