All Projects → cdroulers → awesome-sql-builder

cdroulers / awesome-sql-builder

Licence: LGPL-3.0 license
A small library for building SQL queries in a better way than regular string concatenation.

Programming Languages

C#
18002 projects
powershell
5483 projects

Projects that are alternatives of or similar to awesome-sql-builder

Ship Hold
data access framework for Postgresql on nodejs
Stars: ✭ 110 (+150%)
Mutual labels:  builder, sql-query
qhs
SQL queries on CSV and TSV files
Stars: ✭ 31 (-29.55%)
Mutual labels:  sql-query
Qmkbuilder
Online GUI for QMK Firmware
Stars: ✭ 254 (+477.27%)
Mutual labels:  builder
spec-pattern
Specification design pattern for JavaScript and TypeScript with bonus classes
Stars: ✭ 43 (-2.27%)
Mutual labels:  builder
opla
🚀 🤖 Your open chatbot builder. Start here to install Opla. ✨
Stars: ✭ 46 (+4.55%)
Mutual labels:  builder
ui5-cap-event-app
Showcase of SAP Cloud Application Programming Model and OData V4 with draft mode in a freestyle SAPUI5 app and an SAP Fiori elements app.
Stars: ✭ 70 (+59.09%)
Mutual labels:  odata
React Email Editor
Drag-n-Drop Email Editor Component for React.js
Stars: ✭ 3,131 (+7015.91%)
Mutual labels:  builder
builder
🍉 Build scenes for Decentraland
Stars: ✭ 141 (+220.45%)
Mutual labels:  builder
swift-declarative-configuration
Declarative configuration for your objects
Stars: ✭ 46 (+4.55%)
Mutual labels:  builder
oasis-sdk
Official SDK for the Oasis Network.
Stars: ✭ 57 (+29.55%)
Mutual labels:  builder
AndroidEasySQL-Library
An Easier & Lazier approach to SQL database for Android
Stars: ✭ 28 (-36.36%)
Mutual labels:  sql-query
oh-my-design-patterns
🎨 Record the articles and code I wrote while learning design patterns
Stars: ✭ 33 (-25%)
Mutual labels:  builder
angular-odata-es5
OData Service for Angular.io (es5 version)
Stars: ✭ 45 (+2.27%)
Mutual labels:  odata
SQL-Practice
Solutions to Problems For SQL on Leetcode, Hackerrank & DataLemur
Stars: ✭ 116 (+163.64%)
Mutual labels:  sql-query
SQLServerTools
This repo is the home of various SQL-Server-Tools
Stars: ✭ 28 (-36.36%)
Mutual labels:  sql-query
Dgr
Container build and runtime tool
Stars: ✭ 249 (+465.91%)
Mutual labels:  builder
flutter sticky and expandable list
粘性头部与分组列表Sliver实现 Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.
Stars: ✭ 116 (+163.64%)
Mutual labels:  builder
smaller-sites
Smaller Sites is a small BUT Powerful, free and easy to use drag and drop builder for blogs, websites or e-commerce stores. Designed for everyone Developers and non Developers. You can use it to design your next website. The goal is to create something like webflow
Stars: ✭ 27 (-38.64%)
Mutual labels:  builder
SwiftBuilder
SwiftBuilder is a fast way to assign new value to the property of the object.
Stars: ✭ 26 (-40.91%)
Mutual labels:  builder
maestro
Faster CI/CD for multi-artifact projects
Stars: ✭ 13 (-70.45%)
Mutual labels:  builder

Awesome.Data.Sql.Builder

Travis CI: Build Status Gitter Chat: Gitter chat

A small library for building SQL queries in a better way than regular string concatenation.

Clauses can be added in any order.

Mostly for use directly by ADO.NET or micro-ORMs such as Dapper. It aims to support as much of SQL as possible in a fluent, simple way.

It definitely does not aim to be an ORM, so there's no integration with any actual querying mechanism!

Awesome.Data.Sql.Builder.OData

A small helper project that allows transforming ODataQueryOptions<T> directly into a SelectStatement.

Installation

NuGet Awesome.Data.Sql.Builder

Install-Package Awesome.Data.Sql.Builder

NuGet Awesome.Data.Sql.Builder.OData

Install-Package Awesome.Data.Sql.Builder.OData

Awesome.Data.Sql.Builder Usage

SELECT Statement

Here is a sample unit test from the project.

