public static ISqlProvider <T1, T2, T3> From <T1, T2, T3>(this ISqlExe sqlMapper) where T1 : class where T2 : class where T3 : class
        {
            var provider = new DefaultSqlProvider <T1, T2, T3>();

            provider.Init(sqlMapper);
            return(provider);
        }
        public static ISqlProvider <T> From <T>(this ISqlExe sqlMapper) where T : class
        {
            var provider = new DefaultSqlProvider <T>();

            provider.Init(sqlMapper);
            return(provider);
        }
        public static Task <IEnumerable <T> > QueryPageAsync <T>(this ISqlExe sqlMapper, string sql, object param, int pageIndex, int pageSize, int?timeout = null)
        {
            var provider = sqlMapper.SqlFactory.DbProvider.GetService <IPageProvider>();

            provider.Init(sqlMapper);
            return(provider.QueryPageAsync <T>(sql, param, pageIndex, pageSize, timeout));
        }
        public static IMigrateProvider Migrate(this ISqlExe sqlMapper)
        {
            var provider = sqlMapper.SqlFactory.DbProvider.GetService <IMigrateProvider>();

            provider.Init(sqlMapper);
            return(provider);
        }
Beispiel #5
0
        private void CreateTable(ISqlExe sqlMapper)
        {
            if (sqlMapper != null)
            {
                var tables = EntityUtil.GetMaps(sqlMapper.SqlFactory.DbProvider.Name).ToList();

                for (int i = 0; i < tables.Count; i++)
                {
                    var table = tables[i];
                    var sqls  = CreateSql(table, sqlMapper);
                    foreach (var item in sqls)
                    {
                        sqlMapper.Execute(item, null);
                    }
                }
            }
        }
Beispiel #6
0
        private IList <string> CreateSql(TableInfo table, ISqlExe sqlExe)
        {
            if (table == null || table.Columns == null || !table.Columns.Any())
            {
                return(new List <string>());
            }

            IList <string> result = new List <string>();
            StringBuilder  sb     = new StringBuilder();

            //表结构
            sb.AppendLine($"create table if not exists {sqlExe.SqlFactory.DbProvider.FormatQuotationForSql(table.TableName)}(");
            for (int i = 0; i < table.Columns.Count; i++)
            {
                var item = table.Columns[i];
                ResolveColumnInfo(item);
                string defaultValue = item.DefaultValue == null ? "" : (item.DefaultValue is string) ? $"'{item.DefaultValue}'" : $"{item.DefaultValue}";
                string colSql       = $"{sqlExe.SqlFactory.DbProvider.FormatQuotationForSql(item.ColumnName)} {ResolveDataType(item)} {(item.IsNotNull ? "not null" : "")}";
                if (item.IsPrimaryKey)
                {
                    colSql += " primary key";
                }

                if (item.IsUnique)
                {
                    colSql += " unique";
                }

                if (!string.IsNullOrEmpty(defaultValue))
                {
                    colSql += $" default {defaultValue}";
                }

                if (i < table.Columns.Count - 1)
                {
                    colSql += ",";
                }

                sb.AppendLine(colSql);
            }
            sb.AppendLine(")");
            result.Add(sb.ToString());
            return(result);
        }
Beispiel #7
0
 public virtual void Init(ISqlExe sqlMapper)
 {
     _sqlMapper = sqlMapper;
 }