sqlc-gen-csharp is a .Net plugin for sqlc.
It leverages the SQLC plugin system to generate type-safe C# code for SQL queries, supporting PostgresSQL, MySQL & SQLite via the corresponding driver or suitable Dapper abstraction.
Option | Possible values | Optional | Info |
---|---|---|---|
overrideDriverVersion | default:2.3.6 for MySqlConnector (mysql)8.0.3 for Npgsql (postgresql)8.0.10 for Microsoft.Data.Sqlite (sqlite)values: The desired driver version |
Yes | Determines the version of the driver to be used. |
targetFramework | default: net8.0 values: netstandard2.0 , netstandard2.1 , net8.0 |
Yes | Determines the target framework for your generated code, meaning the generated code will be compiled to the specified runtime. For more information and help deciding on the right value, refer to the Microsoft .NET Standard documentation. |
generateCsproj | default: true values: false ,true |
Yes | Assists you with the integration of SQLC and csharp by generating a .csproj file. This converts the generated output to a .dll, a project that you can easily incorporate into your build process. |
namespaceName | default: the generated project name | Yes | Allows you to override the namespace name to be different than the project name |
useDapper | default: false values: false ,true |
Yes | Enables Dapper as a thin wrapper for the generated code. For more information, please refer to the Dapper documentation. |
overrideDapperVersion | default:2.1.35 values: The desired Dapper version |
Yes | If useDapper is set to true , this option allows you to override the version of Dapper to be used. |
version: "2"
plugins:
- name: csharp
wasm:
url: https://github.com/DaredevilOSS/sqlc-gen-csharp/releases/download/v0.13.0/sqlc-gen-csharp.wasm
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
sql:
# For PostgresSQL
- schema: schema.sql
queries: queries.sql
engine: postgresql
codegen:
- plugin: csharp
out: PostgresDalGen
# For MySQL
- schema: schema.sql
queries: queries.sql
engine: mysql
codegen:
- plugin: csharp
out: MySqlDalGen
# For SQLite
- schema: schema.sql
queries: queries.sql
engine: sqlite
codegen:
- plugin: csharp
out: SqliteDalGen
All of the examples can be found in here.
Make sure that the following applications are installed and added to your path.
Follow the instructions in each of these:
- Dotnet CLI - Dotnet Installation - use version
.NET 8.0 (latest)
- Buf build - Buf Build
- WASM (follow this guide) - WASM libs
SQLC protobuf are defined in sqlc-dev/sqlc repository. Generating C# code from protocol buffer files:
make protobuf-generate
SQLC utilizes our process / WASM plugin to generate code:
make sqlc-generate-process
make sqlc-generate-wasm
Testing the SQLC generated code via a predefined flow:
make test-process-plugin
make test-wasm-plugin
The release flow in this repo follows the semver conventions, building tag as v[major].[minor].[patch]
.
In order to create a release you need to add [release]
somewhere in your commit message when merging to master.
By default, the release script will bump the patch version. Adding [release]
to your commit message results in a new tag with v[major].[minor].[patch]+1
.
- Bump
minor
version by adding[minor]
to your commit message resulting in a new tag withv[major].[minor]+1.0
- Bump
major
version by adding[major]
to your commit message resulting in a new tag withv[major]+1.0.0
The new created tag will create a draft release with it, in the release there will be the wasm plugin embedded in the release.