$ show praeclarum/sqlite-net
sqlite-net is a lightweight .NET ORM library for SQLite, providing both synchronous and asynchronous APIs. It maps C# classes to database tables via attributes, supports CRUD operations, LINQ-like queries, transactions, migrations, encryption (SQLCipher), and backup. The library is implemented in two main source files (SQLite.cs and SQLiteAsync.cs) and uses SQLitePCLRaw or P/Invoke to interface with native SQLite. It targets .NET Standard 2.0, .NET 8, and .NET 9, and is designed for cross-platform use including Xamarin, UWP, and desktop applications. The codebase is well-structured with performance optimizations like fast column setters and prepared statement caching, and includes a comprehensive test suite. It is actively maintained with recent commits and CI integration.
The LLM identified 3 files worth highlighting for reuse:
The SQLiteConnectionPool class manages a pool of SQLiteConnectionWithLock instances keyed by connection string. It provides thread-safe access to connections, supports lazy initialization, and allows closing specific connections or resetting the entire pool. This pattern is reusable for any scenario requiring pooled, thread-safe database connections with transaction locking.
The CompileExpr method in TableQuery translates C# expression trees into SQL WHERE clauses, supporting operators, method calls (StartsWith, Contains, etc.), and null handling. This is a non-trivial piece of code that demonstrates how to convert LINQ expressions to parameterized SQL, and could be extracted as a standalone expression-to-SQL compiler for other ORMs or query builders.
The FastColumnSetter class generates strongly-typed delegates for setting object properties from SQLite column values, avoiding repeated reflection overhead. It handles nullable types, enums, and various CLR types. This pattern is reusable for any data access layer that needs high-performance object materialization from database rows.