Skip to content

Commit d6a564f

Browse files
realorkoclaude
andcommitted
Migrate from System.Data.SQLite to Microsoft.Data.Sqlite and upgrade NuGet packages
System.Data.SQLite doesn't ship linux-arm64 native binaries, causing test failures on ARM64 machines. Microsoft.Data.Sqlite uses SQLitePCLRaw which supports all platforms. Also updates all outdated NuGet packages and switches connection strategy from singleton to factory for thread safety with Microsoft.Data.Sqlite. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent eeb3dee commit d6a564f

14 files changed

Lines changed: 49 additions & 43 deletions

docker/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"datadirectory": "/tmp",
1414
"settings": {
1515
"connections": {
16-
"strategy": "singleton"
16+
"strategy": "factory"
1717
},
1818
"forwarding": {
1919
"allowed": false,

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ You can activate it using the `Interface.Setup(typeof(Program).Assembly, "appset
6767
"enabled": true,
6868
"settings": {
6969
"connections": {
70-
"strategy": "singleton"
70+
"strategy": "factory"
7171
},
7272
"forwarding": {
7373
"allowed": true,

helm/files/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"datadirectory": "/tmp",
1414
"settings": {
1515
"connections": {
16-
"strategy": "singleton"
16+
"strategy": "factory"
1717
},
1818
"forwarding": {
1919
"allowed": false,

src/sql-d.ui/SqlD.UI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
<Import Project="../../version.props" />
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.0" />
17+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.3" />
1818
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
1919
<PackageReference Include="NSwag.Annotations" Version="14.6.3" />
2020
<PackageReference Include="NSwag.AspNetCore" Version="14.6.3" />
21-
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
21+
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.3" />
2222
<PackageReference Update="Packaging.Targets">
2323
<Version>0.1.232</Version>
2424
</PackageReference>

src/sql-d.ui/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"enabled": true,
1313
"settings": {
1414
"connections": {
15-
"strategy": "singleton"
15+
"strategy": "factory"
1616
},
1717
"forwarding": {
1818
"allowed": true,

src/sql-d/DbConnection.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Data;
2-
using System.Data.SQLite;
2+
using Microsoft.Data.Sqlite;
33
using System.Security.Cryptography;
44
using System.Text;
55
using SqlD.Configs.Model;
@@ -15,7 +15,7 @@ public class DbConnection : IDisposable
1515
public string Name { get; private set; }
1616
public string DatabaseName { get; private set; }
1717
public string ConnectionString { get; private set; }
18-
public SQLiteConnection Connection { get; private set; }
18+
public SqliteConnection Connection { get; private set; }
1919
public SqlDPragmaModel PragmaOptions { get; private set; }
2020

2121
public virtual void Dispose()
@@ -41,7 +41,7 @@ internal string CreateConnectionString(string databaseName)
4141
{
4242
Log.Out.Debug($"Start of creating connection string {databaseName} ... ");
4343

44-
var builder = new SQLiteConnectionStringBuilder();
44+
var builder = new SqliteConnectionStringBuilder { Cache = SqliteCacheMode.Shared };
4545
if (databaseName == ":memory:")
4646
{
4747
builder.DataSource = databaseName;
@@ -55,8 +55,7 @@ internal string CreateConnectionString(string databaseName)
5555

5656
if (!File.Exists(databaseName))
5757
{
58-
Log.Out.Debug($"File does not exist, creating '{databaseName}' ... ");
59-
SQLiteConnection.CreateFile(databaseName);
58+
Log.Out.Debug($"File does not exist, will be created on open '{databaseName}' ... ");
6059
}
6160
}
6261
else
@@ -67,8 +66,7 @@ internal string CreateConnectionString(string databaseName)
6766

6867
if (!File.Exists(databasePath))
6968
{
70-
Log.Out.Debug($"File does not exist, creating '{databasePath}' ... ");
71-
SQLiteConnection.CreateFile(databasePath);
69+
Log.Out.Debug($"File does not exist, will be created on open '{databasePath}' ... ");
7270
}
7371
}
7472
}
@@ -78,13 +76,13 @@ internal string CreateConnectionString(string databaseName)
7876
builder.DataSource = databaseName;
7977
}
8078

81-
Log.Out.Debug($"ConnectionString='{builder};cache=shared'");
82-
return $"{builder};cache=shared";
79+
Log.Out.Debug($"ConnectionString='{builder}'");
80+
return builder.ToString();
8381
}
8482

85-
internal SQLiteConnection CreateConnection(string databaseName)
83+
internal SqliteConnection CreateConnection(string databaseName)
8684
{
87-
var connection = new SQLiteConnection(ConnectionString);
85+
var connection = new SqliteConnection(ConnectionString);
8886

8987
try
9088
{

src/sql-d/DbConnectionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Concurrent;
22
using System.Data;
3-
using System.Data.SQLite;
3+
using Microsoft.Data.Sqlite;
44
using SqlD.Configs.Model;
55
using SqlD.Exceptions;
66
using SqlD.Extensions;

src/sql-d/DbReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
using System.Data.Common;
2-
using System.Data.SQLite;
2+
using Microsoft.Data.Sqlite;
33

44
namespace SqlD;
55

66
public class DbReader : IDisposable
77
{
8-
public DbReader(SQLiteConnection connection)
8+
public DbReader(SqliteConnection connection)
99
{
1010
Connection = connection;
1111
Command = connection.CreateCommand();
1212
}
1313

14-
public SQLiteCommand Command { get; }
15-
public SQLiteConnection Connection { get; }
14+
public SqliteCommand Command { get; }
15+
public SqliteConnection Connection { get; }
1616
public DbDataReader Reader { get; private set; }
1717

1818
public void Dispose()

src/sql-d/Extensions/InsertExtensions.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Data.SQLite;
1+
using Microsoft.Data.Sqlite;
22
using System.Text;
33
using SqlD.Extensions.Discovery;
44

@@ -57,9 +57,9 @@ internal static string GetInsert(this object instance, bool withIdentity = false
5757
return result.ToString();
5858
}
5959

60-
internal static SQLiteCommand GetInsertPrepared(this object instance, SQLiteConnection connection, bool withIdentity = false)
60+
internal static SqliteCommand GetInsertPrepared(this object instance, SqliteConnection connection, bool withIdentity = false)
6161
{
62-
var command = new SQLiteCommand(connection);
62+
var command = connection.CreateCommand();
6363

6464
var result = new StringBuilder();
6565

@@ -87,14 +87,16 @@ internal static SQLiteCommand GetInsertPrepared(this object instance, SQLiteConn
8787
result.AppendLine("(");
8888

8989
var values = new List<string>();
90+
var paramIndex = 0;
9091

9192
foreach (var property in properties)
9293
{
9394
if (property.Name == idProperty.Name && !withIdentity) continue;
94-
values.Add("?");
95+
var paramName = $"@p{paramIndex++}";
96+
values.Add(paramName);
9597
var instanceValue = property.GetValue(instance);
9698

97-
var sqlParameter = new SQLiteParameter(instanceValue.GetType().ToDbType(), instanceValue);
99+
var sqlParameter = new SqliteParameter(paramName, instanceValue);
98100
command.Parameters.Add(sqlParameter);
99101
}
100102

src/sql-d/Extensions/UpdateExtensions.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Data.SQLite;
1+
using Microsoft.Data.Sqlite;
22
using System.Text;
33
using SqlD.Extensions.Discovery;
44

@@ -38,9 +38,9 @@ internal static string GetUpdate(this object instance)
3838
return result.ToString();
3939
}
4040

41-
internal static SQLiteCommand GetUpdatePrepared(this object instance, SQLiteConnection connection)
41+
internal static SqliteCommand GetUpdatePrepared(this object instance, SqliteConnection connection)
4242
{
43-
var command = new SQLiteCommand(connection);
43+
var command = connection.CreateCommand();
4444

4545
var result = new StringBuilder();
4646

@@ -53,16 +53,18 @@ internal static SQLiteCommand GetUpdatePrepared(this object instance, SQLiteConn
5353
var columns = new List<string>();
5454

5555
var properties = PropertyDiscovery.GetProperties(type);
56+
var paramIndex = 0;
5657

5758
var idProperty = PropertyDiscovery.GetProperty("Id", type);
5859
foreach (var property in properties)
5960
{
6061
if (property.Name == idProperty.Name) continue;
6162
var columnName = AttributeDiscovery.GetColumnName(property);
62-
columns.Add($"{columnName} = ?");
63+
var paramName = $"@p{paramIndex++}";
64+
columns.Add($"{columnName} = {paramName}");
6365

6466
var columnValue = ValueDiscovery.GetValue(instance, property);
65-
var sqlParameter = new SQLiteParameter(columnValue.GetType().ToDbType(), columnValue);
67+
var sqlParameter = new SqliteParameter(paramName, columnValue);
6668
command.Parameters.Add(sqlParameter);
6769
}
6870

@@ -71,9 +73,10 @@ internal static SQLiteCommand GetUpdatePrepared(this object instance, SQLiteConn
7173
result.AppendLine("WHERE");
7274

7375
var idValue = ValueDiscovery.GetValue(instance, idProperty);
74-
result.AppendLine("Id = ?");
76+
var idParamName = $"@p{paramIndex}";
77+
result.AppendLine($"Id = {idParamName}");
7578

76-
var idSqlParameter = new SQLiteParameter(idValue.GetType().ToDbType(), idValue);
79+
var idSqlParameter = new SqliteParameter(idParamName, idValue);
7780
command.Parameters.Add(idSqlParameter);
7881

7982
command.CommandText = result.ToString();

0 commit comments

Comments
 (0)