Skip to content

parakago/Leettle.Data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeettleDB

Introduction

LeettleDB is a C# ADO.NET wrapper library to provide simple and easy api for different types of database providers and useful method that maps fetched result to a POCO.

Example

  • Creating leettleDB object
var leettleDb = new LeettleDbBuilder()
    .WithConnectionType(typeof(System.Data.SQLite.SQLiteConnection))
    .WithConnectionString("Data Source=:memory:;Version=3;New=True;")
    .WithBindStrategy(new CamelObjectSnakeDbBindStrategy(':'))
    .Build();
  • Fetching and mapping to POCO List
using (var con = leettleDb.OpenConnection())
{
    // codes disposing resource doesn't need.
    List<Author> authors = con.NewDataset("select * from Author where name like :name")
        .SetParam("name", "%phen%")
        .OpenAndFetchList<Author>();
}
  • Basic raw API fetching data
using (var con = leettleDb.OpenConnection())
{
    con.NewDataset("select * from Author where name like :name")
        .SetParam("name", "%phen%")
        .Open(dr =>
    {
        while (dr.Next())
        {
            var authorId = dr.GetInt("id");
            var authorName = dr.GetString("name");
        }
    });
}
  • Transaction
using (var con = leettleDb.OpenConnection())
{
    con.RunInTransaction(() =>
    {
        con.NewCommand("insert into Author values (:id, :name)")
            .SetParam("id", 1)
            .SetParam("name", "dodo")
            .Execute();
        
        con.NewCommand("insert into AuthorBook values (:id, :title)")
            .SetParam("id", 1)
            .SetParam("title", "dodo's story")
            .Execute();
    });
}

Check out Getting Started page.

Performance Benchmarking Test

Method Mean Error StdDev Ratio RatioSD
Leettle.Data 54.55 ms 0.657 ms 0.549 ms 1.29 0.02
Oracle Managed Data Direct Access 42.42 ms 0.464 ms 0.387 ms 1.00 0.00
NHibernate 119.83 ms 1.898 ms 2.031 ms 2.83 0.05

Installation

  • install Leettle.Data package through the nuget.
  • install ado.net data provider that what you want. (following data providers were tested)
    • Oracle (Oracle.ManagedDataAccess)
    • MySql (Mysql.Data)
    • PostgreSQL (Npgsql)
    • SQLite (System.Data.SQLite.Core)
    • SQL Server (System.Data.SqlClient)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages