All Projects → sqlkata → Querybuilder

sqlkata / Querybuilder

Licence: mit
SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Querybuilder

Jooq
jOOQ is the best way to write SQL in Java
Stars: ✭ 4,695 (+122.41%)
Mutual labels:  sql, sql-query, database, mysql, postgresql, sql-query-builder
Squid
🦑 Provides SQL tagged template strings and schema definition functions.
Stars: ✭ 57 (-97.3%)
Mutual labels:  sql, query-builder, sql-query, database, postgresql
Beekeeper Studio
Modern and easy to use SQL client for MySQL, Postgres, SQLite, SQL Server, and more. Linux, MacOS, and Windows.
Stars: ✭ 8,053 (+281.48%)
Mutual labels:  sql, database, mysql, postgresql, sql-server
Nut
Advanced, Powerful and easy to use ORM for Qt
Stars: ✭ 181 (-91.43%)
Mutual labels:  sql, database, mysql, postgresql, sql-server
Sqlfiddle3
New version based on vert.x and docker
Stars: ✭ 242 (-88.54%)
Mutual labels:  sql, database, mysql, postgresql, sql-server
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (-53.39%)
Mutual labels:  sql, sql-query, database, mysql, postgresql
Jet
Type safe SQL builder with code generation and automatic query result data mapping
Stars: ✭ 373 (-82.33%)
Mutual labels:  sql, sql-query, database, mysql, postgresql
Postguard
🐛 Statically validate Postgres SQL queries in JS / TS code and derive schemas.
Stars: ✭ 104 (-95.07%)
Mutual labels:  sql, query-builder, sql-query, database, postgresql
Db Dumper
Dump the contents of a database
Stars: ✭ 744 (-64.76%)
Mutual labels:  sql, database, mysql, postgresql
Eralchemy
Entity Relation Diagrams generation tool
Stars: ✭ 767 (-63.67%)
Mutual labels:  sql, database, mysql, postgresql
Reiner
萊納 - A MySQL wrapper which might be better than the ORMs and written in Golang
Stars: ✭ 19 (-99.1%)
Mutual labels:  sql, query-builder, database, mysql
Vscode Sqltools
Database management for VSCode
Stars: ✭ 741 (-64.9%)
Mutual labels:  sql, sql-query, mysql, postgresql
Ship Hold
data access framework for Postgresql on nodejs
Stars: ✭ 110 (-94.79%)
Mutual labels:  query-builder, sql-query, database, postgresql
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (-74.47%)
Mutual labels:  sql, database, mysql, postgresql
Qb
The database toolkit for go
Stars: ✭ 524 (-75.18%)
Mutual labels:  sql, database, mysql, postgresql
Aspnetcorenlog
ASP.NET Core NLog MS SQL Server PostgreSQL MySQL Elasticsearch
Stars: ✭ 54 (-97.44%)
Mutual labels:  sql, mysql, postgresql, sql-server
Kangaroo
SQL client and admin tool for popular databases
Stars: ✭ 127 (-93.98%)
Mutual labels:  sql, database, mysql, postgresql
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (-39.98%)
Mutual labels:  sql, database, mysql, postgresql
Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (-40.12%)
Mutual labels:  sql, database, mysql, postgresql
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+760.63%)
Mutual labels:  database, mysql, postgresql, sql-server

SqlKata Query Builder

Twitter

WE ARE NOT ACCEPTING NEW COMPILERS, if you want to add your own compiler, we recommend to create a separate repo like SqlKata-Oracle

Follow Twitter for the latest updates about SqlKata.

Quick Demo

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.

By providing 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 and others. Currently it has built-in compilers for SqlServer, MySql, PostgreSql and Firebird.

The SqlKata.Execution package provides the ability to submit the queries to the database, using Dapper under the covers.

Checkout the full documentation on https://sqlkata.com

Installation

using dotnet cli

$ dotnet add package SqlKata

using Nuget Package Manager

PM> Install-Package SqlKata

Quick Examples

Setup Connection

var connection = new SqlConnection("...");
var compiler = new SqlCompiler();

var db = new QueryFactory(connection, compiler)

QueryFactory is provided by the SqlKata.Execution package.

Retrieve all records

var books = db.Query("Books").Get();

Retrieve published books only

var books = db.Query("Books").WhereTrue("IsPublished").Get();

Retrieve one book

var introToSql = db.Query("Books").Where("Id", 145).Where("Lang", "en").First();

Retrieve recent books: last 10

var recent = db.Query("Books").OrderByDesc("PublishedAt").Limit(10).Get();

Include Author information

var books = db.Query("Books")
    .Include(db.Query("Authors")) // Assumes that the Books table have a `AuthorId` column
    .Get();

This will include the property "Author" on each "Book"

[{
    "Id": 1,
    "PublishedAt": "2019-01-01",
    "AuthorId": 2,
    "Author": { // <-- included property
        "Id": 2,
        "...": ""
    }
}]

Join with authors table

var books = db.Query("Books")
    .Join("Authors", "Authors.Id", "Books.AuthorId")
    .Select("Books.*", "Authors.Name as AuthorName")
    .Get();

foreach(var book in books)
{
    Console.WriteLine($"{book.Title}: {book.AuthorName}");
}

Conditional queries

var isFriday = DateTime.Today.DayOfWeek == DayOfWeek.Friday;

var books = db.Query("Books")
    .When(isFriday, q => q.WhereIn("Category", new [] {"OpenSource", "MachineLearning"}))
    .Get();

Pagination

var page1 = db.Query("Books").Paginate(10);

foreach(var book in page1.List)
{
    Console.WriteLine(book.Name);
}

...

var page2 = page1.Next();

Insert

int affected = db.Query("Users").Insert(new {
    Name = "Jane",
    CountryId = 1
});

Update

int affected = db.Query("Users").Where("Id", 1).Update(new {
    Name = "Jane",
    CountryId = 1
});

Delete

int affected = db.Query("Users").Where("Id", 1).Delete();
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].