1 Star 0 Fork 0

Rocher / Bara

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

    ____                     
   |  _ \                    
   | |_) |  __ _  _ __  __ _ 
   |  _ <  / _` || '__|/ _` |
   | |_) || (_| || |  | (_| |
   |____/  \__,_||_|   \__,_|
                             
                            

Bara

Codacy Appveyor NuGet Gitchat
Codacy Badge Build status NuGet Join the chat at https://gitter.im/Bara

Bara is a .Net library for Orm. Bara provides quick access to DataBase. Also it is a cross-platform orm which is written by .net Standard version 1.4 . You Can use it on .net Framwork platform or .net Core platform with Any type DataBase which Dapper Support.

Features

  • Using Dapper for DataMapping and DataAccess.
  • Using Xml Config and Manage your sql like Ibatis.
  • Hot Update Sql when you changed your sql sentence.

Installing

Just install the Bara NuGet package:

PM> Install-Package Bara

If your want Bara Extension.(A collection of commonly used methods already included)

PM> Install-Package Bara.DataAccess

How To Use After Intalled

1.Add BaraMapConfig.xml To Root Path.

  • Config whether the config need Watched.It will be update when setting true.
  • Config DataBase ConnectString
  • Split Writen DB and Read DB. Specify each Database Weight which indicate the Access probability.
  • Specify the ParameterPrefix(MSSQL:'@',Mysql:'#'...)
  • Config your Maps which your sql in.
<?xml version="1.0" encoding="utf-8" ?>
<BaraMapConfig xmlns="https://github.com/RocherKong/Bara/schemas/BaraMapConfig.xsd">
  <Settings
    IsWatchConfigFile="true"
  />
  <Database>
    <DbProvider Name="SqlClientFactory" ParameterPrefix="@" Type="System.Data.SqlClient.SqlClientFactory,System.Data.SqlClient"/>
    <Write Name="WriteDB" ConnectionString="Data Source=.;database=GoodJob;uid=sa;pwd=App1234"/>
    <Read Name="ReadDB-0" ConnectionString="Data Source=.;database=GoodJob;uid=sa;pwd=App1234" Weight="50"/>
    <Read Name="ReadDB-1" ConnectionString="Data Source=.;database=GoodJob;uid=sa;pwd=App1234" Weight="50"/>
  </Database>
  <BaraMaps>
    <BaraMap Path="Maps/" Type="Directory"></BaraMap>
  </BaraMaps>
</BaraMapConfig>

Oracle:(Reference ODP Library From ./Doc/OracleDataProvider)
<DbProvider Name="OracleClientFactory" ParameterPrefix=":" Type="Oracle.ManagedDataAccess.Client.OracleClientFactory,Oracle.ManagedDataAccess,Version=4.122.1.0,Culture=neutral, PublicKeyToken=89b483f429c47342"/>
<Write Name="WriteDB" ConnectionString="User Id=User;Password=User;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));"/>

2.Config BaraMap Xml Files(eg:T_Test.xml in Root-Folder Maps)

3.Register To DI in Startup.cs

 services.AddSingleton<IBaraMapper>(MapperContainer.Instance.GetBaraMapper());

4.Use Any Where

4.1 GetEntity

var mapper = new BaraMapper();
var result = mapper.QuerySingle<T_Test>(new Core.Context.RequestContext
  {
      SqlId = "GetEntity",
      Scope = "T_Test",
      Request = new { Id = 1 }
  });

4.2 QueryList

var list= mapper.Query<T_Test>(new Core.Context.RequestContext
  {
      SqlId="GetList",
      Scope="T_Test",
  });

4.3 Add

int i = mapper.Execute(new Core.Context.RequestContext
  {
      Scope = "T_Test",
      SqlId = "Insert",
      Request = new { Id = 4, Name = "Rocher4" }
  });

4.4 Update

int i = mapper.Execute(new Core.Context.RequestContext
  {
      Scope = "T_Test",
      SqlId = "Update",
      Request = Entity
  });

Cache Config

Firstly You Need Config Cache in BaraMap file .

<Caches>
    <Cache Id="T_Test.LruCache" Type="Lru">
      <Parameter Key="CacheSize" Value="100"/>
      <FlushInterval Hours="0" Minutes="10" Seconds="0"/>
      <FlushOnExecute Statement="T_Test.Insert"/>
      <FlushOnExecute Statement="T_Test.Update"/>
    </Cache>
</Caches>

Secondly You Need Relate Cache to your statement.

<Statement Id="QueryList" Cache="T_Test.LruCache">
  SELECT Top 10 T.* From T_Test T With(NoLock)
  <Include RefId="QueryParams"/>
</Statement>

After config Metioned.The Same-Query after first Query Will fetch Data from Cache.Also it will dismiss after Insert or Update method executed.

Next Step

  • 0.Tags(Logic bit operator)
  • 1.Test
  • 2.Test Compare
  • 3.redis cache
  • 4.zookeeper(options)
  • 5.add Doc
  • 6.Release

Tips

  • Can DataAccess be more Simple?(Auto Generate dao Code for Mapping Method Name.)

Thanks

Ahoo-Wang/SmartSql:

空文件

简介

micro orm for .net cross-platform 展开 收起
C# 等 4 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/rocherkong/Bara.git
git@gitee.com:rocherkong/Bara.git
rocherkong
Bara
Bara
master

搜索帮助