57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace XP.Common.Configs
|
||
{
|
||
/// <summary>
|
||
/// SQLite 配置实体
|
||
/// </summary>
|
||
public class SqliteConfig
|
||
{
|
||
/// <summary>
|
||
/// 数据库文件路径
|
||
/// </summary>
|
||
public string DbFilePath { get; set; } = Path.Combine(
|
||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||
"Files", "Data", "XP.db");
|
||
|
||
/// <summary>
|
||
/// 连接超时时间(秒,默认30)
|
||
/// </summary>
|
||
public int ConnectionTimeout { get; set; } = 30;
|
||
|
||
/// <summary>
|
||
/// 数据库不存在时是否自动创建(默认true)
|
||
/// </summary>
|
||
public bool CreateIfNotExists { get; set; } = true;
|
||
|
||
/// <summary>
|
||
/// 是否启用 WAL 模式(提升并发性能,默认true)
|
||
/// </summary>
|
||
public bool EnableWalMode { get; set; } = true;
|
||
|
||
/// <summary>
|
||
/// 是否开启日志记录(记录所有SQL操作,默认false)
|
||
/// </summary>
|
||
public bool EnableSqlLogging { get; set; } = false;
|
||
|
||
/// <summary>
|
||
/// 获取SQLite连接字符串
|
||
/// </summary>
|
||
public string GetConnectionString()
|
||
{
|
||
var builder = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder
|
||
{
|
||
DataSource = DbFilePath,
|
||
Cache = Microsoft.Data.Sqlite.SqliteCacheMode.Default,
|
||
DefaultTimeout = ConnectionTimeout
|
||
};
|
||
return builder.ToString();
|
||
}
|
||
}
|
||
}
|