예제 #1
0
        public SqlExpBase(SqlAdapterType adater, SqlTableDefine tableDefine, List <SqlColumnDefine> columnDefines)
        {
            _type    = SqlType.Query;
            _adapter = adater;

            _builder  = new Builder.Builder(_type, tableDefine, columnDefines, AdapterFactory.GetAdapterInstance(_adapter));
            _resolver = new LambdaResolver(_builder);
        }
        public static void CreateTable(this IDbConnection db, SqlTableDefine tableDefine, List <SqlColumnDefine> columnList, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var createTableSql = dbAdapter.CreateTableSql(tableDefine, columnList);

            db.Execute(createTableSql, transaction: transaction);
        }
        public static void TruncateTable(this IDbConnection db, string tableName, string tableSchema, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var sql = dbAdapter.TruncateTableSql(tableName, tableSchema);

            db.Execute(sql, transaction: transaction);
        }
예제 #4
0
 public SqlExpBase(SqlAdapterType adater, Type entityType)
 {
     _type       = SqlType.Query;
     _adapter    = adater;
     _entityType = entityType;
     _builder    = new Builder.Builder(_type, entityType, AdapterFactory.GetAdapterInstance(_adapter));
     _resolver   = new LambdaResolver(_builder);
 }
        public static bool TableExist(this IDbConnection db, string tableName, string tableSchema = null, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var tableExistSql = dbAdapter.TableExistSql(tableName, tableSchema);

            return(db.ExecuteScalar <int>(tableExistSql, transaction: transaction) > 0);
        }
예제 #6
0
        public static Task CreateTableAsync(this IDbConnection db, SqlTableDefine tableDefine,
                                            List <SqlColumnDefine> columnList, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var createTableSql = dbAdapter.CreateTableSql(tableDefine, columnList);

            return(db.ExecuteSqlAsync(transaction, createTableSql));
        }
예제 #7
0
        public static Task <int> TruncateTableAsync(this IDbConnection db, string tableName, string tableSchema,
                                                    IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var sql = dbAdapter.TruncateTableSql(tableName, tableSchema);

            return(db.ExecuteAsync(sql, transaction: transaction));
        }
예제 #8
0
 public SqlExpBase(SqlAdapterType adater, Type entityType, string specialSchema)
 {
     _type       = SqlType.Query;
     _adapter    = adater;
     _entityType = entityType;
     SqlAdapter  = AdapterFactory.GetAdapterInstance(_adapter);
     _builder    = new Builder.Builder(_type, entityType, SqlAdapter, specialSchema);
     //_builder = new Builder.Builder(_type, entityType, AdapterFactory.GetAdapterInstance(_adapter));
     _resolver = new LambdaResolver(_builder);
 }
        /// <summary>
        /// 根据实体类创建数据库表
        /// </summary>
        /// <typeparam name="T">实体类类型</typeparam>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        public static void CreateTable <T>(this IDbConnection db, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var entityDef = EntityHelper.GetEntityDefine <T>();

            var createTableSql = dbAdapter.CreateTableSql(entityDef.Item1, entityDef.Item2);

            db.Execute(createTableSql, transaction: transaction);
        }
예제 #10
0
        public static async Task <bool> TableExistAsync(this IDbConnection db, string tableName, string tableSchema = null,
                                                        IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var tableExistSql = dbAdapter.TableExistSql(tableName, tableSchema);

            var result = await db.ExecuteScalarAsync <int>(tableExistSql, transaction : transaction);

            return(result > 0);
        }
예제 #11
0
        public static Task CreateTableAsync <T>(this IDbConnection db, IDbTransaction transaction = null)
        {
            //return Task.Run(() => { db.CreateTable<T>(transaction); });
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var entityDef = EntityHelper.GetEntityDefine <T>();

            var createTableSql = dbAdapter.CreateTableSql(entityDef.Item1, entityDef.Item2);

            return(db.ExecuteSqlAsync(transaction, createTableSql));
        }
예제 #12
0
        public static void CreateSchemaIfNotExists(this IDbConnection db, string tableSchema, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var sql = dbAdapter.CreateSchemaIfNotExistsSql(tableSchema);

            if (string.IsNullOrEmpty(sql))
            {
                return;
            }
            db.Execute(sql, transaction: transaction);
        }
