All Projects → 1448376744 → SqlBatis

1448376744 / SqlBatis

Licence: other
A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite etc..

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to SqlBatis

Dapper.lnskydb
基于Dapper的LINQ扩展,支持Lambda表达式,支持按时间分库分表,也可以自定义分库分表方法,且实体类有T4模版自动生成.省去手写实体类的麻烦。已在实际项目使用
Stars: ✭ 228 (+570.59%)
Mutual labels:  linq, dapper
System.linq.dynamic.core
The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
Stars: ✭ 864 (+2441.18%)
Mutual labels:  linq, expression
EFSqlTranslator
A standalone linq to sql translator that can be used with EF and Dapper.
Stars: ✭ 51 (+50%)
Mutual labels:  linq, dapper
Masuit.tools
ldqk.xyz/55
Stars: ✭ 2,539 (+7367.65%)
Mutual labels:  linq, expression
SQLBuilder.Core
.NET Standard 2.1、.NET 5、.NET 6 版本SQLBuilder,Expression表达式转换为SQL语句,支持SqlServer、MySql、Oracle、Sqlite、PostgreSql;基于Dapper实现了不同数据库对应的数据仓储Repository;
Stars: ✭ 85 (+150%)
Mutual labels:  expression, dapper
my-blog-project
这个项目只是我自己练手的,链接地址是基于该项目的docker版本,感谢!
Stars: ✭ 13 (-61.76%)
Mutual labels:  mybatis
spring-boot-examples
本仓库为《Spring Boot 系列文章》代码仓库,欢迎点赞、收藏。
Stars: ✭ 52 (+52.94%)
Mutual labels:  mybatis
shik
shik项目基于springcloud微服务搭建的分布式项目。搭建了shik-config云公共配置,通过shik-RA服务注册发现各个模块,通过shik-zuul路由转发与统一接口。并整合了包括mybatis,jpa,jedis,quartz,freemarker和layui等多个模块,支持spring-session二级域名共享session,使用了RESTful方式提供api接口
Stars: ✭ 89 (+161.76%)
Mutual labels:  mybatis
sinosteel
Spring Boot + React/Node.js based framework for web application development
Stars: ✭ 32 (-5.88%)
Mutual labels:  mybatis
CodexMicroORM
An alternative to ORM's such as Entity Framework, offers light-weight database mapping to your existing CLR objects. Visit "Design Goals" on GitHub to see more rationale and guidance.
Stars: ✭ 32 (-5.88%)
Mutual labels:  dapper
mayday
mayday博客系统,基于springboot、mybatis、ehcache、thymeleaf、bootstrap做的博客系统,完美自适应,支持markdown编辑器
Stars: ✭ 113 (+232.35%)
Mutual labels:  mybatis
mybatis-typehandlers-postgis
MyBatis Type Handlers for PostGIS
Stars: ✭ 58 (+70.59%)
Mutual labels:  mybatis
mybatis-helper
Mybatis plugins package
Stars: ✭ 13 (-61.76%)
Mutual labels:  mybatis
mpsl
Shader-Like Mathematical Expression JIT Engine for C++ Language
Stars: ✭ 52 (+52.94%)
Mutual labels:  expression
LinqToXsdCore
LinqToXsd ported to .NET Core (targets .NET Standard 2 for generated code and .NET Core 3.1, .NET 5+ 6 for the code generator CLI tool).
Stars: ✭ 23 (-32.35%)
Mutual labels:  linq
GraphQL.RepoDB
A set of extensions for working with HotChocolate GraphQL and Database access with micro-orms such as RepoDb (or Dapper). This extension pack provides access to key elements such as Selections/Projections, Sort arguments, & Paging arguments in a significantly simplified facade so this logic can be leveraged in the Serivces/Repositories that enca…
Stars: ✭ 25 (-26.47%)
Mutual labels:  dapper
Java-CS-Record
记录准备春招实习过程中,学习与复习的知识(模块化整理,非面试题速成)。注:暂停更新,后续请移步博客
Stars: ✭ 73 (+114.71%)
Mutual labels:  mybatis
coupons
淘宝客项目,支持App,微信小程序,QQ小程序
Stars: ✭ 392 (+1052.94%)
Mutual labels:  mybatis
money
Dapper Style Distributed Tracing Instrumentation Libraries
Stars: ✭ 65 (+91.18%)
Mutual labels:  dapper
dapper-repositories
CRUD for Dapper
Stars: ✭ 523 (+1438.24%)
Mutual labels:  dapper

SqlBatis

免责声明

本人对所有因使用本产品而导致的损失概不负责,使用前请先测试和阅读源代码并自觉遵守开源协议,可用于学习交流二次开发

打印日志

//通过重写DbContext,我们可以定制化一些需求
public class LoggerDbContext : DbContext
{
    public MyDbContext(DbContextBuilder builder)
        : base(builder)
    {

    }
    //通过覆盖CreateDbCommand,来实现日志打印,DbContext中有许多方法设计成可以被覆盖的,
    protected override IDbCommand CreateDbCommand(string sql, object parameter, int? commandTimeout = null, CommandType? commandType = null)
    {
        Trace.WriteLine("================Command===================");
        Trace.WriteLine(sql);
        Trace.WriteLine("===========================================");
        return base.CreateDbCommand(sql, parameter, commandTimeout, commandType);
    }
}
//创建数据上下文
var context = new LoggerDbContext(new DbContext()
{
    Connection = new MySqlConnector.MySqlConnection("server=127.0.0.1;user id=root;password=1024;database=test;"),
    DbContextType = DbContextType.Mysql
});

