最新开源DBLayer,数据库操作也可以很简单

发布时间:2020-07-29 20:52:08 作者:zddnd
来源:网络 阅读:486

DBLayer,我最近开源的数据库轻量级orm框架,目前支持sqlserver、mysql、oracle, 特别做了分页的封装。

这个框架从七八年前开始逐渐升级而来,也经历了不少项目,希望可以将大家从sql字符串中解放出来。

开源地址

https://github.com/wutao0315/DBLayer

 

访问代码案例

最新开源DBLayer,数据库操作也可以很简单

var id = TheService.InsertEntity<SysLog, long>(
        () => new SysLog()
        {
            LogId = -1,
            LogContentJson = "测试",
            LogCreater = "测试",
            LogCreateTime = DateTime.Now,
            LogType = "1"
        });

最新开源DBLayer,数据库操作也可以很简单

分页操作

最新开源DBLayer,数据库操作也可以很简单

        /// <summary>
        /// 分页查询        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <returns></returns>
        public IEnumerable<SysUser> Seach(SysUserCondition.Search condition)
        {            var page = new Pager<SysUserCondition.Search>()
            {
                Condition = condition,
                Table = "sys_user",
                Key = "user_id",
                Order = string.Empty,
                Field = "*",
                WhereAction = (Condition, Where, Paramters) =>
                {                    if (!string.IsNullOrEmpty(Condition.UserName))
                    {
                        Where.Append("AND user_name LIKE @user_name ");
                        Paramters.Add(base.CreateParameter("@user_name", string.Concat("%", Condition.UserName, "%")));
                    }                    if (!string.IsNullOrEmpty(Condition.UserEmail))
                    {
                        Where.Append("AND user_email LIKE @user_email ");
                        Paramters.Add(base.CreateParameter("@user_email", string.Concat("%", Condition.UserEmail, "%")));
                    }                    if (!string.IsNullOrEmpty(Condition.UserMobile))
                    {
                        Where.Append("AND user_mobile LIKE @user_mobile ");
                        Paramters.Add(base.CreateParameter("@user_mobile", string.Concat("%", Condition.UserMobile, "%")));
                    }
                }
            };            var result = base.GetResultByPager<SysUser, SysUserCondition.Search>(page);            return result;
        }

最新开源DBLayer,数据库操作也可以很简单

推荐和spring 配合使用,具体配置代码请进入源码查看。

同时在spring 配置多个数据库连接,支持数据库连接字符串密码加密。只需要在 passwordKey加入密钥

最新开源DBLayer,数据库操作也可以很简单

  <object id="sql_wxius_string_server" type="DBLayer.Core.ConnectionString, DBLayer.Core" singleton="true">
    <property name="Properties">
      <name-values>
        <add key="userid" value="sa" />
        <add key="password" value="***" />
        <add key="passwordKey" value="" />
        <add key="database" value="wxius" />
        <add key="datasource" value="." />
      </name-values>
    </property>
    <property name="ConnectionToken" value="Password=${password};Persist Security Info=True;User ID=${userid};Initial Catalog=${database};Data Source=${datasource};pooling=true;min pool size=5;max pool size=10" />
  </object>

最新开源DBLayer,数据库操作也可以很简单

数据库唯一标识除了可以数据自动编码,还支持在代码端自动 生成 GUID 和 时间点。下面代码是uuid,时间点并按照顺序生成的自动编号

最新开源DBLayer,数据库操作也可以很简单

  <object id="uuidGenerator" type="DBLayer.Persistence.UUIDGenerator, DBLayer.Persistence" singleton="true" >
    <!--workerId:区域(机房):3 bits-->
    <constructor-arg name="workerId" value="1"/>
    <!--regionId:机器编号:10 bits-->
    <constructor-arg name="regionId" value="1"/>
    <!--twepoch:基准时间:Thu, 04 Nov 2010 01:42:54 GMT-->
    <!--(long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds-->
    <constructor-arg name="twepoch" value="1288834974657"/>
  </object>

最新开源DBLayer,数据库操作也可以很简单


推荐阅读:
  1. 安装wampserver的过程很简单,php爱好者有福了
  2. Python也能高并发

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

db layer

上一篇:java反射技术

下一篇:8Python全栈之路系列之MySQL触发器

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》