-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMDSQLiteOptions.cs
More file actions
160 lines (129 loc) · 5.35 KB
/
MDSQLiteOptions.cs
File metadata and controls
160 lines (129 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
namespace PowerSync.Common.MDSQLite;
public sealed class TemporaryStorageOption
{
public static readonly TemporaryStorageOption MEMORY = new("memory");
public static readonly TemporaryStorageOption FILESYSTEM = new("file");
public string Value { get; }
private TemporaryStorageOption(string value) => Value = value;
public override string ToString() => Value;
public static implicit operator string(TemporaryStorageOption option) => option.Value;
}
/// <summary>
/// SQLite journal mode. Set on the primary connection.
/// This library is written with WAL mode in mind - other modes may cause
/// unexpected locking behavior.
/// </summary>
public sealed class SqliteJournalMode
{
/// <summary>
/// Use a write-ahead log instead of a rollback journal.
/// This provides good performance and concurrency.
/// </summary>
public static readonly SqliteJournalMode WAL = new("WAL");
public static readonly SqliteJournalMode DELETE = new("DELETE");
public static readonly SqliteJournalMode TRUNCATE = new("TRUNCATE");
public static readonly SqliteJournalMode PERSIST = new("PERSIST");
public static readonly SqliteJournalMode MEMORY = new("MEMORY");
public static readonly SqliteJournalMode OFF = new("OFF");
public string Value { get; }
private SqliteJournalMode(string value) => Value = value;
public override string ToString() => Value;
public static implicit operator string(SqliteJournalMode mode) => mode.Value;
}
/// <summary>
/// SQLite file commit mode.
/// </summary>
public sealed class SqliteSynchronous
{
public static readonly SqliteSynchronous NORMAL = new("NORMAL");
public static readonly SqliteSynchronous FULL = new("full");
public static readonly SqliteSynchronous OFF = new("OFF");
public string Value { get; }
private SqliteSynchronous(string value) => Value = value;
public override string ToString() => Value;
public static implicit operator string(SqliteSynchronous mode) => mode.Value;
}
public class SqliteExtension
{
public string Path { get; set; } = string.Empty;
public string? EntryPoint { get; set; }
}
public class MDSQLiteOptions
{
/// <summary>
/// SQLite journal mode. Defaults to WAL.
/// </summary>
public SqliteJournalMode? JournalMode { get; set; }
/// <summary>
/// SQLite synchronous flag. Defaults to NORMAL, which is safe for WAL mode.
/// </summary>
public SqliteSynchronous? Synchronous { get; set; }
/// <summary>
/// Journal/WAL size limit. Defaults to 6MB.
/// </summary>
public int? JournalSizeLimit { get; set; }
/// <summary>
/// Timeout in milliseconds waiting for locks to be released by other connections.
/// Defaults to 30 seconds.
/// </summary>
public int? LockTimeoutMs { get; set; }
/// <summary>
/// Encryption key for the database.
/// If set, the database will be encrypted using SQLCipher.
/// </summary>
public string? EncryptionKey { get; set; }
/// <summary>
/// Where to store SQLite temporary files. Defaults to MEMORY.
/// </summary>
public TemporaryStorageOption? TemporaryStorage { get; set; }
/// <summary>
/// Maximum SQLite cache size. Defaults to 50MB.
/// </summary>
public int? CacheSizeKb { get; set; }
/// <summary>
/// Additional SQLite extensions to load on every connection, in order. Defaults
/// to an empty list. The bundled PowerSync core extension is loaded separately
/// and controlled by <see cref="LoadPowerSyncExtension"/> — do not include it
/// here.
/// </summary>
public SqliteExtension[]? Extensions { get; set; }
/// <summary>
/// Whether to load the bundled PowerSync core SQLite extension on every
/// connection. Defaults to true and should remain true for normal use — the
/// rest of the library relies on the SQL functions and virtual tables it
/// registers (e.g. <c>powersync_init()</c>). Set to false only if you are
/// supplying an equivalent PowerSync-compatible extension via
/// <see cref="Extensions"/>.
/// </summary>
public bool? LoadPowerSyncExtension { get; set; }
/// <summary>
/// The number of MDSQLiteConnection objects to create for the read pool.
/// </summary>
public int? ReadPoolSize { get; set; }
}
public class RequiredMDSQLiteOptions : MDSQLiteOptions
{
public static RequiredMDSQLiteOptions DEFAULT_SQLITE_OPTIONS = new()
{
JournalMode = SqliteJournalMode.WAL,
Synchronous = SqliteSynchronous.NORMAL,
JournalSizeLimit = 6 * 1024 * 1024,
CacheSizeKb = 50 * 1024,
TemporaryStorage = TemporaryStorageOption.MEMORY,
LockTimeoutMs = 30000,
EncryptionKey = null,
Extensions = [],
LoadPowerSyncExtension = true,
ReadPoolSize = 5,
};
public new SqliteJournalMode JournalMode { get; set; } = null!;
public new SqliteSynchronous Synchronous { get; set; } = null!;
public new int JournalSizeLimit { get; set; }
public new int LockTimeoutMs { get; set; }
public new string? EncryptionKey { get; set; }
public new TemporaryStorageOption TemporaryStorage { get; set; } = null!;
public new int CacheSizeKb { get; set; }
public new SqliteExtension[] Extensions { get; set; } = null!;
public new bool LoadPowerSyncExtension { get; set; }
public new int ReadPoolSize { get; set; }
}