Update demo

This commit is contained in:
sunkaixuan 2024-06-30 21:37:32 +08:00
parent 2c8bc264b3
commit e68cad4a98
2 changed files with 120 additions and 4 deletions

View File

@ -0,0 +1,94 @@
 using SqlSugar;
namespace DorisTest
{
/// <summary>
/// 日志记录表
///</summary>
[SugarTable("LogEntity111")]
public class LogEntity
{
/// <summary>
/// 主键
///</summary>
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 地址
/// </summary>
[SugarColumn(IsNullable = true)]
public string? Url { get; set; }
/// <summary>
/// 方法
/// </summary>
[SugarColumn(IsNullable = true)]
public string? Method { get; set; }
/// <summary>
/// 数据-请求体
/// </summary>
[SugarColumn(IsNullable = true)]
public string? Data { get; set; }
/// <summary>
/// 数据-返回(包括异常信息)
/// </summary>
[SugarColumn(IsNullable = true)]
public string? RsData { get; set; }
/// <summary>
/// 是否成功
/// </summary>
[SugarColumn(IsNullable = true)]
public bool? IsSuccess { get; set; }
/// <summary>
/// Header
/// </summary>
[SugarColumn(IsNullable = true, IsJson = true )]
public Dictionary<string, string> Header { get; set; }
/// <summary>
/// Token
/// </summary>
[SugarColumn(IsNullable = true)]
public string? Token { get; set; }
/// <summary>
/// 客户端ip
/// </summary>
[SugarColumn(IsNullable = true)]
public string ClientHost { get; set; }
/// <summary>
/// 应用标识
/// </summary>
[SugarColumn(IsNullable = true)]
public string? AppId { get; set; }
/// <summary>
/// 应用的Ip
/// </summary>
[SugarColumn(IsNullable = true)]
public string? AppHost { get; set; }
/// <summary>
/// 持续时长
/// </summary>
[SugarColumn(IsNullable = true)]
public int? RunTime { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime /*long*/ CreateTime { get; set; }
public LogEntity()
{
CreateTime = DateTime.Now;
//CreateTime = DateTime.Now.ToFileTimeUtc();
}
}
}

View File

@ -1,4 +1,5 @@
using SqlSugar;
using DorisTest;
using SqlSugar;
using System;
namespace OrmTest
@ -8,8 +9,26 @@ namespace OrmTest
{
static void Main(string[] args)
{
var db = DbHelper.GetNewDb();
var db = DbHelper.GetNewDb();
var xx= db.Ado.GetDataTable(@"SELECT
0 as TableId,
TABLE_NAME as TableName,
column_name AS DbColumnName,
CASE WHEN COLUMN_TYPE NOT LIKE '(' THEN COLUMN_TYPE ELSE left(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)-1) END AS DataType,
CAST(SUBSTRING(COLUMN_TYPE,LOCATE('(',COLUMN_TYPE)+1,LOCATE(')',COLUMN_TYPE)-LOCATE('(',COLUMN_TYPE)-1) AS decimal(18,0) ) AS Length,
column_default AS `DefaultValue`,
column_comment AS `ColumnDescription`,
CASE WHEN COLUMN_KEY = 'PRI'
THEN true ELSE false END AS `IsPrimaryKey`,
CASE WHEN EXTRA='auto_increment' THEN true ELSE false END as IsIdentity,
CASE WHEN is_nullable = 'YES'
THEN true ELSE false END AS `IsNullable`,
numeric_scale as Scale,
numeric_scale as DecimalDigits,
LOCATE( 'unsigned',COLUMN_type ) >0 as IsUnsigned
FROM
Information_schema.columns where TABLE_NAME='LogEntity1' and TABLE_SCHEMA=(select database()) ORDER BY ordinal_position");
db.CodeFirst.InitTables<LogEntity>();
db.CodeFirst.InitTables<Student11>();
db.Insertable(new Student11() { Id = 1, Age = 1, Name = "a" })
@ -37,7 +56,7 @@ namespace OrmTest
/// Database connection string
/// 数据库连接字符串
/// </summary>
public readonly static string Connection = "data source=139.170.74.9;port=9030;database=test;user id=root;password=1q!1q!;pooling=true;charset=utf8;Pooling=false";
public readonly static string Connection = "server=39.170.74.9;port=9030;Database=test;Uid=root;Pwd=1q!1q!;Pooling=false;";
/// <summary>
/// Get a new SqlSugarClient instance with specific configurations
@ -61,6 +80,9 @@ namespace OrmTest
{
Console.WriteLine(UtilMethods.GetNativeSql(sql, para));
};
it.Aop.OnError = ex =>
{
};
});
return db;
}