Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
root = true

[*]
charset = utf-8
end_of_line = lf
# Note: the trim_trailing_whitespace option is br0ken in visualstudio, it
# simply does not follow the EditorConfig specification. Therefor you are
# strongly encouraged to not rely on this setting alone, but please install
# the following extension too: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TrailingWhitespaceVisualizer
#
# References:
# https://developercommunity.visualstudio.com/t/EditorConfig:-trim_trailing_whitespace-d/1240174?space=8&q=trim_trailing_whitespace
# https://developercommunity.visualstudio.com/t/editorconfig-trim_trailing_whitespace-on/134457?space=8&q=trim_trailing_whitespace
# https://developercommunity.visualstudio.com/t/trim_trailing_whitespace-in-editorconfi/1351034?space=8&q=trim_trailing_whitespace
# https://developercommunity.visualstudio.com/t/BUG:-editorconfig-trim_trailing_whitespa/953937?space=8&q=trim_trailing_whitespace
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 2


[*.cs] # To match existing style
indent_style = space
indent_size = 4


[*.yml]
indent_style = space
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ jobs:
- name: Push to GitHub Feed
run: dotnet nuget push ./nupkg/*.nupkg --skip-duplicate --source $GITHUB_FEED --api-key $GITHUB_TOKEN
- name: Push to NuGet Feed
run: dotnet nuget push ./nupkg/*.nupkg --skip-duplicate --source $NUGET_FEED --api-key $NUGET_KEY
run: dotnet nuget push ./nupkg/*.nupkg --skip-duplicate --source $NUGET_FEED --api-key $NUGET_KEY
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"processId": "${command:pickProcess}"
}
,]
}
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"problemMatcher": "$msCompile"
}
]
}
}
228 changes: 114 additions & 114 deletions Program/Program.cs
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
using System;
using System.Collections.Generic;
using SqlKata;
using SqlKata.Compilers;
using SqlKata.Execution;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Linq;
using Newtonsoft.Json;
using Npgsql;
using System.Data;
using Dapper;
using System.Data.SQLite;
using static SqlKata.Expressions;
using System.IO;

namespace Program
{
class Program
{
private class Loan
{
public string Id { get; set; }
public string Name { get; set; }
public List<Installment> Installments { get; set; } = new List<Installment>();
}

private class Installment
{
public string Id { get; set; }
public string LoanId { get; set; }
public int DaysCount { get; set; }
}

static void Main(string[] args)
{
using (var db = SqlLiteQueryFactory())
{
var query = db.Query("accounts")
.Where("balance", ">", 0)
.GroupBy("balance")
.Limit(10);

var accounts = query.Clone().Get();
Console.WriteLine(JsonConvert.SerializeObject(accounts, Formatting.Indented));

var exists = query.Clone().Exists();
Console.WriteLine(exists);
}
}

private static void log(Compiler compiler, Query query)
{
var compiled = compiler.Compile(query);
Console.WriteLine(compiled.ToString());
Console.WriteLine(JsonConvert.SerializeObject(compiled.Bindings));
}

private static QueryFactory SqlLiteQueryFactory()
{
var compiler = new SqliteCompiler();

var connection = new SQLiteConnection("Data Source=Demo.db");

var db = new QueryFactory(connection, compiler);

db.Logger = result =>
{
Console.WriteLine(result.ToString());
};

if (!File.Exists("Demo.db"))
{
Console.WriteLine("db not exists creating db");

SQLiteConnection.CreateFile("Demo.db");

db.Statement("create table accounts(id integer primary key autoincrement, name varchar, currency_id varchar, balance decimal, created_at datetime);");
for (var i = 0; i < 10; i++)
{
db.Statement("insert into accounts(name, currency_id, balance, created_at) values(@name, @currency, @balance, @date)", new
{
name = $"Account {i}",
currency = "USD",
balance = 100 * i * 1.1,
date = DateTime.UtcNow,
});
}

}

return db;

}

private static QueryFactory SqlServerQueryFactory()
{
var compiler = new PostgresCompiler();
var connection = new SqlConnection(
"Server=tcp:localhost,1433;Initial Catalog=Lite;User ID=sa;Password=P@ssw0rd"
);

var db = new QueryFactory(connection, compiler);

db.Logger = result =>
{
Console.WriteLine(result.ToString());
};

return db;
}

}
}
using System;
using System.Collections.Generic;
using SqlKata;
using SqlKata.Compilers;
using SqlKata.Execution;
using System.Data.SqlClient;
using System.Threading.Tasks;
using System.Linq;
using Newtonsoft.Json;
using Npgsql;
using System.Data;
using Dapper;
using System.Data.SQLite;
using static SqlKata.Expressions;
using System.IO;

namespace Program
{
class Program
{
private class Loan
{
public string Id { get; set; }
public string Name { get; set; }
public List<Installment> Installments { get; set; } = new List<Installment>();
}

private class Installment
{
public string Id { get; set; }
public string LoanId { get; set; }
public int DaysCount { get; set; }
}

static void Main(string[] args)
{
using (var db = SqlLiteQueryFactory())
{
var query = db.Query("accounts")
.Where("balance", ">", 0)
.GroupBy("balance")
.Limit(10);

var accounts = query.Clone().Get();
Console.WriteLine(JsonConvert.SerializeObject(accounts, Formatting.Indented));

var exists = query.Clone().Exists();
Console.WriteLine(exists);
}
}

private static void log(Compiler compiler, Query query)
{
var compiled = compiler.Compile(query);
Console.WriteLine(compiled.ToString());
Console.WriteLine(JsonConvert.SerializeObject(compiled.Bindings));
}

private static QueryFactory SqlLiteQueryFactory()
{
var compiler = new SqliteCompiler();

var connection = new SQLiteConnection("Data Source=Demo.db");

var db = new QueryFactory(connection, compiler);

db.Logger = result =>
{
Console.WriteLine(result.ToString());
};

if (!File.Exists("Demo.db"))
{
Console.WriteLine("db not exists creating db");

SQLiteConnection.CreateFile("Demo.db");

db.Statement("create table accounts(id integer primary key autoincrement, name varchar, currency_id varchar, balance decimal, created_at datetime);");
for (var i = 0; i < 10; i++)
{
db.Statement("insert into accounts(name, currency_id, balance, created_at) values(@name, @currency, @balance, @date)", new
{
name = $"Account {i}",
currency = "USD",
balance = 100 * i * 1.1,
date = DateTime.UtcNow,
});
}

}

return db;

}

private static QueryFactory SqlServerQueryFactory()
{
var compiler = new PostgresCompiler();
var connection = new SqlConnection(
"Server=tcp:localhost,1433;Initial Catalog=Lite;User ID=sa;Password=P@ssw0rd"
);

var db = new QueryFactory(connection, compiler);

db.Logger = result =>
{
Console.WriteLine(result.ToString());
};

return db;
}

}
}
2 changes: 1 addition & 1 deletion QueryBuilder.Tests/AggregateTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SqlKata.Compilers;
using SqlKata.Compilers;
using SqlKata.Tests.Infrastructure;
using Xunit;

Expand Down
2 changes: 1 addition & 1 deletion QueryBuilder.Tests/DefineTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using static SqlKata.Expressions;
using static SqlKata.Expressions;
using SqlKata.Compilers;
using SqlKata.Tests.Infrastructure;
using Xunit;
Expand Down
4 changes: 2 additions & 2 deletions QueryBuilder.Tests/ExecutionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using SqlKata.Execution;
using Xunit;

Expand All @@ -15,4 +15,4 @@ public void ShouldThrowException()
});
}
}
}
}
10 changes: 5 additions & 5 deletions QueryBuilder.Tests/Firebird/FirebirdLimitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public FirebirdLimitTests()
public void NoLimitNorOffset()
{
var query = new Query("Table");
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult { Query = query };

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -26,7 +26,7 @@ public void NoLimitNorOffset()
public void LimitOnly()
{
var query = new Query("Table").Limit(10);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult { Query = query };

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -35,7 +35,7 @@ public void LimitOnly()
public void OffsetOnly()
{
var query = new Query("Table").Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult { Query = query };

Assert.Null(compiler.CompileLimit(ctx));
}
Expand All @@ -44,12 +44,12 @@ public void OffsetOnly()
public void LimitAndOffset()
{
var query = new Query("Table").Limit(5).Offset(20);
var ctx = new SqlResult {Query = query};
var ctx = new SqlResult { Query = query };

Assert.Equal("ROWS ? TO ?", compiler.CompileLimit(ctx));
Assert.Equal(21, ctx.Bindings[0]);
Assert.Equal(25, ctx.Bindings[1]);
Assert.Equal(2, ctx.Bindings.Count);
}
}
}
}
2 changes: 1 addition & 1 deletion QueryBuilder.Tests/HelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,4 @@ public void WrapIdentifiers(string input, string escapeCharacter, string identif
Assert.Equal(expected, result);
}
}
}
}
2 changes: 1 addition & 1 deletion QueryBuilder.Tests/Infrastructure/TestCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ public virtual MethodInfo Call_FindCompilerMethodInfo(Type clauseType, string me
return FindCompilerMethodInfo(clauseType, methodName);
}
}
}
}
6 changes: 3 additions & 3 deletions QueryBuilder.Tests/Infrastructure/TestCompilersContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using SqlKata.Compilers;
Expand Down Expand Up @@ -52,7 +52,7 @@ public Compiler Get(string engineCode)
/// <returns></returns>
public TCompiler Get<TCompiler>(string engineCode) where TCompiler : Compiler
{
return (TCompiler) Get(engineCode);
return (TCompiler)Get(engineCode);
}

/// <summary>
Expand Down Expand Up @@ -103,4 +103,4 @@ public TestSqlResultContainer Compile(Query query)
return new TestSqlResultContainer(resultKeyValues);
}
}
}
}
4 changes: 2 additions & 2 deletions QueryBuilder.Tests/Infrastructure/TestSqlResultContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace SqlKata.Tests.Infrastructure
Expand All @@ -10,4 +10,4 @@ public TestSqlResultContainer(IDictionary<string, SqlResult> dictionary) : base(

}
}
}
}
Loading