diff --git a/.editorconfig b/.editorconfig
index b33fe946..6beac8af 100755
--- a/.editorconfig
+++ b/.editorconfig
@@ -15,8 +15,9 @@ end_of_line = lf
# 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_style = space
indent_size = 2
+ij_xml_space_inside_empty_tag = true
[*.cs] # To match existing style
diff --git a/BuildScripts/update-version.ps1 b/BuildScripts/update-version.ps1
new file mode 100644
index 00000000..59d217ad
--- /dev/null
+++ b/BuildScripts/update-version.ps1
@@ -0,0 +1,86 @@
+$Path = "$( $PSScriptRoot )/version.txt"
+$values = Get-Content $Path | Out-String | ConvertFrom-StringData
+#$values.Version
+#$values.Package
+
+$projects = @(
+"QueryBuilder",
+"SqlKata.Execution"
+)
+
+Function UpdateVersion($csprojPath)
+{
+ "File: " + $csprojPath | Write-Host
+ [xml]$xml = Get-Content $csprojPath
+
+ if ($xml.Project.PropertyGroup.GetType().ToString() -eq "System.Xml.XmlElement")
+ {
+ $group = $xml.Project.PropertyGroup
+ }
+ else
+ {
+ $group = $xml.Project.PropertyGroup[0]
+ }
+
+ if ($null -ne $group.Version -and !$values.Package.equals($group.Version))
+ {
+ "Version: " + $group.Version + " -> " + $values.Package | Write-Host
+ $group.Version = $values.Package
+ }
+
+ if ($null -ne $group.AssemblyVersion -and !$values.Version.equals($group.AssemblyVersion))
+ {
+ "AssemblyVersion: " + $group.AssemblyVersion + " -> " + $values.Version | Write-Host
+ $group.AssemblyVersion = $values.Version
+ }
+
+ if ($null -ne $group.FileVersion -and !$values.Version.equals($group.FileVersion))
+ {
+ "FileVersion: " + $group.FileVersion + " -> " + $values.Version | Write-Host
+ $group.FileVersion = $values.Version
+ }
+
+ if ($null -ne $group.Copyright)
+ {
+ $group.Copyright = "OptimaJet Workflow Engine " + (Get-Date).Year
+ }
+
+ if ($null -ne $group.Product)
+ {
+ $group.Product = "Data Engine"
+ }
+
+ $PackageReference = $xml.Project.ItemGroup.PackageReference
+
+ foreach ($package in $PackageReference)
+ {
+ if ($null -eq $package.Include -and $null -eq $package.Version)
+ {
+ continue;
+ }
+
+ $packName = $package.Include.ToString()
+ $packVersion = $package.Version.ToString()
+
+ foreach ($project in $projects)
+ {
+ if ($packName.equals($project) -and !$packVersion.equals($values.Package))
+ {
+ $packName + " " + $packVersion + " -> " + $values.Package | Write-Host
+ $package.Version = $values.Package
+ break
+ }
+ }
+ }
+
+ $xml.Save($csprojPath);
+ "Saved: " + $csprojPath | Write-Host
+}
+
+"Updating projects" | Write-Host
+"---------------------------------------" | Write-Host
+
+foreach ($project in $projects)
+{
+ UpdateVersion([IO.Path]::Combine($PSScriptRoot, "..", $project, $project + ".csproj"))
+}
\ No newline at end of file
diff --git a/BuildScripts/version.txt b/BuildScripts/version.txt
new file mode 100644
index 00000000..a53e0a47
--- /dev/null
+++ b/BuildScripts/version.txt
@@ -0,0 +1,2 @@
+Version=0.0.2
+Package=0.0.2
diff --git a/Program/AssemblyManifest.cs b/Program/AssemblyManifest.cs
new file mode 100644
index 00000000..28e984c2
--- /dev/null
+++ b/Program/AssemblyManifest.cs
@@ -0,0 +1 @@
+[assembly: Fody.ConfigureAwait(false)]
diff --git a/Program/FodyWeavers.xml b/Program/FodyWeavers.xml
new file mode 100644
index 00000000..00e1d9a1
--- /dev/null
+++ b/Program/FodyWeavers.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/Program/FodyWeavers.xsd b/Program/FodyWeavers.xsd
new file mode 100644
index 00000000..3f3946e2
--- /dev/null
+++ b/Program/FodyWeavers.xsd
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.
+
+
+
+
+ A comma-separated list of error codes that can be safely ignored in assembly verification.
+
+
+
+
+ 'false' to turn off automatic generation of the XML Schema file.
+
+
+
+
+
\ No newline at end of file
diff --git a/Program/Program.csproj b/Program/Program.csproj
index 6341ecef..aaeca952 100644
--- a/Program/Program.csproj
+++ b/Program/Program.csproj
@@ -6,7 +6,14 @@
-
+
+ all
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
@@ -15,7 +22,8 @@
Exe
false
- netcoreapp2.0
+ net6.0
+ true
diff --git a/QueryBuilder.Tests/AssemblyManifest.cs b/QueryBuilder.Tests/AssemblyManifest.cs
new file mode 100644
index 00000000..627c6805
--- /dev/null
+++ b/QueryBuilder.Tests/AssemblyManifest.cs
@@ -0,0 +1 @@
+[assembly: Fody.ConfigureAwait(false)]
\ No newline at end of file
diff --git a/QueryBuilder.Tests/FodyWeavers.xml b/QueryBuilder.Tests/FodyWeavers.xml
new file mode 100644
index 00000000..00e1d9a1
--- /dev/null
+++ b/QueryBuilder.Tests/FodyWeavers.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/QueryBuilder.Tests/FodyWeavers.xsd b/QueryBuilder.Tests/FodyWeavers.xsd
new file mode 100644
index 00000000..3f3946e2
--- /dev/null
+++ b/QueryBuilder.Tests/FodyWeavers.xsd
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.
+
+
+
+
+ A comma-separated list of error codes that can be safely ignored in assembly verification.
+
+
+
+
+ 'false' to turn off automatic generation of the XML Schema file.
+
+
+
+
+
\ No newline at end of file
diff --git a/QueryBuilder.Tests/MySqlExecutionTest.cs b/QueryBuilder.Tests/MySqlExecutionTest.cs
index 07df93c8..494fc7ef 100644
--- a/QueryBuilder.Tests/MySqlExecutionTest.cs
+++ b/QueryBuilder.Tests/MySqlExecutionTest.cs
@@ -6,6 +6,8 @@
using System.Linq;
using static SqlKata.Expressions;
using System.Collections.Generic;
+using System.IO;
+using Newtonsoft.Json;
namespace SqlKata.Tests
{
@@ -14,12 +16,12 @@ public class MySqlExecutionTest
[Fact]
public void EmptySelect()
{
-
- var db = DB().Create("Cars", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Brand TEXT NOT NULL",
- "Year INT NOT NULL",
- "Color TEXT NULL",
+ var db = DB().Create("Cars", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Brand TEXT NOT NULL",
+ "Year INT NOT NULL",
+ "Color TEXT NULL",
});
var rows = db.Query("Cars").Get();
@@ -32,11 +34,12 @@ public void EmptySelect()
[Fact]
public void SelectWithLimit()
{
- var db = DB().Create("Cars", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Brand TEXT NOT NULL",
- "Year INT NOT NULL",
- "Color TEXT NULL",
+ var db = DB().Create("Cars", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Brand TEXT NOT NULL",
+ "Year INT NOT NULL",
+ "Color TEXT NULL",
});
db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)");
@@ -51,11 +54,12 @@ public void SelectWithLimit()
[Fact]
public void Count()
{
- var db = DB().Create("Cars", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Brand TEXT NOT NULL",
- "Year INT NOT NULL",
- "Color TEXT NULL",
+ var db = DB().Create("Cars", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Brand TEXT NOT NULL",
+ "Year INT NOT NULL",
+ "Color TEXT NULL",
});
db.Statement("INSERT INTO `Cars`(Brand, Year) VALUES ('Honda', 2020)");
@@ -78,11 +82,12 @@ public void Count()
[Fact]
public void CloneThenCount()
{
- var db = DB().Create("Cars", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Brand TEXT NOT NULL",
- "Year INT NOT NULL",
- "Color TEXT NULL",
+ var db = DB().Create("Cars", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Brand TEXT NOT NULL",
+ "Year INT NOT NULL",
+ "Color TEXT NULL",
});
for (int i = 0; i < 10; i++)
@@ -107,11 +112,12 @@ public void CloneThenCount()
[Fact]
public void QueryWithVariable()
{
- var db = DB().Create("Cars", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Brand TEXT NOT NULL",
- "Year INT NOT NULL",
- "Color TEXT NULL",
+ var db = DB().Create("Cars", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Brand TEXT NOT NULL",
+ "Year INT NOT NULL",
+ "Color TEXT NULL",
});
for (int i = 0; i < 10; i++)
@@ -137,10 +143,11 @@ public void QueryWithVariable()
[Fact]
public void InlineTable()
{
- var db = DB().Create("Transaction", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Amount int NOT NULL",
- "Date DATE NOT NULL",
+ var db = DB().Create("Transaction", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Amount int NOT NULL",
+ "Date DATE NOT NULL",
});
db.Query("Transaction").Insert(new
@@ -151,8 +158,9 @@ public void InlineTable()
var rows = db.Query("Transaction")
- .With("Rates", new[] { "Date", "Rate" }, new object[][] {
- new object[] {"2022-01-01", 0.5},
+ .With("Rates", new[] { "Date", "Rate" }, new object[][]
+ {
+ new object[] { "2022-01-01", 0.5 },
})
.Join("Rates", "Rates.Date", "Transaction.Date")
.SelectRaw("Transaction.Amount * Rates.Rate as AmountConverted")
@@ -167,14 +175,15 @@ public void InlineTable()
[Fact]
public void ExistsShouldReturnFalseForEmptyTable()
{
- var db = DB().Create("Transaction", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Amount int NOT NULL",
- "Date DATE NOT NULL",
+ var db = DB().Create("Transaction", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Amount int NOT NULL",
+ "Date DATE NOT NULL",
});
var exists = db.Query("Transaction").Exists();
- Assert.Equal(false, exists);
+ Assert.False(exists);
db.Drop("Transaction");
}
@@ -182,10 +191,11 @@ public void ExistsShouldReturnFalseForEmptyTable()
[Fact]
public void ExistsShouldReturnTrueForNonEmptyTable()
{
- var db = DB().Create("Transaction", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Amount int NOT NULL",
- "Date DATE NOT NULL",
+ var db = DB().Create("Transaction", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Amount int NOT NULL",
+ "Date DATE NOT NULL",
});
db.Query("Transaction").Insert(new
@@ -195,7 +205,7 @@ public void ExistsShouldReturnTrueForNonEmptyTable()
});
var exists = db.Query("Transaction").Exists();
- Assert.Equal(true, exists);
+ Assert.True(exists);
db.Drop("Transaction");
}
@@ -203,26 +213,28 @@ public void ExistsShouldReturnTrueForNonEmptyTable()
[Fact]
public void BasicSelectFilter()
{
- var db = DB().Create("Transaction", new[] {
- "Id INT PRIMARY KEY AUTO_INCREMENT",
- "Date DATE NOT NULL",
- "Amount int NOT NULL",
+ var db = DB().Create("Transaction", new[]
+ {
+ "Id INT PRIMARY KEY AUTO_INCREMENT",
+ "Date DATE NOT NULL",
+ "Amount int NOT NULL",
});
- var data = new Dictionary {
+ var data = new Dictionary
+ {
// 2020
- {"2020-01-01", 10},
- {"2020-05-01", 20},
-
+ { "2020-01-01", 10 },
+ { "2020-05-01", 20 },
+
// 2021
- {"2021-01-01", 40},
- {"2021-02-01", 10},
- {"2021-04-01", -10},
-
+ { "2021-01-01", 40 },
+ { "2021-02-01", 10 },
+ { "2021-04-01", -10 },
+
// 2022
- {"2022-01-01", 80},
- {"2022-02-01", -30},
- {"2022-05-01", 50},
+ { "2022-01-01", 80 },
+ { "2022-02-01", -30 },
+ { "2022-05-01", 50 },
};
foreach (var row in data)
@@ -235,9 +247,9 @@ public void BasicSelectFilter()
}
var query = db.Query("Transaction")
- .SelectSum("Amount as Total_2020", q => q.WhereDatePart("year", "date", 2020))
- .SelectSum("Amount as Total_2021", q => q.WhereDatePart("year", "date", 2021))
- .SelectSum("Amount as Total_2022", q => q.WhereDatePart("year", "date", 2022))
+ .SelectSum("Amount as Total_2020", q => q.WhereDatePart("year", "date", 2020))
+ .SelectSum("Amount as Total_2021", q => q.WhereDatePart("year", "date", 2021))
+ .SelectSum("Amount as Total_2022", q => q.WhereDatePart("year", "date", 2022))
;
var results = query.Get().ToList();
@@ -250,20 +262,32 @@ public void BasicSelectFilter()
}
QueryFactory DB()
+ {
+ var connection = GetConnectionFromEnv() ?? GetConnectionFromConfig();
+ var db = new QueryFactory(connection, new MySqlCompiler());
+ return db;
+ }
+
+ MySqlConnection GetConnectionFromEnv()
{
var host = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_HOST");
var user = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_USER");
var dbName = System.Environment.GetEnvironmentVariable("SQLKATA_MYSQL_DB");
- var cs = $"server={host};user={user};database={dbName}";
- var connection = new MySqlConnection(cs);
+ if (string.IsNullOrEmpty(host) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(dbName))
+ return null;
- var db = new QueryFactory(connection, new MySqlCompiler());
+ var cs = $"server={host};user={user};database={dbName}";
- return db;
+ return new MySqlConnection(cs);
}
+ MySqlConnection GetConnectionFromConfig()
+ {
+ var settings = File.ReadAllText("config.json");
+ var deserializedSettings = JsonConvert.DeserializeObject(settings);
-
+ return new MySqlConnection(deserializedSettings.ConnectionStrings.MySql.ToString());
+ }
}
-}
\ No newline at end of file
+}
diff --git a/QueryBuilder.Tests/MySqlInitialization.cs b/QueryBuilder.Tests/MySqlInitialization.cs
new file mode 100644
index 00000000..c9ff6826
--- /dev/null
+++ b/QueryBuilder.Tests/MySqlInitialization.cs
@@ -0,0 +1,30 @@
+using DotNet.Testcontainers.Builders;
+using DotNet.Testcontainers.Configurations;
+using DotNet.Testcontainers.Containers;
+
+namespace SqlKata.Tests;
+
+public static class MySqlInitialization
+{
+ public static MySqlTestcontainer DbTestContainer { get; } = GetTestContainer();
+
+ private static MySqlTestcontainer GetTestContainer()
+ {
+ var database = System.Environment.GetEnvironmentVariable("MYSQL_DATABASE") ?? "master";
+ var user = System.Environment.GetEnvironmentVariable("MYSQL_USER") ?? "root";
+ var password = System.Environment.GetEnvironmentVariable("MYSQL_PASSWORD") ?? "1";
+ var port = System.Environment.GetEnvironmentVariable("MYSQL_Port") ?? "13306";
+
+ var testContainer = new TestcontainersBuilder()
+ .WithDatabase(new MySqlTestcontainerConfiguration("mysql/mysql-server:latest")
+ {
+ Database = database,
+ Username = user,
+ Password = password,
+ Port = int.Parse(port)
+ })
+ .Build();
+ testContainer?.StartAsync().Wait();
+ return testContainer;
+ }
+}
diff --git a/QueryBuilder.Tests/ParameterTypeTests.cs b/QueryBuilder.Tests/ParameterTypeTests.cs
index 095a6e53..b1060992 100644
--- a/QueryBuilder.Tests/ParameterTypeTests.cs
+++ b/QueryBuilder.Tests/ParameterTypeTests.cs
@@ -22,9 +22,9 @@ public class ParameterTypeGenerator : IEnumerable