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
<PackageReference Include="Hi.Ltd.Sqlite" Version="2026.10.16.1156" />
<PackageVersion Include="Hi.Ltd.Sqlite" Version="2026.10.16.1156" />
<PackageReference Include="Hi.Ltd.Sqlite" />
paket add Hi.Ltd.Sqlite --version 2026.10.16.1156
#r "nuget: Hi.Ltd.Sqlite, 2026.10.16.1156"
#:package Hi.Ltd.Sqlite@2026.10.16.1156
#addin nuget:?package=Hi.Ltd.Sqlite&version=2026.10.16.1156
#tool nuget:?package=Hi.Ltd.Sqlite&version=2026.10.16.1156
Hi.Ltd.Sqlite
面向本地文件的 SQLite 访问库:属性映射 CRUD、Schema 补齐、备份/还原/静默、完整性守卫、FTS5。公开 API 统一返回 Hi.Ltd 的 Result / Result<T>。
依赖
Hi.LtdMicrosoft.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 EXISTSSchemaEnsureOptions.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
- 模型属性标
[FullText](列名遵循[Column]物理名),调用CreateFts5Table<T>()或Factory.CreateFts5Table<T>() IndexFts5(entity)/Factory.IndexFts5:要求 INTEGER[Key],按rowid = Key删除后插入SearchFts5(keyword)/Factory.SearchFts5:从主表按 FTSrowid回填完整实体
特性说明(勿误用)
已接线: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 | Versions 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. |
-
.NETFramework 4.6.2
- Hi.Ltd (>= 2026.10.15.1049)
- Microsoft.Data.Sqlite.Core (>= 10.0.13)
- System.Text.Json (>= 10.0.13)
-
.NETFramework 4.8.1
- Hi.Ltd (>= 2026.10.15.1049)
- Microsoft.Data.Sqlite.Core (>= 10.0.13)
- System.Text.Json (>= 10.0.13)
-
net6.0
- Hi.Ltd (>= 2026.10.15.1049)
- Microsoft.Data.Sqlite.Core (>= 10.0.13)
- System.Drawing.Common (>= 10.0.13)
-
net8.0
- Hi.Ltd (>= 2026.10.15.1049)
- Microsoft.Data.Sqlite.Core (>= 10.0.13)
- System.Drawing.Common (>= 10.0.13)
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 |