Skip to content

Commit

Permalink
Minor release 4.1.* (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
mishael-o authored Dec 1, 2024
2 parents 7b4029b + d45c866 commit 3606e01
Show file tree
Hide file tree
Showing 98 changed files with 1,625 additions and 1,106 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.x
8.x
6.x
- name: Restore dependencies
run: dotnet restore
- name: Build solution
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
run:
working-directory: docs/github-pages
env:
docfx_version: 2.76.0
docfx_version: 2.78.2

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
Expand All @@ -158,21 +158,17 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
dotnet-version: 9.x
- name: Install DocFx
run: dotnet tool update -g docfx --version ${{ env.docfx_version }}
- name: Generate XrefMap
- name: Generate Xrefmap
run: _scripts/generate-xrefmap.sh
- name: Set Google Analytics Id
run: jq --arg gaId "${{ vars.GA_TAG_ID }}" '.build.globalMetadata._googleAnalyticsTagId = $gaId' docfx.json > temp.json && mv temp.json docfx.json
- name: DocFx Metadata
run: docfx metadata docfx.json
- name: Remove Extension Methods
run: _scripts/remove-extn-method.sh
- name: Generate Metadata
run: _scripts/generate-metadata.sh
- name: DocFx Build
run: docfx build docfx.json
- name: Fix Xref Links
run: _scripts/fix-xref-links.sh
- name: Upload Doc Artifacts
uses: actions/upload-pages-artifact@v3
with:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ jobs:
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.x
8.x
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

![Dapper Simple SQL Builder](https://raw.githubusercontent.com/mishael-o/Dapper.SimpleSqlBuilder/main/images/readme-icon.png)

A simple SQL builder for [Dapper](https://github.com/DapperLib/Dapper), using [string interpolation](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated) and a fluent API to build safe, static, and dynamic SQL queries.
A simple and [performant](https://mishael-o.github.io/Dapper.SimpleSqlBuilder/docs/miscellaneous/performance) SQL builder for [Dapper](https://github.com/DapperLib/Dapper), using [string interpolation](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated) and a fluent API to build safe, static, and dynamic SQL queries.

## Getting Started

Expand All @@ -26,5 +26,4 @@ This project is licensed under the MIT License. See the [LICENSE](https://github

## Acknowledgements

- Thanks to [JetBrains](https://www.jetbrains.com) for their open source development [support](https://jb.gg/OpenSourceSupport).
- This project was inspired by these amazing libraries. [Dapper SqlBuilder](https://github.com/DapperLib/Dapper/tree/main/Dapper.SqlBuilder) and [DapperQueryBuilder](https://github.com/Drizin/DapperQueryBuilder).
Refer to the [Acknowledgements](https://mishael-o.github.io/Dapper.SimpleSqlBuilder/docs/miscellaneous/acknowledgements) page for more details.
8 changes: 7 additions & 1 deletion docs/github-pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The documentation is powered by [Docfx](https://dotnet.github.io/docfx/). Docs a

- Install the .NET Core SDK that the project is using.
- Install [Docfx](https://dotnet.github.io/docfx/). The project version can be found in [ci-cd.yml](../../.github/workflows/ci-cd.yml) file.
- Install bash. If you are on Windows, you can use Git Bash.
- Bash. If you are on Windows, you can use Git Bash or WSL.

To build the documentation run the following command in the github-pages folder:

Expand All @@ -17,3 +17,9 @@ _scripts/local-doc-gen.sh
```

The script will perform some clean up, run `docfx` to generate the documentation and then serve it on `http://localhost:8080`. You can then preview the documentation in your browser.

To serve the documentation with a different port, you can pass the port number as an argument to the script:

```bash
_scripts/local-doc-gen.sh 8081
```
23 changes: 0 additions & 23 deletions docs/github-pages/_scripts/fix-xref-links.sh

This file was deleted.

36 changes: 36 additions & 0 deletions docs/github-pages/_scripts/generate-metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

readonly metadata_file_dir="api-docs"

change_netstd2_uids() {
local -r file_dir="$metadata_file_dir/netstd2"

# Loop through all yaml files in the api-docs/netstd2 folder
for file in $(find $file_dir -name "*.yml" -o -name "*.yaml"); do
# Update the uid property to prefix with netstd2.
sed -i "s|uid: |uid: netstd2.|g" $file

# Update text that contains <xref href="Dapper. to <xref href="netstd2.Dapper.
sed -i "s|<xref href=\"Dapper.SimpleSqlBuilder.|<xref href=\"netstd2.Dapper.SimpleSqlBuilder.|g" $file
done
}

remove_extension_methods() {
# Block of text to remove
local -r pattern="- h4: Extension Methods"

# Loop through all yaml files in the api-docs folder
for file in $(find $metadata_file_dir -name "*.yml" -o -name "*.yaml"); do
# Ignore file starts with toc
if [[ $file == *"toc.yml"* ]] || [[ $file == *"toc.yaml"* ]]; then
continue
fi

# Use sed to remove the block of text
sed -i "/$pattern/,+3d" "$file"
done
}

docfx metadata docfx.json
change_netstd2_uids
remove_extension_methods
28 changes: 24 additions & 4 deletions docs/github-pages/_scripts/generate-xrefmap.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
#!/bin/bash

readonly gen_folder="_xref-gen"
readonly file_path="xrefs"

# Copy and update xrefmap files with base URL in href property.
copy_and_update_xrefmap_files() {
local -r files=("core.xrefmap.yml" "netstd2.xrefmap.yml")

for file in "${files[@]}"; do
# Copy file to xrefs folder
cp -f "$gen_folder/$file" "$file_path"

# Add forward slash to href property
sed -i "s|href: |href: /|g" "$file_path/$file"

# Update uid property in netstd2.xrefmap.yml to prefix with netstd2.
if [ "$file" == "netstd2.xrefmap.yml" ]; then
sed -i "s|uid: |uid: netstd2.|g" "$file_path/$file"
fi
done
}

docfx metadata docfx-xref.json
docfx build docfx-xref.json
cp -f _xref-gen/core.xrefmap.yml xrefs
cp -f _xref-gen/netstd2.xrefmap.yml xrefs
rm -r _xref-gen
rm -r api-docs
copy_and_update_xrefmap_files
rm -r $gen_folder
rm -r api-docs
26 changes: 16 additions & 10 deletions docs/github-pages/_scripts/local-doc-gen.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#!/bin/bash

script_dir=$(dirname $0)
set -e

readonly default_port=8080
readonly script_dir=$(dirname $0)

# Read port number from the first argument, use default port if not provided
readonly port=${1:-$default_port}

# Validate port
if ! [[ $port =~ ^[0-9]+$ ]] ; then
echo "Error: Port must be a number" >&2
exit 1
fi

# Remove Existing Documentation
if [ -d "_site" ]; then
Expand All @@ -11,20 +23,14 @@ if [ -d "api-docs" ]; then
rm -r api-docs
fi

# Generate Generate XrefMap
# Generate Xrefmap
$script_dir/generate-xrefmap.sh

# Generate Metadata
docfx metadata docfx.json

# Remove Extension Methods
$script_dir/remove-extn-method.sh
$script_dir/generate-metadata.sh

# Build Documentation
docfx build docfx.json

# Fix Xref Links
$script_dir/fix-xref-links.sh

# Serve Documentation
docfx serve _site
docfx serve _site --port $port
18 changes: 0 additions & 18 deletions docs/github-pages/_scripts/remove-extn-method.sh

This file was deleted.

3 changes: 2 additions & 1 deletion docs/github-pages/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
],
"resource": [
{
"files": ["/images/**"]
"files": ["/images/**"],
"exclude": ["_site/**", "obj/**"]
}
],
"xref": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var builder = SimpleBuilder.Create($"SELECT * FROM User WHERE Id = @id")
.AddParameter("id", value: id, dbType: DbType.Int32);
```

However, the library also provides an extension method, [`DefineParam`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Extensions.SimpleParameterInfoExtensions.yml#Dapper_SimpleSqlBuilder_Extensions_SimpleParameterInfoExtensions_DefineParam__1___0_System_Nullable_System_Data_DbType__System_Nullable_System_Int32__System_Nullable_System_Byte__System_Nullable_System_Byte__), to streamline this process when using interpolated strings.
However, the library also provides an extension method, [`DefineParam`](xref:Dapper.SimpleSqlBuilder.Extensions.SimpleParameterInfoExtensions.DefineParam``1(``0,System.Nullable{System.Data.DbType},System.Nullable{System.Int32},System.Nullable{System.Byte},System.Nullable{System.Byte})), to streamline this process when using interpolated strings.

```csharp
using Dapper.SimpleSqlBuilder.Extensions;
Expand All @@ -29,7 +29,7 @@ var fluentBuilder = SimpleBuilder.CreateFluent()
.Where($"Id = {id.DefineParam(dbType: DbType.Int32)}");
```

The [`DefineParam`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Extensions.SimpleParameterInfoExtensions.yml#Dapper_SimpleSqlBuilder_Extensions_SimpleParameterInfoExtensions_DefineParam__1___0_System_Nullable_System_Data_DbType__System_Nullable_System_Int32__System_Nullable_System_Byte__System_Nullable_System_Byte__) extension method enables you to define the [`DbType`](xref:System.Data.DbType), `Size`, `Precision` and `Scale` of your parameter. This should only be used for parameters passed into the interpolated string, as the <xref:System.Data.ParameterDirection> is always set to `Input` for values in the interpolated string.
The [`DefineParam`](xref:Dapper.SimpleSqlBuilder.Extensions.SimpleParameterInfoExtensions.DefineParam``1(``0,System.Nullable{System.Data.DbType},System.Nullable{System.Int32},System.Nullable{System.Byte},System.Nullable{System.Byte})) extension method enables you to define the [`DbType`](xref:System.Data.DbType), `Size`, `Precision` and `Scale` of your parameter. This should only be used for parameters passed into the interpolated string, as the <xref:System.Data.ParameterDirection> is always set to `Input` for values in the interpolated string.

For cases where you don't want to use the extension method, you can manually create the parameter object:

Expand Down
16 changes: 8 additions & 8 deletions docs/github-pages/docs/builders/builder.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Builder

The [`Builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) is a versatile tool for constructing static, dynamic, complex SQL queries, and stored procedures.
The [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) is a versatile tool for constructing static, dynamic, complex SQL queries, and stored procedures.

The `Create` method on the [`SimpleSqlBuilder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.SimpleBuilder.yml) or [`ISimpleBuilder`](../../api-docs/di/Dapper.SimpleSqlBuilder.DependencyInjection.ISimpleBuilder.yml) (when using [dependency injection](../configuration/dependency-injection.md)) creates a new [`builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) instance. It accepts a SQL query as one of its parameters and returns a new [`builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) instance.
The `Create` method on the [`SimpleSqlBuilder`](xref:Dapper.SimpleSqlBuilder.SimpleBuilder.Create(System.FormattableString,System.String,System.Nullable{System.Boolean})) or [`ISimpleBuilder`](xref:Dapper.SimpleSqlBuilder.DependencyInjection.ISimpleBuilder.Create(System.FormattableString,System.String,System.Nullable{System.Boolean})) (when using [dependency injection](../configuration/dependency-injection.md)) creates a new [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) instance. It accepts a SQL query as one of its parameters and returns a new [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) instance.

The SQL query can be a static string or an interpolated string. The [`builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) parses the SQL query and extracts the parameters from it. The parameters can be accessed via the [`Parameters`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml#Dapper_SimpleSqlBuilder_Builder_Parameters) property, and the generated SQL query can be accessed via the [`Sql`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml#Dapper_SimpleSqlBuilder_Builder_Sql) property.
The SQL query can be a static string or an interpolated string. The [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) parses the SQL query and extracts the parameters from it. The parameters can be accessed via the [`Parameters`](xref:Dapper.SimpleSqlBuilder.Builder.Parameters) property, and the generated SQL query can be accessed via the [`Sql`](xref:Dapper.SimpleSqlBuilder.Builder.Sql) property.

## Static SQL

Expand Down Expand Up @@ -71,7 +71,7 @@ SELECT * FROM User WHERE UserTypeId = @p0 AND Age >= @p1

### Builder Chaining

If you prefer an alternative to interpolated string concatenation, you can use the [`Append`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml#Dapper_SimpleSqlBuilder_Builder_Append_Dapper_SimpleSqlBuilder_AppendInterpolatedStringHandler__), [`AppendIntact`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml#Dapper_SimpleSqlBuilder_Builder_AppendIntact_Dapper_SimpleSqlBuilder_AppendIntactInterpolatedStringHandler__), and [`AppendNewLine`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml#Dapper_SimpleSqlBuilder_Builder_AppendNewLine_Dapper_SimpleSqlBuilder_AppendNewLineInterpolatedStringHandler__) methods, which can be chained.
If you prefer an alternative to interpolated string concatenation, you can use the [`Append`](xref:Dapper.SimpleSqlBuilder.Builder.Append(Dapper.SimpleSqlBuilder.AppendInterpolatedStringHandler@)), [`AppendIntact`](xref:Dapper.SimpleSqlBuilder.Builder.AppendIntact(Dapper.SimpleSqlBuilder.AppendIntactInterpolatedStringHandler@)), and [`AppendNewLine`](xref:Dapper.SimpleSqlBuilder.Builder.AppendNewLine(Dapper.SimpleSqlBuilder.AppendNewLineInterpolatedStringHandler@)) methods, which can be chained.

```csharp
int userTypeId = 4;
Expand Down Expand Up @@ -124,7 +124,7 @@ ORDER BY FirstName, LastName

### Insert

You can perform INSERT operations with the [`builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) as seen in the example below.
You can perform INSERT operations with the [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) as seen in the example below.

```csharp
var user = new User { FirstName = "John", LastName = "Doe", UserTypeId = 4 };
Expand All @@ -146,7 +146,7 @@ VALUES (@p0, @p1, @p2)

### Update

You can perform UPDATE operations with the [`builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) as seen in the example below.
You can perform UPDATE operations with the [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) as seen in the example below.

```csharp
int id = 1;
Expand Down Expand Up @@ -183,7 +183,7 @@ DELETE FROM User WHERE Id = @p0

## Stored Procedures

You can execute stored procedures with the [`builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) as seen in the example below.
You can execute stored procedures with the [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) as seen in the example below.

```csharp
var user = new User { FirstName = "John", LastName = "Doe", UserTypeId = 4 };
Expand All @@ -205,7 +205,7 @@ int result = builder.GetValue<int>("Result");

## Builder Reset

There are scenarios where you may want to reuse the [`builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) without creating a new instance. This can be achieved by calling the [`Reset`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml#Dapper_SimpleSqlBuilder_Builder_Reset) method on the [`builder`](../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml) instance as seen in the example below.
There are scenarios where you may want to reuse the [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) without creating a new instance. This can be achieved by calling the [`Reset`](xref:Dapper.SimpleSqlBuilder.Builder.Reset) method on the [`Builder`](xref:Dapper.SimpleSqlBuilder.Builder) instance as seen in the example below.

```csharp
int id = 1;
Expand Down
4 changes: 4 additions & 0 deletions docs/github-pages/docs/builders/dapper-comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ var users = connection.Query<User>(fluentBuilder.Sql, fluentBuilder.Parameters);
```

---

## Next Steps

- [Performance](../miscellaneous/performance.md)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Delete Builder

You can perform `DELETE` operations with the [`Delete Builder`](../../../api-docs/netcore/Dapper.SimpleSqlBuilder.FluentBuilder.IDeleteBuilderEntry.yml) as seen in the example below.
You can perform `DELETE` operations with the [`Delete Builder`](xref:Dapper.SimpleSqlBuilder.FluentBuilder.IDeleteBuilderEntry) as seen in the example below.

```csharp
int id = 10;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Fluent Builder

The [`Fluent Builder`](../../../api-docs/netcore/Dapper.SimpleSqlBuilder.FluentBuilder.ISimpleFluentBuilder.yml) enables you to build dynamic SQL queries using fluent APIs, offering a more intuitive and readable way to construct complex SQL statements.
The [`Fluent Builder`](xref:Dapper.SimpleSqlBuilder.FluentBuilder.ISimpleFluentBuilder) enables you to build dynamic SQL queries using fluent APIs, offering a more intuitive and readable way to construct complex SQL statements.

The `CreateFluent` method on the [`SimpleSqlBuilder`](../../../api-docs/netcore/Dapper.SimpleSqlBuilder.SimpleBuilder.yml) or [`ISimpleBuilder`](../../../api-docs/di/Dapper.SimpleSqlBuilder.DependencyInjection.ISimpleBuilder.yml) (when using [dependency injection](../../configuration/dependency-injection.md)) creates a new [`fluent builder`](../../../api-docs/netcore/Dapper.SimpleSqlBuilder.FluentBuilder.ISimpleFluentBuilder.yml) instance.
The `CreateFluent` method on the [`SimpleSqlBuilder`](xref:Dapper.SimpleSqlBuilder.SimpleBuilder.CreateFluent(System.String,System.Nullable{System.Boolean},System.Nullable{System.Boolean})) or [`ISimpleBuilder`](xref:Dapper.SimpleSqlBuilder.DependencyInjection.ISimpleBuilder.CreateFluent(System.String,System.Nullable{System.Boolean},System.Nullable{System.Boolean})) (when using [dependency injection](../../configuration/dependency-injection.md)) creates a new [`fluent builder`](xref:Dapper.SimpleSqlBuilder.FluentBuilder.ISimpleFluentBuilder) instance.

Using fluent APIs, you can build `SELECT`, `INSERT`, `UPDATE`, and `DELETE` queries. The [`fluent builder`](../../../api-docs/netcore/Dapper.SimpleSqlBuilder.FluentBuilder.ISimpleFluentBuilder.yml) parses the SQL query and extracts parameters from it. These parameters can be accessed via the [`Parameters`](../../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml#Dapper_SimpleSqlBuilder_Builder_Parameters) property, and the generated SQL query is available through the [`Sql`](../../../api-docs/netcore/Dapper.SimpleSqlBuilder.Builder.yml#Dapper_SimpleSqlBuilder_Builder_Sql) property.
Using fluent APIs, you can build `SELECT`, `INSERT`, `UPDATE`, and `DELETE` queries. The [`Fluent builder`](xref:Dapper.SimpleSqlBuilder.FluentBuilder.ISimpleFluentBuilder) parses the SQL query and extracts parameters from it. These parameters can be accessed via the [`Parameters`](xref:Dapper.SimpleSqlBuilder.Builder.Parameters) property, and the generated SQL query is available through the [`Sql`](xref:Dapper.SimpleSqlBuilder.Builder.Sql) property.

## Fluent Builders

Expand Down
Loading

0 comments on commit 3606e01

Please sign in to comment.