DBLayer,我最近開源的資料庫輕量級orm框架,目前支持sqlserver、mysql、oracle, 特別做了分頁的封裝。 這個框架從七八年前開始逐漸升級而來,也經歷了不少項目,希望可以將大家從sql字元串中解放出來。 開源地址 https://github.com/wutao0315/DBL ...
DBLayer,我最近開源的資料庫輕量級orm框架,目前支持sqlserver、mysql、oracle, 特別做了分頁的封裝。
這個框架從七八年前開始逐漸升級而來,也經歷了不少項目,希望可以將大家從sql字元串中解放出來。
開源地址
https://github.com/wutao0315/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; }
分頁操作
/// <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; }
推薦和spring 配合使用,具體配置代碼請進入源碼查看。
同時在spring 配置多個資料庫連接,支持資料庫連接字元串密碼加密。只需要在 passwordKey加入密鑰
<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>
資料庫唯一標識除了可以數據自動編碼,還支持在代碼端自動 生成 GUID 和 時間點。下麵代碼是uuid,時間點並按照順序生成的自動編號
<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>