var statement = SqlStatements.Select(new[] { "u.ID", "u.Name", "u.EmailAddress" })
    .From("Users u")
    .Where("u.IsCool = TRUE")
    .Where("u.Name LIKE @Query")
    .OrderBy("u.Name", false)
    .Limit(3).Offset(6);

var sql = statement.ToSql();

Assert.That(
    sql,
    SqlCompareConstraint.EqualTo(@"SELECT
    u.ID, u.Name, u.EmailAddress
FROM
    Users u
WHERE
    u.IsCool = TRUE AND
    u.Name LIKE @Query
ORDER BY
    u.Name DESC
LIMIT 3 OFFSET 6"));

UPDATE Statement

Sample unit test!

var statement = new UpdateStatement(new[] { "ID", "Name", "EmailAddress" })
    .From("Users")
    .Where("u.IsCool = TRUE")
    .Where("u.Name LIKE @Query");

var sql = statement.ToSql();

Assert.That(
    sql,
    SqlCompareConstraint.EqualTo(@"UPDATE Users
SET
    ID = @ID,
    Name = @Name,
    EmailAddress = @EmailAddress
WHERE
    u.IsCool = TRUE AND
    u.Name LIKE @Query"));

INSERT Statement

Sample unit test!

var statement = new InsertStatement(new[] { "Name", "EmailAddress" })
    .Into("Users");

var sql = statement.ToSql();

Assert.That(
    sql,
    SqlCompareConstraint.EqualTo(@"INSERT INTO Users
    (
        Name,
        EmailAddress
    )
VALUES
    (
        @Name,
        @EmailAddress
    )"));

DELETE Statement

Sample unit test!

var statement = new DeleteStatement(tableToDelete: "u")
    .From("Users u")
    .InnerJoin("Teams t", "u.TeamID = t.ID")
    .Where("t.IsOld = TRUE");

var sql = statement.ToSql();

Assert.That(
    sql,
    SqlCompareConstraint.EqualTo(@"DELETE u
FROM
    Users u
    INNER JOIN Teams t ON u.TeamID = t.ID
WHERE
    t.IsOld = TRUE"));

Different provider

var statement = new SelectStatement(new[] { "u.ID" })
    .From("Users u")
    .Limit(3)
    .Offset(6);

var sql = new SqlServer2012SqlRenderer().RenderSelect(statement);

Assert.That(
    sql,
    SqlCompareConstraint.EqualTo(@"SELECT
    u.ID
FROM
    Users u
OFFSET 6 ROWS
FETCH NEXT 3 ROWS ONLY"));

Awesome.Data.Sql.Builder.OData Usage

var options = ODataQueryOptionsHelper.Build<TestDTO>(
    "$select=Id,Name,Contact/FirstName,Contact/BirthDate,Contact/Address/City&" + 
    "$expand=Contact,Contact/Address&" +
    "$top=10&" +
    "$skip=20");
var result = new ODataQueryOptionsToSqlStatement().ToSelect(options).First();

Assert.That(
    result.ColumnsList,
    Is.EquivalentTo(new[]
    {
        "Id",
        "Name",
        "Contact/FirstName",
        "Contact/BirthDate",
        "Contact/Address/City"
    }));
Assert.That(result.LimitClause, Is.EqualTo("10"));
Assert.That(result.OffsetClause, Is.EqualTo("20"));

Only supports $select, $top, $skip and $inlinecount=allpages for now!

Using with ADO.NET

You can generate the SQL then add the parameters manually.

var select = SqlStatements.Select("Name").From("Users").Where("Name LIKE @Query");

cmd.Text = select.ToString();
cmd.Parameters.AddWithValue("@Query", "%" + userInput + "%");

var dr = cmd.ExecuteDataReader();

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Make sure you add a unit test!
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request :D

Credits

Author: cdroulers

License

LGPL: See LICENSE

Awesome.Data.Sql.Builder History

1.2.0 (2018-05-07)

  • Basic support for INSERT, UPDATE and DELETE statements.

1.1.0 (2016-01-18)

  • Support for different SQL providers (SQL Server in particular) in a pluggable way.

1.0.0 (2012-11-16)

  • First public version. Supports all basic SQL operations for PostgreSQL.

Roadmap

1.2.0

  • ???

Awesome.Data.Sql.Builder.OData History

1.0.0 (2016-01-23)

  • First public version. Supports $select, $top, $skip and $inlinecount=allpages.

Roadmap

1.1.0

  • Support basic $filter operations
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].