From 0b12f6a9db828c39757474d41b9fd2826ee88bcb Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 1 Feb 2025 07:37:16 +0200 Subject: [PATCH 01/15] add ci workflow --- .github/workflows/build.yml | 144 ------------------------------------ .github/workflows/ci.yml | 15 ++++ 2 files changed, 15 insertions(+), 144 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 574626ca..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,144 +0,0 @@ -name: .NET Core -on: - push: - pull_request: - release: - types: - - published -env: - # Stop wasting time caching packages - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - # Disable sending usage data to Microsoft - DOTNET_CLI_TELEMETRY_OPTOUT: true - # Project name to pack and publish - PROJECT_NAME: SqlKata - DOTNET_VERSION: 6.0.202 - # DOTNET_VERSION: 5.0.201 - # DOTNET_VERSION: 2.2.203 - # GitHub Packages Feed settings - GITHUB_FEED: https://nuget.pkg.github.com/sqlkata/ - GITHUB_USER: ahmad-moussawi - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Official NuGet Feed settings - NUGET_FEED: https://api.nuget.org/v3/index.json - NUGET_KEY: ${{ secrets.NUGET_KEY }} - - DB_MYSQL_DATABASE: test_sqlkata - DB_MYSQL_USER: root - DB_MYSQL_PASSWORD: 'root' - DB_MYSQL_HOST: localhost - -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - - name: Checking release - run: | - echo $RELEASE_VERSION - echo ${{ env.RELEASE_VERSION }} - - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} - - - name: Restore - run: dotnet restore - - - name: Build - run: dotnet build -c Release --no-restore - - - name: Start MySql - run: | - sudo /etc/init.d/mysql start - mysqladmin -u ${{ env.DB_MYSQL_USER }} -p${{ env.DB_MYSQL_PASSWORD }} password '' - mysql -e 'CREATE DATABASE ${{ env.DB_MYSQL_DATABASE }};' -u${{ env.DB_MYSQL_USER }} - mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - - - name: Test - run: dotnet test -c Release - env: - SQLKATA_MYSQL_HOST: ${{ env.DB_MYSQL_HOST }} - SQLKATA_MYSQL_USER: ${{ env.DB_MYSQL_USER }} - SQLKATA_MYSQL_DB: ${{ env.DB_MYSQL_DATABASE }} - - - name: Pack QueryBuilder - if: matrix.os == 'ubuntu-latest' - run: dotnet pack -v normal -c Release --no-restore --include-symbols --include-source --version-suffix=$GITHUB_RUN_ID QueryBuilder/QueryBuilder.csproj - - - name: Pack SqlKata.Execution - if: matrix.os == 'ubuntu-latest' - run: dotnet pack -v normal -c Release --no-restore --include-symbols --include-source --version-suffix=$GITHUB_RUN_ID SqlKata.Execution/SqlKata.Execution.csproj - - - name: Upload QueryBuilder Artifact - if: matrix.os == 'ubuntu-latest' - uses: actions/upload-artifact@v2 - with: - name: nupkg - path: ./QueryBuilder/bin/Release/*.nupkg - - - name: Upload SqlKata.Execution Artifact - if: matrix.os == 'ubuntu-latest' - uses: actions/upload-artifact@v2 - with: - name: nupkg - path: ./SqlKata.Execution/bin/Release/*.nupkg - prerelease: - needs: build - if: github.ref == 'refs/heads/develop' - runs-on: ubuntu-latest - steps: - - name: Download Artifact - uses: actions/download-artifact@v1 - with: - name: nupkg - - name: Push to GitHub Feed - run: | - for f in ./nupkg/*.nupkg - do - if [[ ${f} != *".symbols."* ]];then - echo "Uploading package $f" to $GITHUB_FEED - dotnet nuget push $f --api-key=$GITHUB_TOKEN --source=$GITHUB_FEED - fi - # curl -X PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED - done - deploy: - needs: build - if: github.event_name == 'release' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} - - name: Create Release NuGet package (QueryBuilder) - run: | - arrTag=(${GITHUB_REF//\// }) - VERSION="${arrTag[2]}" - echo Version: $VERSION - VERSION="${VERSION//v}" - echo Clean Version: $VERSION - dotnet pack -v normal -c Release --include-symbols --include-source -p:Version=$VERSION -p:PackageVersion=$VERSION -o nupkg QueryBuilder/QueryBuilder.csproj - - name: Create Release NuGet package (SqlKata.Execution) - run: | - arrTag=(${GITHUB_REF//\// }) - VERSION="${arrTag[2]}" - echo Version: $VERSION - VERSION="${VERSION//v}" - echo Clean Version: $VERSION - dotnet pack -v normal -c Release --include-symbols --include-source -p:Version=$VERSION -p:PackageVersion=$VERSION -o nupkg SqlKata.Execution/SqlKata.Execution.csproj - - 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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..52fa32a5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,15 @@ +on: + push: + branches: + - main +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Build + run: dotnet build --configuration Release + - name: Test + run: dotnet test --configuration Release --no-build From 9936d83397d67cbe6f2d74e403b725c864c4b08c Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 1 Feb 2025 08:45:44 +0200 Subject: [PATCH 02/15] remove Program folder --- .github/workflows/ci.yml | 24 +++- Program/Program.cs | 114 ------------------- Program/Program.csproj | 21 ---- QueryBuilder.Tests/MySqlExecutionTest.cs | 4 +- QueryBuilder.Tests/QueryBuilder.Tests.csproj | 2 +- QueryBuilder/Compilers/Compiler.cs | 2 +- QueryBuilder/Compilers/SqlServerCompiler.cs | 2 +- QueryBuilder/QueryBuilder.csproj | 57 ++++------ SqlKata.Execution/SqlKata.Execution.csproj | 68 +++++------ sqlkata.sln | 16 +-- 10 files changed, 83 insertions(+), 227 deletions(-) delete mode 100644 Program/Program.cs delete mode 100644 Program/Program.csproj diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52fa32a5..24ce81e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,14 +2,36 @@ on: push: branches: - main +env: + # Stop wasting time caching packages + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + # Disable sending usage data to Microsoft + DOTNET_CLI_TELEMETRY_OPTOUT: true + + # MYSQL DB + DB_MYSQL_DATABASE: test_sqlkata + DB_MYSQL_USER: root + DB_MYSQL_PASSWORD: "root" + DB_MYSQL_HOST: localhost jobs: build: runs-on: ubuntu-latest timeout-minutes: 15 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Build run: dotnet build --configuration Release + - name: Start MySql + run: | + sudo /etc/init.d/mysql start + mysqladmin -u ${{ env.DB_MYSQL_USER }} -p${{ env.DB_MYSQL_PASSWORD }} password '' + mysql -e 'CREATE DATABASE ${{ env.DB_MYSQL_DATABASE }};' -u${{ env.DB_MYSQL_USER }} + mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} + mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - name: Test run: dotnet test --configuration Release --no-build + env: + SQLKATA_MYSQL_HOST: ${{ env.DB_MYSQL_HOST }} + SQLKATA_MYSQL_USER: ${{ env.DB_MYSQL_USER }} + SQLKATA_MYSQL_DB: ${{ env.DB_MYSQL_DATABASE }} diff --git a/Program/Program.cs b/Program/Program.cs deleted file mode 100644 index 9b4c2845..00000000 --- a/Program/Program.cs +++ /dev/null @@ -1,114 +0,0 @@ -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 Installments { get; set; } = new List(); - } - - 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; - } - - } -} diff --git a/Program/Program.csproj b/Program/Program.csproj deleted file mode 100644 index a5ac20c5..00000000 --- a/Program/Program.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - Exe - false - netcoreapp2.0 - - - diff --git a/QueryBuilder.Tests/MySqlExecutionTest.cs b/QueryBuilder.Tests/MySqlExecutionTest.cs index 07df93c8..6da915d2 100644 --- a/QueryBuilder.Tests/MySqlExecutionTest.cs +++ b/QueryBuilder.Tests/MySqlExecutionTest.cs @@ -174,7 +174,7 @@ public void ExistsShouldReturnFalseForEmptyTable() }); var exists = db.Query("Transaction").Exists(); - Assert.Equal(false, exists); + Assert.False(exists); db.Drop("Transaction"); } @@ -195,7 +195,7 @@ public void ExistsShouldReturnTrueForNonEmptyTable() }); var exists = db.Query("Transaction").Exists(); - Assert.Equal(true, exists); + Assert.True(exists); db.Drop("Transaction"); } diff --git a/QueryBuilder.Tests/QueryBuilder.Tests.csproj b/QueryBuilder.Tests/QueryBuilder.Tests.csproj index 92829215..cb0580b7 100755 --- a/QueryBuilder.Tests/QueryBuilder.Tests.csproj +++ b/QueryBuilder.Tests/QueryBuilder.Tests.csproj @@ -1,6 +1,6 @@ - net6.0 + net8.0 Library false SqlKata.Tests diff --git a/QueryBuilder/Compilers/Compiler.cs b/QueryBuilder/Compilers/Compiler.cs index 6bb208ea..5ac6c080 100644 --- a/QueryBuilder/Compilers/Compiler.cs +++ b/QueryBuilder/Compilers/Compiler.cs @@ -229,7 +229,7 @@ protected virtual SqlResult CompileSelectQuery(Query query) protected virtual SqlResult CompileAdHocQuery(AdHocTableFromClause adHoc) { - var ctx = new SqlResult(); + var ctx = new SqlResult(parameterPlaceholder, EscapeCharacter); var row = "SELECT " + string.Join(", ", adHoc.Columns.Select(col => $"{parameterPlaceholder} AS {Wrap(col)}")); diff --git a/QueryBuilder/Compilers/SqlServerCompiler.cs b/QueryBuilder/Compilers/SqlServerCompiler.cs index a1b7da55..98b488bf 100644 --- a/QueryBuilder/Compilers/SqlServerCompiler.cs +++ b/QueryBuilder/Compilers/SqlServerCompiler.cs @@ -173,7 +173,7 @@ protected override string CompileBasicDateCondition(SqlResult ctx, BasicDateCond protected override SqlResult CompileAdHocQuery(AdHocTableFromClause adHoc) { - var ctx = new SqlResult(); + var ctx = new SqlResult(parameterPlaceholder, EscapeCharacter); var colNames = string.Join(", ", adHoc.Columns.Select(Wrap)); diff --git a/QueryBuilder/QueryBuilder.csproj b/QueryBuilder/QueryBuilder.csproj index 5ce65d65..d30c6789 100755 --- a/QueryBuilder/QueryBuilder.csproj +++ b/QueryBuilder/QueryBuilder.csproj @@ -1,36 +1,25 @@ - - SqlKata The C# Sql Query Builder - A powerful Dynamic Sql Query Builder supporting Sql Server, MySql, PostgreSql, Oracle and Firebird - Ahmad Moussawi - Copyright (c) 2017 Ahmad Moussawi - netstandard2.0 - SqlKata - SqlKata - - - SqlKata - sql;query-builder;dynamic-query - https://github.com/sqlkata/querybuilder - https://github.com/sqlkata/querybuilder - true - MIT - git - https://github.com/sqlkata/querybuilder - - - true - true - CS1591 - - - bin\Debug\netstandard2.0\SqlKata.xml - - - bin\Release\netstandard2.0\SqlKata.xml - - - - - + + SqlKata + A powerful Dynamic Sql Query Builder supporting SQL Server, MySql, PostgreSql, Sqlite, and Oracle + Ahmad Moussawi + Copyright (c) 2017 Ahmad Moussawi + net8.0 + SqlKata + SqlKata.Core + + SqlKata + sql;query-builder;dynamic-query + https://github.com/sqlkata/querybuilder + https://github.com/sqlkata/querybuilder + true + MIT + git + https://github.com/sqlkata/querybuilder + + true + true + CS1591 + + \ No newline at end of file diff --git a/SqlKata.Execution/SqlKata.Execution.csproj b/SqlKata.Execution/SqlKata.Execution.csproj index f6a7ff1e..b81e1815 100644 --- a/SqlKata.Execution/SqlKata.Execution.csproj +++ b/SqlKata.Execution/SqlKata.Execution.csproj @@ -1,38 +1,32 @@ - - SqlKata The C# Sql Query Builder - Adds the execution capabilities for SqlKata - Ahmad Moussawi - Copyright (c) 2017 Ahmad Moussawi - netstandard2.0 - SqlKata - - - SqlKata.Execution - sql;query-builder;dynamic-query - https://github.com/sqlkata/querybuilder - https://github.com/sqlkata/querybuilder - true - MIT - git - https://github.com/sqlkata/querybuilder - - - true - true - CS1591 - - - bin\Release\netstandard2.0\SqlKata.Execution.xml - - - bin\Debug\netstandard2.0\SqlKata.Execution.xml - - - - - - - - - + + SqlKata + Adds the execution capabilities for SqlKata + Ahmad Moussawi + Copyright (c) 2017 Ahmad Moussawi + net8.0 + SqlKata + + SqlKata.Execution + sql;query-builder;dynamic-query + https://github.com/sqlkata/querybuilder + https://github.com/sqlkata/querybuilder + true + MIT + git + https://github.com/sqlkata/querybuilder + + true + true + CS1591 + + + + + + + + + \ No newline at end of file diff --git a/sqlkata.sln b/sqlkata.sln index 957e67a0..ef91408a 100644 --- a/sqlkata.sln +++ b/sqlkata.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26124.0 @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QueryBuilder.Tests", "Query EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlKata.Execution", "SqlKata.Execution\SqlKata.Execution.csproj", "{B6DF0569-6040-4EAF-A38B-E4DEB8DC76E0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Program", "Program\Program.csproj", "{5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{86D00525-7428-4DD7-914D-0A10D5C53EDE}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig @@ -62,18 +60,6 @@ Global {B6DF0569-6040-4EAF-A38B-E4DEB8DC76E0}.Release|x64.Build.0 = Release|Any CPU {B6DF0569-6040-4EAF-A38B-E4DEB8DC76E0}.Release|x86.ActiveCfg = Release|Any CPU {B6DF0569-6040-4EAF-A38B-E4DEB8DC76E0}.Release|x86.Build.0 = Release|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Debug|x64.ActiveCfg = Debug|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Debug|x64.Build.0 = Debug|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Debug|x86.ActiveCfg = Debug|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Debug|x86.Build.0 = Debug|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Release|Any CPU.Build.0 = Release|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Release|x64.ActiveCfg = Release|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Release|x64.Build.0 = Release|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Release|x86.ActiveCfg = Release|Any CPU - {5DEA7DBC-5B8A-44A9-A070-55E95881A4CF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From f6e9516c0c7d7698aaccf07eceb5f409c515790a Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 1 Feb 2025 09:45:19 +0200 Subject: [PATCH 03/15] chore: add release pipeline --- .github/workflows/release.yml | 52 ++++++++++++++++++++ QueryBuilder.Tests/QueryBuilder.Tests.csproj | 39 ++++++++------- 2 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..16b5855b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,52 @@ +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" +env: + # Stop wasting time caching packages + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + # Disable sending usage data to Microsoft + DOTNET_CLI_TELEMETRY_OPTOUT: true + + # MYSQL DB + DB_MYSQL_DATABASE: test_sqlkata + DB_MYSQL_USER: root + DB_MYSQL_PASSWORD: "root" + DB_MYSQL_HOST: localhost +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Verify commit exists in origin/main + run: git branch --remote --contains | grep origin/main + # - name: Extract release notes + # run: | + # git log --pretty=format:'%d %s' ${GITHUB_REF} | perl -pe 's| \(.*tag: v(\d+.\d+.\d+(-preview\d{3})?)(, .*?)*\)|\n## \1\n|g' > RELEASE-NOTES + - name: Set VERSION variable from tag + run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV + - name: Build + run: dotnet build --configuration Release /p:Version=${VERSION} + - name: Start MySql + run: | + sudo /etc/init.d/mysql start + mysqladmin -u ${{ env.DB_MYSQL_USER }} -p${{ env.DB_MYSQL_PASSWORD }} password '' + mysql -e 'CREATE DATABASE ${{ env.DB_MYSQL_DATABASE }};' -u${{ env.DB_MYSQL_USER }} + mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} + mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} + - name: Test + run: dotnet test --configuration Release /p:Version=${VERSION} --no-build + env: + SQLKATA_MYSQL_HOST: ${{ env.DB_MYSQL_HOST }} + SQLKATA_MYSQL_USER: ${{ env.DB_MYSQL_USER }} + SQLKATA_MYSQL_DB: ${{ env.DB_MYSQL_DATABASE }} + - name: Pack + run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output . + - name: Push + run: dotnet nuget push *.${VERSION}.nupkg --source https://nuget.pkg.github.com/sqlkata/index.json --api-key ${GITHUB_TOKEN} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/QueryBuilder.Tests/QueryBuilder.Tests.csproj b/QueryBuilder.Tests/QueryBuilder.Tests.csproj index cb0580b7..78e5f4de 100755 --- a/QueryBuilder.Tests/QueryBuilder.Tests.csproj +++ b/QueryBuilder.Tests/QueryBuilder.Tests.csproj @@ -1,19 +1,24 @@ - - net8.0 - Library - false - SqlKata.Tests - - - - - - - - - - - - + + net8.0 + Library + false + SqlKata.Tests + + + + + + + + + + + + \ No newline at end of file From 82ea97e10b75a5e67a16826e297f8b352bc25483 Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 1 Feb 2025 10:13:28 +0200 Subject: [PATCH 04/15] chore: update release ci to add nuget source --- .github/workflows/release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 16b5855b..ad7b033d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -46,7 +46,11 @@ jobs: SQLKATA_MYSQL_DB: ${{ env.DB_MYSQL_DATABASE }} - name: Pack run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output . - - name: Push - run: dotnet nuget push *.${VERSION}.nupkg --source https://nuget.pkg.github.com/sqlkata/index.json --api-key ${GITHUB_TOKEN} + - name: Push to Github Packages + run: dotnet nuget push *.${VERSION}.nupkg --skip-duplicate --source https://nuget.pkg.github.com/sqlkata/index.json --api-key ${GITHUB_TOKEN} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Push to Nuget + run: dotnet nuget push *.${VERSION}.nupkg --skip-duplicate --source https://api.nuget.org/v3/index.json --api-key ${NUGET_KEY} + env: + NUGET_KEY: ${{ secrets.NUGET_KEY }} From d20e930c8a4bd801225f96302917432fa4b3b3ea Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sun, 2 Feb 2025 23:15:58 +0200 Subject: [PATCH 05/15] chore: update readme --- README.md | 62 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index d07b1216..b911d738 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- SqlKata Query Builder + SqlKata Query Builder