예제 #13
0
        public static bool SchemaExist(this IDbConnection db, string tableSchema, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var schemaExistSql = dbAdapter.SchemaExistsSql(tableSchema);

            if (string.IsNullOrEmpty(schemaExistSql))
            {
                return(true);
            }

            return(db.ExecuteScalar <int>(schemaExistSql, transaction: transaction) > 0);
        }
예제 #14
0
        /// <summary>
        /// 根据实体类创建数据库表
        /// </summary>
        /// <typeparam name="T">实体类类型</typeparam>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        public static void CreateTableIfNotExist <T>(this IDbConnection db, IDbTransaction transaction = null)
        {
            if (!db.TableExist <T>(transaction))
            {
                var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

                var entityDef = EntityHelper.GetEntityDefine <T>();

                var createTableSql = dbAdapter.CreateTableSql(entityDef.Item1, entityDef.Item2);

                ExecuteSql(db, transaction, createTableSql);
            }
        }
예제 #15
0
        public static Task CreateTableIfNotExistAsync <T>(this IDbConnection db, IDbTransaction transaction = null)
        {
            return(db.TableExistAsync <T>(transaction).ContinueWith((async task =>
            {
                if (!task.Result)
                {
                    var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

                    var entityDef = EntityHelper.GetEntityDefine <T>();

                    var createTableSql = dbAdapter.CreateTableSql(entityDef.Item1, entityDef.Item2);

                    await db.ExecuteSqlAsync(transaction, createTableSql);
                }
            })));
        }
예제 #16
0
        public static Task CreateTableIfNotExistAsync(this IDbConnection db, SqlTableDefine tableDefine,
                                                      List <SqlColumnDefine> columnList, IDbTransaction transaction = null)
        {
            return(db.TableExistAsync(tableDefine, transaction).ContinueWith((async task =>
            {
                if (!task.Result)
                {
                    var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());


                    var createTableSql = dbAdapter.CreateTableSql(tableDefine, columnList);

                    await db.ExecuteSqlAsync(transaction, createTableSql);
                }
            })));
        }
예제 #17
0
        /// <summary>
        /// 根据实体类创建数据库表
        /// </summary>
        /// <typeparam name="T">实体类类型</typeparam>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        public static void CreateTable <T>(this IDbConnection db, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var entityDef = EntityHelper.GetEntityDefine <T>();

            var createTableSql = dbAdapter.CreateTableSql(entityDef.Item1, entityDef.Item2);

            DapperLambdaExt.DebuggingSqlString(createTableSql);

            if (transaction == null)
            {
                var trans = db.BeginTransaction();
                try
                {
                    db.Execute(createTableSql, transaction: trans);

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();

                    DapperLambdaExt.DebuggingException(ex, createTableSql);
                    throw new DapperLamException(ex.Message, ex, createTableSql);
                }
            }
            else
            {
                try
                {
                    db.Execute(createTableSql, transaction: transaction);
                }
                catch (Exception ex)
                {
                    DapperLambdaExt.DebuggingException(ex, createTableSql);
                    throw new DapperLamException(ex.Message, ex, createTableSql);
                }
            }
        }
예제 #18
0
        public static void CreateTable(this IDbConnection db, SqlTableDefine tableDefine, List <SqlColumnDefine> columnList, IDbTransaction transaction = null)
        {
            var dbAdapter = AdapterFactory.GetAdapterInstance(db.GetAdapter());

            var createTableSql = dbAdapter.CreateTableSql(tableDefine, columnList);

            DapperLambdaExt.DebuggingSqlString(createTableSql);

            if (transaction == null)
            {
                var trans = db.BeginTransaction();
                try
                {
                    db.Execute(createTableSql, transaction: trans);

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();

                    DapperLambdaExt.DebuggingException(ex, createTableSql);
                    throw new DapperLamException(ex.Message, ex, createTableSql);
                }
            }
            else
            {
                try
                {
                    db.Execute(createTableSql, transaction: transaction);
                }
                catch (Exception ex)
                {
                    DapperLambdaExt.DebuggingException(ex, createTableSql);
                    throw new DapperLamException(ex.Message, ex, createTableSql);
                }
            }
        }
예제 #19
0
 public void SetAdapter(SqlAdapterType adapter)
 {
     _builder.Adapter = AdapterFactory.GetAdapterInstance(adapter);
 }