Skip to content

mgpx/querybuilder

 
 

Repository files navigation

SqlKata Query Builder

Build status

SqlKata on Nuget

SqlKata Query Builder is a powerful Sql Query Builder written in C#.

it's secure and framework agnostic. Inspired by the top Query Builders available, like Laravel Query Builder, and Knex.

SqlKata has an expressive API. it follows a clean naming convention, which is very similar to the SQL syntax.

It make writing SQL queries easy and funny, with no need to read long pages of documentations.

It provides a level of abstraction over the supported database engines, that allows you to work with multiple databases with the same unified API.

SqlKata supports complex queries, such as nested conditions, selection from SubQuery, filtering over SubQueries, Conditional Statements, Deep Joins and others. Currently it has built-in compilers for SqlServer 2008 and above, MySql and PostgreSql.

Some fresh code

var compiler = new SqlServerCompiler();

var withSportCars = Config.get('IncludeSportsCar');

var fastCarsQuery = new Query("Cars")
    .Where("Speed", ">", 120);

if(withSportCars) 
{
    fastCarsQuery.OrWhere("IsSportCar", true);
}

string sql = compiler.Compile(fastCarsQuery).Sql;

Check out the docs for other examples SqlKata docs

Why do I need a Query Builder ?

I've started building this Query Builder, when I was developing big applications that have complex dashboards, and reports.

before I've used to write my SQL queries in strings, and things get worse quickly when you have some dynamic conditions, and even when you are working with multiple database providers, like SqlServer and PostgreSql with the same code base.

Installation

SqlKata is supported on both dotnet standard and net framework 4.5.*.

To install it check the installation guide from the Installing SqlKata

What Next ?

While SqlKata is still in beta, I've stopped adding new major features until I get a stable release.

But to give you an idea about my priorities, I will add the support to Execute Queries, Caching mechanism and to support more native features across available compilers.

Contributions

I don't have a strict contribution guide till the moment, but you can contribute with ideas, bug fixing, or add more test cases.

One simple note to keep in mind, that there is no room for complex or unclean features.

A big thanks for all contributors, for making SqlKata an awesome library

About

SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql and PostgreSql

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.2%
  • PowerShell 2.7%
  • Batchfile 0.1%