The latest open source DBLayer, the original database operations can be so simple, open source dblayer

Source: Internet
Author: User

The latest open source DBLayer, the original database operations can be so simple, open source dblayer

DBLayer: I recently developed a lightweight orm framework for open-source databases. Currently, it supports sqlserver, mysql, and oracle, especially paging encapsulation.

This framework has been gradually upgraded since year 78 and has gone through many projects, hoping to free everyone from SQL strings.

Open Source Address

Https://github.com/wutao0315/DBLayer

 

Access code case

Var id = TheService. insertEntity <SysLog, long> () => new SysLog () {LogId =-1, LogContentJson = "test", LogCreater = "test", LogCreateTime = DateTime. now, LogType = "1 "});
Paging operation
/// <Summary> /// query by PAGE /// </summary> /// <param name = "condition"> query 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 ;}

We recommend that you use spring in combination. For specific configuration code, see the source code.

At the same time, configure multiple database connections in spring to support database connection string and password encryption. You only need to add a key to 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>

In addition to automatic data encoding, the unique database identifier also supports automatic generation of guids and time points on the Code side. The following code is uuid, which is automatically generated at the time point in sequence.

<Object id = "uuidGenerator" type = "DBLayer. Persistence. UUIDGenerator, DBLayer. Persistence" singleton = "true"> <! -- WorkerId: Region (Data Center): 3 bits --> <constructor-arg name = "workerId" value = "1"/> <! -- RegionId: machine no.: 10 bits --> <constructor-arg name = "regionId" value = "1"/> <! -- Twepoch: reference time: 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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.