Skip to content

Commit 8653f19

Browse files
committed
Update SQLiteInitializer.cs
1 parent 1ce0235 commit 8653f19

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

plugins/magic.library/internals/SQLiteInitializer.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,7 @@ public async Task Initialize(IRootResolver resolver, SqliteConnection connection
3737
var plt = GetPlatformExtension();
3838
var extensionPath = resolver.RuntimePath("sqlite-plugins/vector" + plt);
3939

40-
// Load the extension ONCE per connection (no retries for load).
41-
using (var load = connection.CreateCommand())
42-
{
43-
load.CommandText = "select load_extension($p, 'sqlite3_vector_init')";
44-
load.Parameters.AddWithValue("$p", extensionPath);
45-
_ = await load.ExecuteScalarAsync();
46-
}
47-
40+
// Notice, we cannot run vector_init before we've created our magic database!!
4841
if (_shouldRunVectorInit)
4942
{
5043
const int maxAttempts = 3;
@@ -53,6 +46,13 @@ public async Task Initialize(IRootResolver resolver, SqliteConnection connection
5346
{
5447
try
5548
{
49+
// Load the extension ONCE per connection (no retries for load).
50+
using (var load = connection.CreateCommand())
51+
{
52+
load.CommandText = "select load_extension($p, 'sqlite3_vector_init')";
53+
load.Parameters.AddWithValue("$p", extensionPath);
54+
_ = await load.ExecuteScalarAsync();
55+
}
5656
await RunVectorInit(connection);
5757
break;
5858
}
@@ -68,6 +68,10 @@ public async Task Initialize(IRootResolver resolver, SqliteConnection connection
6868
_locker.Release();
6969
}
7070
}
71+
72+
/*
73+
* Private helper methods.
74+
*/
7175

7276
static async Task RunVectorInit(SqliteConnection connection)
7377
{

0 commit comments

Comments
 (0)