using System;
using System.IO;
namespace XP.Common.Database.Configs
{
///
/// SQLite 配置实体(从 App.config 读取)| SQLite configuration entity (loaded from App.config)
///
public class SqliteConfig
{
///
/// 数据库文件路径 | Database file path
///
public string DbFilePath { get; set; } = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Files", "Data", "XP.db");
///
/// 连接超时时间(秒,默认30)| Connection timeout (seconds, default 30)
///
public int ConnectionTimeout { get; set; } = 30;
///
/// 数据库不存在时是否自动创建(默认true)| Whether to auto-create if not exists (default true)
///
public bool CreateIfNotExists { get; set; } = true;
///
/// 是否启用 WAL 模式(提升并发性能,默认true)| Whether to enable WAL mode (default true)
///
public bool EnableWalMode { get; set; } = true;
///
/// 是否开启日志记录(记录所有SQL操作,默认false)| Whether to enable SQL logging (default false)
///
public bool EnableSqlLogging { get; set; } = false;
///
/// 获取 SQLite 连接字符串 | Get SQLite connection string
///
public string GetConnectionString()
{
var builder = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder
{
DataSource = DbFilePath,
Cache = Microsoft.Data.Sqlite.SqliteCacheMode.Default,
DefaultTimeout = ConnectionTimeout
};
return builder.ToString();
}
}
}