Configuration file
Complete example
{
"JsonFile": "appsettings.json",
"ConnectionExtractionPath": "ConnectionStrings:Default",
"OutputPath": "Data/Generated",
"Namespace": "MyApp.Data",
"IsInternal": false,
"Queries": [
{
"MethodName": "GetAlbumsByArtist",
"SQLQuery": "SELECT AlbumId AS Id, Title FROM albums WHERE ArtistId = @artistId"
},
{
"MethodName": "ArchiveInvoices",
"StoredProcName": "dbo.ArchiveInvoices",
"Parameters": [
{
"Name": "@cutoff",
"Type": "datetime2",
"IsNullable": false
}
]
}
]
}
The Visual Studio configuration manager writes the same settings.
Connection source
One connection source property identifies where the connection string comes from.
{
"RawConnectionString": "Server=.;Database=Music;Trusted_Connection=True"
}
{
"EnvironmentVariable": "MUSIC_DB"
}
{
"JsonFile": "appsettings.json",
"ConnectionExtractionPath": "ConnectionStrings:Default"
}
All connection source examples
Database provider
Without Database, Power Tools infers the provider from the resolved connection string when it can do so without ambiguity.
{
"RawConnectionString": "Data Source=mydatabase"
}
Data Source=mydatabase can describe more than one provider, so this form needs an explicit Database.
{
"Database": "Sqlite",
"RawConnectionString": "Data Source=mydatabase"
}
Accepted provider values include SqlServer, PostgreSql, and Sqlite. Postgres and PostgreSQL are accepted when reading configuration. The writer emits PostgreSql.
Output path
{
"OutputPath": "Data/Generated"
}
The path is project relative. An empty path writes the command file at the project root.
Namespace
{
"OutputPath": "Data/Generated",
"Namespace": "Music.Data.Commands"
}
Without Namespace, the generated namespace is derived from the project namespace and output path.
Accessibility
{
"IsInternal": true
}
internal static class DbCommands
{
}
Query sources
{
"MethodName": "GetAlbums",
"SQLQuery": "SELECT AlbumId AS Id, Title FROM albums"
}
{
"MethodName": "GetAlbums",
"SQLFile": "Sql/GetAlbums.sql"
}
{
"MethodName": "GetAlbums",
"StoredProcName": "dbo.GetAlbums"
}
SQL Server and PostgreSQL support stored procedure entries. SQLite supports SQL queries and SQL files.
Method name
{
"MethodName": "GetAlbumsByArtist",
"SQLQuery": "SELECT AlbumId AS Id, Title FROM albums WHERE ArtistId = @artistId"
}
using DbCommand command = cnn.GetAlbumsByArtist(artistId: 7);
Result set name
{
"MethodName": "GetAlbums",
"ResultSetName": "AlbumRow",
"SQLQuery": "SELECT AlbumId AS Id, Title FROM albums"
}
public partial record AlbumRow(int Id, string Title);
Parameter correction
{
"MethodName": "FindAlbums",
"SQLQuery": "SELECT AlbumId AS Id, Title FROM albums WHERE Title = @title",
"Parameters": [
{
"Name": "@title",
"Type": "nvarchar",
"IsNullable": true
}
]
}
Type and IsNullable replace the discovered values when supplied. Provider type names use the provider database type vocabulary.
SQLite can leave an unresolved parameter as object?. A correction can provide a stronger generated type.
PostgreSQL can retain a native PostgreSQL type name in addition to common DbType metadata.
Generated parameters ยท SQLite parameters
Named configurations
rinkupt.json
rinkupt.Reporting.json
rinkupt.Admin.json