using SqlSugar;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using XExten.Advance.StaticFramework;

namespace HKLib.SQLHelper
{
    public class DbContext
    {
        public static SqlSugarScope Context = new SqlSugarScope(new ConnectionConfig()
        {
            ConnectionString = $"DataSource={SyncStatic.CreateFile(Path.Combine(SyncStatic.CreateDir(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DATA")), "data.db3"))}",//连接符字串
            DbType = DbType.Sqlite,//数据库类型
            IsAutoCloseConnection = true //不设成true要手动close
        }, db =>
        {
            db.Aop.OnLogExecuting = (sql, pars) =>
            {

            };
        });

        public static void InitTable()
        {
            var Tables = Assembly.GetAssembly(typeof(DbContext))
                  .GetTypes().Where(t => t.BaseType == typeof(BaseEntity)).ToArray();
            Context.CodeFirst.InitTables(Tables);
        }
    }
}
