Apq.Cfg.Database
1.2.1
dotnet add package Apq.Cfg.Database --version 1.2.1
NuGet\Install-Package Apq.Cfg.Database -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Apq.Cfg.Database" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Apq.Cfg.Database" Version="1.2.1" />
<PackageReference Include="Apq.Cfg.Database" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Apq.Cfg.Database --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Apq.Cfg.Database, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Apq.Cfg.Database@1.2.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Apq.Cfg.Database&version=1.2.1
#tool nuget:?package=Apq.Cfg.Database&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Apq.Cfg.Database
数据库配置源扩展包,支持多种数据库。
仓库地址:https://gitee.com/apq/Apq.Cfg
📖 在线文档:https://apq-cfg.vercel.app/
依赖
- Apq.Cfg
- SqlSugarCore 5.1.4.210
默认层级
该配置源的默认层级为 CfgSourceLevels.Database (100)。
如果不指定 level 参数,将使用默认层级:
// 使用默认层级 100
.AddDatabase(options => { ... })
// 指定自定义层级
.AddDatabase(options => { ... }, level: 150)
支持的数据库
- SQL Server
- MySQL
- PostgreSQL
- Oracle
- SQLite
用法
using Apq.Cfg;
using Apq.Cfg.Database;
var cfg = new CfgBuilder()
.AddDatabase(options =>
{
options.Provider = "SqlServer";
options.ConnectionString = "Server=localhost;Database=ConfigDb;...";
options.Table = "AppConfig";
options.KeyColumn = "ConfigKey";
options.ValueColumn = "ConfigValue";
}, level: 1, isPrimaryWriter: true)
.Build();
// 使用索引器访问
var connStr = cfg["Database:ConnectionString"];
var timeout = cfg.GetValue<int>("Database:Timeout");
方法签名
public static CfgBuilder AddDatabase(
this CfgBuilder builder,
Action<DatabaseOptions> configure,
int level = CfgSourceLevels.Database, // 默认 100
bool isPrimaryWriter = false)
DatabaseOptions
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Provider |
string? |
- | 数据库提供程序名称 |
ConnectionString |
string? |
- | 数据库连接字符串 |
Table |
string? |
- | 配置表名 |
KeyColumn |
string? |
- | 键列名 |
ValueColumn |
string? |
- | 值列名 |
CommandTimeoutMs |
int |
5000 | 命令超时(毫秒) |
Provider 值
| 值 | 数据库 |
|---|---|
SqlServer |
Microsoft SQL Server |
MySql |
MySQL |
PostgreSQL 或 Postgres |
PostgreSQL |
Oracle |
Oracle |
SQLite |
SQLite |
数据表结构
CREATE TABLE AppConfig (
ConfigKey NVARCHAR(256) PRIMARY KEY,
ConfigValue NVARCHAR(MAX)
);
示例
SQL Server
.AddDatabase(options =>
{
options.Provider = "SqlServer";
options.ConnectionString = "Server=.;Database=MyDb;Trusted_Connection=True;";
options.Table = "AppConfig";
options.KeyColumn = "Key";
options.ValueColumn = "Value";
}, level: 1)
MySQL
.AddDatabase(options =>
{
options.Provider = "MySql";
options.ConnectionString = "Server=localhost;Database=mydb;User=root;Password=...;";
options.Table = "app_config";
options.KeyColumn = "config_key";
options.ValueColumn = "config_value";
}, level: 1)
SQLite
.AddDatabase(options =>
{
options.Provider = "SQLite";
options.ConnectionString = "Data Source=config.db";
options.Table = "Config";
options.KeyColumn = "Key";
options.ValueColumn = "Value";
}, level: 1)
许可证
MIT License
作者
- 邮箱:amwpfiqvy@163.com
仓库
- Gitee:https://gitee.com/apq/Apq.Cfg
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Apq.Cfg (>= 1.2.1)
- SqlSugarCore (>= 5.1.4.211)
-
net8.0
- Apq.Cfg (>= 1.2.1)
- SqlSugarCore (>= 5.1.4.211)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.