Skip to content

SQLite Overview ​

Weasel.Sqlite provides schema management and migration support for SQLite databases using the Microsoft.Data.Sqlite driver. It follows the same patterns as other Weasel providers while respecting SQLite's unique characteristics.

Installation ​

bash
dotnet add package Weasel.Sqlite

Key Components ​

  • SqliteMigrator -- DDL generation with transaction support
  • SqliteProvider -- Type mappings and schema introspection
  • SqliteHelper -- Simplified connection creation with PRAGMA configuration

Schema Support ​

SQLite supports two built-in schemas:

SchemaDescriptionDDL Prefix
mainPrimary database schema (default)None
tempTemporary objects, connection-scoped"temp".

Objects in the main schema omit the schema prefix in generated DDL. Objects in temp or attached database schemas include a quoted prefix.

Type Mappings ​

.NET TypeSQLite TypeStorage Class
int, long, short, byteINTEGERINTEGER
boolINTEGERINTEGER
float, double, decimalREALREAL
string, charTEXTTEXT
DateTime, DateTimeOffsetTEXTTEXT (ISO8601)
GuidTEXTTEXT
byte[]BLOBBLOB
Complex types (JSON)TEXTTEXT

ALTER TABLE Limitations ​

SQLite has restricted ALTER TABLE support compared to PostgreSQL or SQL Server:

  • Supported: ADD COLUMN (nullable or with DEFAULT), DROP COLUMN (3.35+), RENAME COLUMN (3.25+)
  • Not supported: ADD CONSTRAINT, DROP CONSTRAINT, most ALTER COLUMN changes

When a schema change cannot be applied incrementally, Weasel automatically handles table recreation: create new table, copy data, drop old table, rename.

Supported Objects ​

  • Tables -- Full DDL generation, delta detection, and migration
  • Views -- CREATE/DROP with automatic recreation on changes

Quick Example ​

cs
var connection = new SqliteConnection("Data Source=myapp.db");
await connection.OpenAsync();

var table = new Table("users");
table.AddColumn<int>("id").AsPrimaryKey().AutoIncrement();
table.AddColumn<string>("name").NotNull();

var migrator = new SqliteMigrator();
var writer = new StringWriter();
table.WriteCreateStatement(migrator, writer);

var cmd = connection.CreateCommand();
cmd.CommandText = writer.ToString();
await cmd.ExecuteNonQueryAsync();

snippet source | anchor

Native SQLite bundle ​

Weasel.Sqlite references Microsoft.Data.Sqlite plus SQLitePCLRaw.bundle_e_sqlite3 on the SQLitePCLRaw 3.0.x line (currently 3.0.5). Microsoft.Data.Sqlite 11 depends on that same bundle and version, so moving to it needs no change here: Weasel does not swap in SQLite3MC.PCLRaw (an encrypted build, which is a choice for an application to make) and does not cap Microsoft.Data.Sqlite below 11. An application that wants SQLite3MC can reference its provider package itself, since SQLite3MC.PCLRaw.provider is built on SQLitePCLRaw 3.0.x as well.

Released under the MIT License.