@@ -9,31 +9,24 @@ Twitter

-

-Follow and Upvote SqlKata on Product Hunt to encourage the development of this project + Follow and Upvote SqlKata on Product Hunt to encourage the development of this project

-SqlKata - Dynamic Sql query builder for dotnet | Product Hunt + SqlKata - Dynamic Sql query builder for dotnet | Product Hunt

+https://private-user-images.githubusercontent.com/2517523/408899411-1f9ff89b-ed17-4d02-ae2f-afc1c66a5932.mp4 -![Quick Demo](https://i.imgur.com/jOWD4vk.gif) - - -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. +## 🚀 Introduction -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 Query Builder is a powerful SQL query builder written in C#. It is secure, framework-agnostic, and inspired by top query builders like Laravel Query Builder and Knex. -The SqlKata.Execution package provides the ability to submit the queries to the database, using [Dapper](https://github.com/StackExchange/Dapper) under the covers. - -Checkout the full documentation on [https://sqlkata.com](https://sqlkata.com) +### ✨ Key Features +- **Expressive API**: Clean and intuitive syntax similar to SQL. +- **Database Agnostic**: Work with multiple databases using a unified API. +- **Complex Queries**: Supports nested conditions, subqueries, conditional statements, and more. +- **Execution Support**: Use the SqlKata.Execution package to execute queries with Dapper. ## Installation @@ -42,7 +35,6 @@ $ dotnet add package SqlKata $ dotnet add package SqlKata.Execution # (optional) If you want the execution support ``` - ## Quick Examples ### Setup Connection @@ -50,40 +42,43 @@ $ dotnet add package SqlKata.Execution # (optional) If you want the execution su ```cs var connection = new SqlConnection("..."); var compiler = new SqlCompiler(); - -var db = new QueryFactory(connection, compiler) +var db = new QueryFactory(connection, compiler); ``` - > `QueryFactory` is provided by the SqlKata.Execution package. ### Retrieve all records + ```cs var books = db.Query("Books").Get(); ``` ### Retrieve published books only + ```cs var books = db.Query("Books").WhereTrue("IsPublished").Get(); ``` ### Retrieve one book + ```cs var introToSql = db.Query("Books").Where("Id", 145).Where("Lang", "en").First(); ``` ### Retrieve recent books: last 10 + ```cs var recent = db.Query("Books").OrderByDesc("PublishedAt").Limit(10).Get(); ``` ### Include Author information + ```cs var books = db.Query("Books") - .Include(db.Query("Authors")) // Assumes that the Books table have a `AuthorId` column + .Include(db.Query("Authors")) // Assumes that the Books table has an `AuthorId` column .Get(); ``` -This will include the property "Author" on each "Book" +This will include the property "Author" on each "Book": ```jsonc [{ "Id": 1, @@ -111,6 +106,7 @@ foreach(var book in books) ``` ### Conditional queries + ```cs var isFriday = DateTime.Today.DayOfWeek == DayOfWeek.Friday; @@ -159,16 +155,22 @@ 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 newsletters 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](https://sqlkata.com). ### 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. + +It's impossible to support all available database vendors, which is why we focus on the major ones. We encourage you to create your own compiler for your database. ### Do you accept new compilers? -Unfortunately, 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 that this would 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 SqlKata - Dynamic Sql query builder for dotnet | Product Hunt -- You can also donate to support the project financially on open collection. + +- ⭐ Star the project here on GitHub, and share it with your friends. +- 🐱‍💻 Follow and upvote it on Product Hunt: + SqlKata - Dynamic Sql query builder for dotnet | Product Hunt +- 💰 You can also donate to support the project financially on open collection. From 8e687c299152cf25015d0839e0b8ddb63c95f241 Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Fri, 26 Sep 2025 23:15:25 +0300 Subject: [PATCH 06/15] Add GitHub Actions workflow for .NET build and test This workflow automates the build and test process for a .NET project on push and pull request events to the main branch. --- .github/workflows/dotnet.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 00000000..217f7cbe --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,28 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: .NET + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal From 513e800171099dc3d2b76dd88ee0459f06d15527 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 26 Sep 2025 23:32:40 +0300 Subject: [PATCH 07/15] run ci on PRs --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24ce81e8..8b63ed91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,8 @@ on: push: - branches: - - main + branches: ["main"] + pull_request: + branches: ["main"] env: # Stop wasting time caching packages DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true From 52f81c38c470725e923e68e8ee2433a38bf2a5b0 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Fri, 26 Sep 2025 23:38:13 +0300 Subject: [PATCH 08/15] reorganize ci.yml --- .github/workflows/ci.yml | 13 +++++++++---- .github/workflows/dotnet.yml | 28 ---------------------------- 2 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b63ed91..3d3a4b8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,10 +19,15 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 steps: - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Restore dependencies + run: dotnet restore - name: Build - run: dotnet build --configuration Release + run: dotnet build --no-restore - name: Start MySql run: | sudo /etc/init.d/mysql start @@ -31,7 +36,7 @@ jobs: mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - name: Test - run: dotnet test --configuration Release --no-build + run: dotnet test --no-build --verbosity normal env: SQLKATA_MYSQL_HOST: ${{ env.DB_MYSQL_HOST }} SQLKATA_MYSQL_USER: ${{ env.DB_MYSQL_USER }} diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml deleted file mode 100644 index 217f7cbe..00000000 --- a/.github/workflows/dotnet.yml +++ /dev/null @@ -1,28 +0,0 @@ -# This workflow will build a .NET project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net - -name: .NET - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - name: Restore dependencies - run: dotnet restore - - name: Build - run: dotnet build --no-restore - - name: Test - run: dotnet test --no-build --verbosity normal From c08a66fd2f6fd1582d1b7ced933d8efa48f47c13 Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 27 Sep 2025 12:26:17 +0300 Subject: [PATCH 09/15] Add MS SQL configuration to CI workflow --- .github/workflows/ci.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d3a4b8c..42195987 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,10 +10,16 @@ env: DOTNET_CLI_TELEMETRY_OPTOUT: true # MYSQL DB - DB_MYSQL_DATABASE: test_sqlkata + DB_MYSQL_HOST: localhost DB_MYSQL_USER: root DB_MYSQL_PASSWORD: "root" - DB_MYSQL_HOST: localhost + DB_MYSQL_DATABASE: test_sqlkata + + # MS SQL + DB_MSSQL_HOST: localhost + DB_MSSQL_USER: admin + DB_MSSQL_PASSWORD: secret + DB_MSSQL_DATABASE: test_sqlkata jobs: build: runs-on: ubuntu-latest @@ -35,7 +41,18 @@ jobs: mysql -e 'CREATE DATABASE ${{ env.DB_MYSQL_DATABASE }};' -u${{ env.DB_MYSQL_USER }} mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - - name: Test + + - name: Start MS SQL + uses: potatoqualitee/mssqlsuite@v1.11 + with: + install: sqlengine, sqlclient + admin-username: ${{ env.DB_MSSQL_USER }} + sa-password: ${{ env.DB_MSSQL_PASSWORD }} + + - name: Test connection with custom admin user + run: sqlcmd -S ${{ env.DB_MSSQL_HOST }} -U ${{ env.DB_MSSQL_USER }} -P ${{ env.DB_MSSQL_PASSWORD }} -d ${{ env.DB_MSSQL_DATABASE }} -Q "SELECT @@version;" -C + + - name: Run Test run: dotnet test --no-build --verbosity normal env: SQLKATA_MYSQL_HOST: ${{ env.DB_MYSQL_HOST }} From 32b39481cdd0440dfa7e6ac6d04bb51976fc9455 Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 27 Sep 2025 12:36:22 +0300 Subject: [PATCH 10/15] Change MSSQL user from 'admin' to 'sa' --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42195987..2d5f00c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ env: # MS SQL DB_MSSQL_HOST: localhost - DB_MSSQL_USER: admin + DB_MSSQL_USER: sa DB_MSSQL_PASSWORD: secret DB_MSSQL_DATABASE: test_sqlkata jobs: @@ -49,8 +49,8 @@ jobs: admin-username: ${{ env.DB_MSSQL_USER }} sa-password: ${{ env.DB_MSSQL_PASSWORD }} - - name: Test connection with custom admin user - run: sqlcmd -S ${{ env.DB_MSSQL_HOST }} -U ${{ env.DB_MSSQL_USER }} -P ${{ env.DB_MSSQL_PASSWORD }} -d ${{ env.DB_MSSQL_DATABASE }} -Q "SELECT @@version;" -C + - name: Test connection with custom sa user + run: sqlcmd -S ${{ env.DB_MSSQL_HOST }} -U ${{ env.DB_MSSQL_USER }} -P ${{ env.DB_MSSQL_PASSWORD }} -d tempdb -Q "SELECT @@version;" -C - name: Run Test run: dotnet test --no-build --verbosity normal From 760367465ac9c590d2b140b60e75defd230f68be Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 27 Sep 2025 15:06:23 +0300 Subject: [PATCH 11/15] Replace MS SQL setup with installation commands --- .github/workflows/ci.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d5f00c8..987ba9a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,15 +42,18 @@ jobs: mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - - name: Start MS SQL - uses: potatoqualitee/mssqlsuite@v1.11 - with: - install: sqlengine, sqlclient - admin-username: ${{ env.DB_MSSQL_USER }} - sa-password: ${{ env.DB_MSSQL_PASSWORD }} + - name: Install SQL Server + run: | + sudo su + curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - + add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/mssql-server-2022.list)" + apt-get update + ACCEPT_EULA=Y apt-get install -y mssql-server mssql-tools unixodbc-dev + /opt/mssql/bin/mssql-conf setup accept-eula --edition Developer --sapassword "${{ env.DB_MSSQL_PASSWORD }}" - - name: Test connection with custom sa user - run: sqlcmd -S ${{ env.DB_MSSQL_HOST }} -U ${{ env.DB_MSSQL_USER }} -P ${{ env.DB_MSSQL_PASSWORD }} -d tempdb -Q "SELECT @@version;" -C + - name: Run SQL commands (example) + run: | + sqlcmd -S localhost -U SA -P "${{ env.DB_MSSQL_PASSWORD }}" -Q "SELECT @@VERSION" - name: Run Test run: dotnet test --no-build --verbosity normal From 5e677e7638cd4ae7adb4411c4460ae505d4020f9 Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 27 Sep 2025 15:16:15 +0300 Subject: [PATCH 12/15] Configure SQL Server service in CI workflow Added SQL Server service container and updated installation steps for sqlcmd tools. --- .github/workflows/ci.yml | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 987ba9a5..74876232 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,28 @@ env: DB_MSSQL_USER: sa DB_MSSQL_PASSWORD: secret DB_MSSQL_DATABASE: test_sqlkata + + jobs: build: runs-on: ubuntu-latest + + # Define a service container for SQL Server + services: + mssql: + image: mcr.microsoft.com/mssql/server:2022-latest + env: + SA_PASSWORD: ${{ env.DB_MSSQL_PASSWORD }} # Use a GitHub secret for the password + ACCEPT_EULA: 'Y' + ports: + - 1433:1433 # Map the port + # Wait for the service to be ready before running steps + options: >- + --health-cmd "sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q 'SELECT 1'" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + timeout-minutes: 15 steps: - uses: actions/checkout@v4 @@ -42,18 +61,19 @@ jobs: mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - - name: Install SQL Server + - name: Install sqlcmd tools run: | - sudo su - curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - - add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/mssql-server-2022.list)" - apt-get update - ACCEPT_EULA=Y apt-get install -y mssql-server mssql-tools unixodbc-dev - /opt/mssql/bin/mssql-conf setup accept-eula --edition Developer --sapassword "${{ env.DB_MSSQL_PASSWORD }}" + sudo apt-get update + sudo apt-get install -y curl apt-transport-https gnupg + curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc + echo "deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/$(lsb_release -rs)/prod $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/microsoft.list + sudo apt-get update + sudo apt-get install -y mssql-tools unixodbc-dev + echo '/opt/mssql-tools/bin' | sudo tee -a $GITHUB_PATH - name: Run SQL commands (example) - run: | - sqlcmd -S localhost -U SA -P "${{ env.DB_MSSQL_PASSWORD }}" -Q "SELECT @@VERSION" + run: | + sqlcmd -S localhost,1433 -U SA -P "${{ env.DB_MSSQL_PASSWORD }}" -Q "SELECT @@VERSION" - name: Run Test run: dotnet test --no-build --verbosity normal From 758e9f3036bef3d10adfbc5ec61ae9614e379f66 Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 27 Sep 2025 15:20:06 +0300 Subject: [PATCH 13/15] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74876232..137c4a1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ env: # MS SQL DB_MSSQL_HOST: localhost DB_MSSQL_USER: sa - DB_MSSQL_PASSWORD: secret + DB_MSSQL_PASSWORD: ZLWFwFhySXbX DB_MSSQL_DATABASE: test_sqlkata From b31ead9d6ced8ccd740360bbd046a5b86f9257a3 Mon Sep 17 00:00:00 2001 From: Ahmad Moussawi Date: Sat, 27 Sep 2025 15:22:22 +0300 Subject: [PATCH 14/15] Update ci.yml --- .github/workflows/ci.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 137c4a1c..976f6ae7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,28 +10,28 @@ env: DOTNET_CLI_TELEMETRY_OPTOUT: true # MYSQL DB - DB_MYSQL_HOST: localhost + DB_MYSQL_HOST: localhost DB_MYSQL_USER: root DB_MYSQL_PASSWORD: "root" - DB_MYSQL_DATABASE: test_sqlkata + DB_MYSQL_DATABASE: test_sqlkata # MS SQL - DB_MSSQL_HOST: localhost + DB_MSSQL_HOST: localhost DB_MSSQL_USER: sa - DB_MSSQL_PASSWORD: ZLWFwFhySXbX + DB_MSSQL_PASSWORD: "cQKY1w4?8+4]" DB_MSSQL_DATABASE: test_sqlkata jobs: build: runs-on: ubuntu-latest - + # Define a service container for SQL Server services: mssql: image: mcr.microsoft.com/mssql/server:2022-latest env: - SA_PASSWORD: ${{ env.DB_MSSQL_PASSWORD }} # Use a GitHub secret for the password + SA_PASSWORD: "${{ env.DB_MSSQL_PASSWORD }}" # Use a GitHub secret for the password ACCEPT_EULA: 'Y' ports: - 1433:1433 # Map the port @@ -40,9 +40,9 @@ jobs: --health-cmd "sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q 'SELECT 1'" --health-interval 10s --health-timeout 5s - --health-retries 10 - - timeout-minutes: 15 + --health-retries 20 + + timeout-minutes: 20 steps: - uses: actions/checkout@v4 - name: Setup .NET @@ -60,7 +60,7 @@ jobs: mysql -e 'CREATE DATABASE ${{ env.DB_MYSQL_DATABASE }};' -u${{ env.DB_MYSQL_USER }} mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - + - name: Install sqlcmd tools run: | sudo apt-get update @@ -72,9 +72,9 @@ jobs: echo '/opt/mssql-tools/bin' | sudo tee -a $GITHUB_PATH - name: Run SQL commands (example) - run: | + run: | sqlcmd -S localhost,1433 -U SA -P "${{ env.DB_MSSQL_PASSWORD }}" -Q "SELECT @@VERSION" - + - name: Run Test run: dotnet test --no-build --verbosity normal env: From 981f444c9377b635589f92863602411b44b754e4 Mon Sep 17 00:00:00 2001 From: Ahmad Date: Sat, 27 Sep 2025 17:09:17 +0300 Subject: [PATCH 15/15] use secret password for db --- .github/workflows/ci.yml | 71 ++++++++++---------- QueryBuilder.Tests/MySqlExecutionTest.cs | 15 +++-- QueryBuilder.Tests/QueryBuilder.Tests.csproj | 4 +- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 976f6ae7..4603b547 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,37 +10,33 @@ env: DOTNET_CLI_TELEMETRY_OPTOUT: true # MYSQL DB - DB_MYSQL_HOST: localhost - DB_MYSQL_USER: root - DB_MYSQL_PASSWORD: "root" DB_MYSQL_DATABASE: test_sqlkata # MS SQL DB_MSSQL_HOST: localhost DB_MSSQL_USER: sa - DB_MSSQL_PASSWORD: "cQKY1w4?8+4]" DB_MSSQL_DATABASE: test_sqlkata jobs: build: runs-on: ubuntu-latest - # Define a service container for SQL Server - services: - mssql: - image: mcr.microsoft.com/mssql/server:2022-latest - env: - SA_PASSWORD: "${{ env.DB_MSSQL_PASSWORD }}" # Use a GitHub secret for the password - ACCEPT_EULA: 'Y' - ports: - - 1433:1433 # Map the port - # Wait for the service to be ready before running steps - options: >- - --health-cmd "sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q 'SELECT 1'" - --health-interval 10s - --health-timeout 5s - --health-retries 20 + # services: + # mssql: + # image: mcr.microsoft.com/mssql/server:2022-latest + # env: + # MSSQL_SA_PASSWORD: "${{ secrets.MSSQL_SA_PASSWORD }}" + # ACCEPT_EULA: 'Y' + # MSSQL_PID: Express + # ports: + # - 1433:1433 # Map the port + # # Wait for the service to be ready before running steps + # options: >- + # --health-cmd "sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q 'SELECT 1'" + # --health-interval 10s + # --health-timeout 5s + # --health-retries 20 timeout-minutes: 20 steps: @@ -56,28 +52,29 @@ jobs: - name: Start MySql run: | sudo /etc/init.d/mysql start - mysqladmin -u ${{ env.DB_MYSQL_USER }} -p${{ env.DB_MYSQL_PASSWORD }} password '' - mysql -e 'CREATE DATABASE ${{ env.DB_MYSQL_DATABASE }};' -u${{ env.DB_MYSQL_USER }} - mysql -e 'CREATE TABLE cars(id int primary key auto_increment);' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} - mysql -e 'SHOW TABLES;' -u${{ env.DB_MYSQL_USER }} ${{ env.DB_MYSQL_DATABASE }} + mysqladmin -u root -proot password "${{ secrets.MYSQL_ROOT_PASSWORD }}" + mysql -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" -e 'CREATE DATABASE ${{ env.DB_MYSQL_DATABASE }};' + mysql -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" -e 'CREATE TABLE cars(id int primary key auto_increment);' ${{ env.DB_MYSQL_DATABASE }} + mysql -uroot -p"${{ secrets.MYSQL_ROOT_PASSWORD }}" -e 'SHOW TABLES;' ${{ env.DB_MYSQL_DATABASE }} - - name: Install sqlcmd tools - run: | - sudo apt-get update - sudo apt-get install -y curl apt-transport-https gnupg - curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc - echo "deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/$(lsb_release -rs)/prod $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/microsoft.list - sudo apt-get update - sudo apt-get install -y mssql-tools unixodbc-dev - echo '/opt/mssql-tools/bin' | sudo tee -a $GITHUB_PATH + # - name: Install sqlcmd tools + # run: | + # sudo apt-get update + # sudo apt-get install -y curl apt-transport-https gnupg + # curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc + # echo "deb [arch=amd64,arm64,armhf] https://packages.microsoft.com/ubuntu/$(lsb_release -rs)/prod $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/microsoft.list + # sudo apt-get update + # sudo apt-get install -y mssql-tools unixodbc-dev + # echo '/opt/mssql-tools/bin' | sudo tee -a $GITHUB_PATH - - name: Run SQL commands (example) - run: | - sqlcmd -S localhost,1433 -U SA -P "${{ env.DB_MSSQL_PASSWORD }}" -Q "SELECT @@VERSION" + # - name: Run SQL commands (example) + # run: | + # sqlcmd -S localhost,1433 -U SA -P "${{ secrets.MSSQL_SA_PASSWORD }}" -Q "SELECT @@VERSION" - name: Run Test run: dotnet test --no-build --verbosity normal env: - SQLKATA_MYSQL_HOST: ${{ env.DB_MYSQL_HOST }} - SQLKATA_MYSQL_USER: ${{ env.DB_MYSQL_USER }} + SQLKATA_MYSQL_HOST: localhost + SQLKATA_MYSQL_USER: root SQLKATA_MYSQL_DB: ${{ env.DB_MYSQL_DATABASE }} + SQLKATA_MYSQL_PASSWORD: "${{ secrets.MYSQL_ROOT_PASSWORD }}" diff --git a/QueryBuilder.Tests/MySqlExecutionTest.cs b/QueryBuilder.Tests/MySqlExecutionTest.cs index 6da915d2..259dcccf 100644 --- a/QueryBuilder.Tests/MySqlExecutionTest.cs +++ b/QueryBuilder.Tests/MySqlExecutionTest.cs @@ -213,12 +213,12 @@ public void BasicSelectFilter() // 2020 {"2020-01-01", 10}, {"2020-05-01", 20}, - + // 2021 {"2021-01-01", 40}, {"2021-02-01", 10}, {"2021-04-01", -10}, - + // 2022 {"2022-01-01", 80}, {"2022-02-01", -30}, @@ -251,10 +251,11 @@ public void BasicSelectFilter() QueryFactory DB() { - 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 host = Environment.GetEnvironmentVariable("SQLKATA_MYSQL_HOST"); + var user = Environment.GetEnvironmentVariable("SQLKATA_MYSQL_USER"); + var dbName = Environment.GetEnvironmentVariable("SQLKATA_MYSQL_DB"); + var dbPass = Environment.GetEnvironmentVariable("SQLKATA_MYSQL_PASSWORD"); + var cs = $"Server={host};User={user};Database={dbName};Password={dbPass}"; var connection = new MySqlConnection(cs); @@ -266,4 +267,4 @@ QueryFactory DB() } -} \ No newline at end of file +} diff --git a/QueryBuilder.Tests/QueryBuilder.Tests.csproj b/QueryBuilder.Tests/QueryBuilder.Tests.csproj index 78e5f4de..ae34193c 100755 --- a/QueryBuilder.Tests/QueryBuilder.Tests.csproj +++ b/QueryBuilder.Tests/QueryBuilder.Tests.csproj @@ -11,7 +11,7 @@ + Version="9.4.0" /> - \ No newline at end of file +