Snippet to automatically enable Sqlite WAL mode when opening connection using ServiceStack.OrmLite.Sqlite.Data
which uses Microsoft.Data.SQLite
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
var connBuilder = new SqliteConnectionStringBuilder
{
DataSource = "database.sqlite",
ForeignKeys = true
};
// Enable WAL mode automatically via Provider OnOpenConnection
var provider = ServiceStack.OrmLite.SqliteDialect.Provider.SqliteDialect.Provider;
provider.OnOpenConnection = db =>
{
db.ExecuteSql("PRAGMA journal_mode=WAL;");
};
var connFactory = new OrmLiteConnectionFactory(connBuilder.ToString(), provider);
// Open Sqlite db connection, WAL will be enabled
using var conn = connFactory.OpenDbConnection();
|