8000 sqlc-gen-csharp/docs/03_Usage.md at main Β· giuliov/sqlc-gen-csharp Β· GitHub
[go: up one dir, main page]

Skip to content

Latest commit

Β 

History

History
54 lines (46 loc) Β· 6.24 KB

File metadata and controls

54 lines (46 loc) Β· 6.24 KB

Usage

Options

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 Allows you to override the version of DB 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.

Supported Features

  • βœ… means the feature is fully supported.
  • 🚫 means the database does not support the feature.
  • ❌ means the feature is not supported by the plugin (but could be supported by the database).

Query Annotations

Basic functionality - same for all databases:

  • :one - returns 0...1 records
  • :many - returns 0...n records
  • :exec - DML / DDL that does not return anything
  • :execrows - returns number of affected rows by DML

Advanced functionality - varies between databases:

  • :execlastid - INSERT with returned last inserted id
  • :copyfrom - batch insert, implementation varies greatly

Annotation PostgresSQL MySQL SQLite
:one βœ… βœ… βœ…
:many βœ… βœ… βœ…
:exec βœ… βœ… βœ…
:execrows βœ… βœ… βœ…
:execlastid βœ… βœ… βœ…
:copyfrom βœ… βœ… βœ…

More info can be found in here.

Macro Annotations

  • sqlc.arg - Attach a name to a parameter in a SQL query
  • sqlc.narg - The same as sqlc.arg, but always marks the parameter as nullable
  • sqlc.slice - For databases that do not support passing arrays to the IN operator, generates a dynamic query at runtime with the correct number of parameters
  • sqlc.embed - Embedding allows you to reuse existing model structs in more queries

Annotation PostgresSQL MySQL SQLite
sqlc.arg βœ… βœ… βœ…
sqlc.narg βœ… βœ… βœ…
sqlc.slice 🚫 βœ… βœ…
sqlc.embed βœ… βœ… βœ…

More info can be found in here.

0