Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sqlkata/querybuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-moussawi committed Mar 5, 2024
2 parents df5935c + c202922 commit a108338
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/codesee-arch-diagram.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This workflow was added by CodeSee. Learn more at https://codesee.io/
# This is v2.0 of this workflow file
on:
push:
branches:
- master
pull_request_target:
types: [opened, synchronize, reopened]

name: CodeSee

permissions: read-all

jobs:
codesee:
runs-on: ubuntu-latest
continue-on-error: true
name: Analyze the repo with CodeSee
steps:
- uses: Codesee-io/codesee-action@v2
with:
codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
codesee-url: https://app.codesee.io
27 changes: 27 additions & 0 deletions QueryBuilder.Tests/SelectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ public void ExpandedSelect()
Assert.Equal("SELECT `users`.`id`, `users`.`name`, `users`.`age` FROM `users`", c[EngineCodes.MySql]);
}

[Fact]
public void ExpandedSelectMultiline()
{
var q = new Query().From("users").Select(@"users.{
id,
name as Name,
age
}");
var c = Compile(q);

Assert.Equal("SELECT [users].[id], [users].[name] AS [Name], [users].[age] FROM [users]", c[EngineCodes.SqlServer]);
Assert.Equal("SELECT `users`.`id`, `users`.`name` AS `Name`, `users`.`age` FROM `users`", c[EngineCodes.MySql]);
}

[Fact]
public void ExpandedSelectWithSchema()
{
Expand All @@ -83,6 +97,19 @@ public void ExpandedSelectWithSchema()
Assert.Equal("SELECT [dbo].[users].[id], [dbo].[users].[name], [dbo].[users].[age] FROM [users]", c[EngineCodes.SqlServer]);
}

[Fact]
public void ExpandedSelectMultilineWithSchema()
{
var q = new Query().From("users").Select(@"dbo.users.{
id,
name as Name,
age
}");
var c = Compile(q);

Assert.Equal("SELECT [dbo].[users].[id], [dbo].[users].[name] AS [Name], [dbo].[users].[age] FROM [users]", c[EngineCodes.SqlServer]);
}

[Fact]
public void NestedEmptyWhereAtFirstCondition()
{
Expand Down
6 changes: 3 additions & 3 deletions QueryBuilder/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public static int EnumerableCount(IEnumerable obj)

public static List<string> ExpandExpression(string expression)
{
var regex = @"^(?:\w+\.){1,2}{(.*)}";
var match = Regex.Match(expression, regex);
var regex = @"^(?:\w+\.){1,2}{([^}]*)}";
var match = Regex.Match(expression, regex, RegexOptions.Multiline);

if (!match.Success)
{
Expand All @@ -152,7 +152,7 @@ public static List<string> ExpandExpression(string expression)

var captures = match.Groups[1].Value;

var cols = Regex.Split(captures, @"\s*,\s*")
var cols = Regex.Split(captures, @"\s*,\s*", RegexOptions.Multiline)
.Select(x => $"{table}.{x.Trim()}")
.ToList();

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@

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.
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.
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](https://github.com/StackExchange/Dapper) under the covers.

Expand Down Expand Up @@ -160,15 +160,15 @@ int affected = db.Query("Users").Where("Id", 1).Delete();

## FAQ
### How to know when a new release or a feature is available?
I announce updates on My [Twitter Account](https://twitter.com/ahmadmuzavi), and you can subscribe to our news letters from the website https://sqlkata.com
I announce updates on My [Twitter Account](https://twitter.com/ahmadmuzavi), and you can subscribe to our newsletters from the website https://sqlkata.com

### The database that I want is not supported why?
Usually it's impossible to support all available database vendors, this why we focus on the major ones, and we are encourage you to create your own compiler for your database
### The database that I want is not supported. Why?
It's impossible to support all available database vendors, this is why we focus on the major ones, and we encourage you to create your own compiler for your database.

### Do you accept new compilers?
Unfortunetly no, the reason is this will add overhead for the project contributors, we prefer to improve the quality of the existing compilers instead
Unfortunately, no, the reason is this will add overhead for the project contributors. We prefer to improve the quality of the existing compilers instead.

### How can I support the project?
- Star the project here in Github, and share it with your friends
- Follow and upvote it on Product Hunt <a href="https://www.producthunt.com/products/sqlkata?utm_source=badge-follow&utm_medium=badge&utm_souce=badge-sqlkata" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/follow.svg?post_id=398417&theme=light&size=small" alt="SqlKata - Dynamic&#0032;Sql&#0032;query&#0032;builder&#0032;for&#0032;dotnet | Product Hunt" style="width: 86px; height: 32px;" width="250" height="54" /></a>
- You can also donate to support the project financily on open collection.
- You can also donate to support the project financially on open collection.

0 comments on commit a108338

Please sign in to comment.