Hi.Ltd.Sqlite 2026.10.16.1156

dotnet add package Hi.Ltd.Sqlite --version 2026.10.16.1156
                    
NuGet\Install-Package Hi.Ltd.Sqlite -Version 2026.10.16.1156
                    
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="Hi.Ltd.Sqlite" Version="2026.10.16.1156" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hi.Ltd.Sqlite" Version="2026.10.16.1156" />
                    
Directory.Packages.props
<PackageReference Include="Hi.Ltd.Sqlite" />
                    
Project file
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 Hi.Ltd.Sqlite --version 2026.10.16.1156
                    
#r "nuget: Hi.Ltd.Sqlite, 2026.10.16.1156"
                    
#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 Hi.Ltd.Sqlite@2026.10.16.1156
                    
#: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=Hi.Ltd.Sqlite&version=2026.10.16.1156
                    
Install as a Cake Addin
#tool nuget:?package=Hi.Ltd.Sqlite&version=2026.10.16.1156
                    
Install as a Cake Tool

Hi.Ltd.Sqlite

面向本地文件的 SQLite 访问库:属性映射 CRUD、Schema 补齐、备份/还原/静默、完整性守卫、FTS5。公开 API 统一返回 Hi.Ltd 的 Result / Result<T>。

依赖

  • Hi.Ltd
  • Microsoft.Data.Sqlite.Core(消费端需自行提供原生 SQLite,例如 SQLitePCLRaw.bundle_e_sqlite3 或完整 Microsoft.Data.Sqlite)

目标框架:net462 / net481 / net6.0 / net8.0。

快速开始

using Hi.Ltd.SQLite;
using Hi.Ltd.SQLite.Attributes;

[Table("Demo"), Auto]
public class Demo
{
    [Key]
    public int Id { get; set; }

    [MaxLength(200), Required]
    public string Name { get; set; }
}

var sqlite = SQLiteEntities.CreateNew();
sqlite.Path = @"D:\data";
sqlite.Database = "app.db";
sqlite.ConcurrencyOptions.Pooling = false; // 退出要拷贝/哈希时建议关闭池

Factory.SetSQLite(sqlite);
var init = Factory.InitialSQLite(sqlite); // 建库/建表/补列
if (!init.Succeeded) { /* 处理错误 */ }

var insert = Factory.Insert(new Demo { Name = "a" });
var list = Factory.Query<Demo>();
var clear = Factory.Truncate<Demo>();

也可不经 Factory,直接调用 ISQLite 上的 InsertTable / UpdateTable / DeleteTable / InquireTable / TruncateTable 等。

连接与并发

SQLiteConcurrencyOptions:

属性 默认 说明
EnableWalMode true 打开后 PRAGMA journal_mode=WAL
BusyTimeoutMs 3000 PRAGMA busy_timeout
Pooling true 桌面退出拷贝/哈希可设 false
Cache Default 可用 Shared
Mode ReadWriteCreate 打开模式

MaxReadConcurrency / AcquireTimeoutMs 已标记 [Obsolete](未接线读并发闸门;请用 BusyTimeoutMs)。

每次 CRUD 为短开短关(using 打开连接),无应用层常开连接。可用 Factory.RunInTransaction / ISqliteLifecycle.RunInTransaction 在 Ambient 事务中组合多步 CRUD。

Schema

  • Factory.InitialSQLite / SchemaEnsureRunner:确保目录与 .db、按 [Auto] 模型 CREATE TABLE IF NOT EXISTS、缺失列 ALTER TABLE ADD COLUMN;建表后还会按 [Index] / FK 索引执行 CREATE [UNIQUE] INDEX IF NOT EXISTS
  • SchemaEnsureOptions.Apply:将 JournalMode / Synchronous / ForeignKeys / BusyTimeoutMs 等写入连接启动 PRAGMA(经 ApplySchemaEnsureOptions)
  • AlterTable:补列 / 必要时整表重建(非就地改列类型);RenameColumn(SQLite 3.25+);DropColumn(优先 ALTER TABLE DROP COLUMN,否则重建排除该列)
  • IdentityColumn 与 DatabaseGenerated(Identity) 等价:INTEGER 主键生成 PRIMARY KEY AUTOINCREMENT
  • 建表时若含 ForeignKey,会生成 FK 约束与索引(DDL 分条执行,避免只跑首条)

运维

API 作用
Quiesce / SqliteQuiesce.Quiesce / Factory.Quiesce ClearAllPools + wal_checkpoint(TRUNCATE)
BackupDatabase / Factory.Backup 静默后原子拷贝
RestoreDatabase / Factory.Restore 静默后覆盖主库
SqliteIntegrityGuard 启动哈希校验、关闭备份、导出/还原;元数据默认 {db}.integrity.json

FTS5

  1. 模型属性标 [FullText](列名遵循 [Column] 物理名),调用 CreateFts5Table<T>() 或 Factory.CreateFts5Table<T>()
  2. IndexFts5(entity) / Factory.IndexFts5:要求 INTEGER [Key],按 rowid = Key 删除后插入
  3. SearchFts5(keyword) / Factory.SearchFts5:从主表按 FTS rowid 回填完整实体

特性说明(勿误用)

已接线:Key、Table、Column、Database、Required、MaxLength、StringLength、MinLength、DatabaseGenerated、IdentityColumn、ForeignKey(建表 DDL,非 JOIN)、Index(属性级 / 类级复合)、FullText、DefaultSql、Collation、NotMapped、Persisted、Auto 等。

未实现(已 Obsolete):

  • ConcurrencyCheck(无乐观锁 WHERE)
  • ComplexType(无展平)
  • Timestamp(无 rowversion)
  • Visiable(无列可见性过滤)
  • InverseProperty(无导航加载)

字符串默认长度以 MaxLengthAttribute 代码默认为准(当前默认 500),请显式标注需要的长度。

Factory 与 ISQLite

Factory 快捷:CRUD、条件 Update、QueryPage/Count、Upsert、Truncate、Deduplicate、RunInTransaction、Backup/Restore、InitialSQLite、Quiesce、FTS5。

默认无条件 Inquire / Query 仍 LIMIT 1000(可传 limit: -1 取消限制);分页请用 QueryPage / InquireTable(offset, limit)。

更多能力(IExecute 原始 SQL、AlterTable、CopyTable、IView、建删库/Exists 等)请直调 ISQLite / Factory.SQLite。

明确未提供

  • 多表 JOIN 联查/联改/联删
  • 存储过程、运行时 ADD CONSTRAINT FK
  • 应用层常开连接
  • CopyTable(CTAS)不保留原表约束/索引(SQLite 固有限制)

许可证

MIT。版权归属深圳市海蓝智能科技有限公司。

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 was computed.  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. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Hi.Ltd.Sqlite:

Package Downloads
Hi.Ltd.LocalResource

Hi.Ltd.* 系列本地化与翻译引擎库。完整 Language 引擎留在本库;兄弟库只需 Hi.Ltd.Interface.ITranslate 薄契约。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.10.16.1156 133 10/16/2026
2026.10.15.1514 132 10/15/2026
2026.9.30.1459 123 9/30/2026
2026.7.11.1711 154 7/11/2026
2026.6.10.1451 166 6/10/2026
2026.4.14.1758 148 4/14/2026
2026.4.14.1613 146 4/14/2026
2025.4.17.1101 298 4/17/2025
2025.4.16.1536 280 4/16/2025
2025.4.16.1410 269 4/16/2025
2024.4.16.933 305 4/16/2025