sql查询

//返回匿名类型的集合
List<dynamic> list = context.Query("select * from student").ToList();
//映射到指定类型,忽略大小写和下划线
List<Student> list = context.Query<Student>("select id,stu_name from student").ToList();
//多结果集
using(var multi = context.QueryMultiple("select id,stu_name from student;select count(1) from student"))
{
    var list = multi.Read<Student>();
    var count = multi.ReadFirst<int>();
}
public class Student
{
    public int Id {get;set;}
    public string StuName {get; set;}
}

Sqlbuilder

var b1 = new SqlBuilder();
b1.Where("id>@Id")
  .Where("score>@Score")
  .Join("student_name as b on a.id=b.sid");
var p = new { Age = 1, Score = 20 };
//对两个模板进行构建
var tmp1 = b1.Build("select * from student as a /**join**/ /**where**/ ");
var tmp2 = b1.Build("select count(1) from student as a /**join**/ /**where**/ ");
using(var multi = context.QueryMultiple($"{tmp1.RawSql};{tmp2.RawSql}",new {Id=1,Score=5}))
{
    var list = multi.Read<Student>();
    var count = multi.ReadFirst<int>();
}

Linq查询

var entity = context.From<Student>().Where(a=>a.id==1).Single();
var entitys = context.From<Student>().Where(a=>a.id>1).Select();
var entiityNames = context.From<Student>().Select(s=>new 
{ 
    s.Name,
    s.Age
});
//默认忽略:这会忽略id字段
var row = context.From<Student>().Insert(new {Name="zs",Age=1});
//默认忽略:这会忽略Age字段
var row = context.From<Student>().Update(new {Name="zs",Id=1});
//显示忽略:这会忽略所有为null的字段
var row = context.From<Student>().Ignore().Update(new Student{Name="zs",Id=1});

public class Student
{
   [PrimaryKey]
   [Indenity]
   public int Id {get;set;}
   public string Name {get;set;}
   public int Age {get;set;}
}

自定义类型映射

/// <summary>
/// 提供json转换能力
/// </summary>
public class MyDDbContextBehavior : DbContextBehavior
{
    readonly static MethodInfo _methodInfo = typeof(MyDDbContextBehavior).GetMethod("StringToJson");

    static readonly JsonSerializerOptions _jsonSerializerOptions;

    static MyDDbContextBehavior()
    {
        _jsonSerializerOptions = new JsonSerializerOptions
        {
            Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
            PropertyNameCaseInsensitive = true,
            PropertyNamingPolicy=JsonNamingPolicy.CamelCase
        };
        _jsonSerializerOptions.Converters.Add(new JsonDateTimeConverter("yyyy-MM-dd HH:mm:ss"));
        _jsonSerializerOptions.Converters.Add(new JsonDateTimeNullableConverter("yyyy-MM-dd HH:mm:ss"));
    }

    public static T StringToJson<T>(IDataRecord record, int i)
    {
        if (record.IsDBNull(i))
        {
            return default;
        }
        var json = record.GetString(i);
        return JsonSerializer.Deserialize<T>(json, _jsonSerializerOptions);
    }

    public override KeyValuePair<string, object> CreateDbCommandParameter(string name, object value)
    {
        if (value != null && typeof(ValueObject).IsInstanceOfType(value))
        {
            var json = JsonSerializer.Serialize(value, _jsonSerializerOptions);
            return base.CreateDbCommandParameter(name, json);
        }
        return base.CreateDbCommandParameter(name, value);
    }

    protected override MethodInfo FindConvertMethod(Type entityType, Type memberType, DataReaderField recordField)
    {
        if (typeof(ValueObject).IsAssignableFrom(memberType))
        {
            return _methodInfo.MakeGenericMethod(memberType);
        }
        return base.FindConvertMethod(entityType, memberType, recordField);
    }
}
var connectionString = @"server=127.0.0.1;user id=root;password=1024;database=sqlbatis;";
var connection = new MySqlConnection(connectionString);
//3.设置默认的数据库上下文行为
new MyDbContext(new DbContextBuilder()
{
    Connection = new MySqlConnector.MySqlConnection(configuration.GetConnectionString("Mysql")),
    DbContextType = DbContextType.Mysql,
    DbContextBehavior = new MyDDbContextBehavior()
})

定义简单的函数

[SqlBatis.Attributes.Function]
 public static class SqlFun
 {
     public static T2 IF<T1, T2>(T1 column, T2 v1, T2 v2)
     {
         return default;
     }

     public static bool ISNULL<T1>(T1 t1)
     {
         return default;
     }
 }
 
 var list = _context.From<StudentDto>()
  .Ignore(a => a.StuGender)
  .Select(s => new
  {
      FF = SqlFun.IF(SqlFun.ISNULL(s.SchId), 1, 2)
  });
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].