Skip to content

Commit 10c7dc3

Browse files
authored
Merge pull request #1 from CoreBTS/feature/add-json-support
Add JSON support for complex types
2 parents e8a24a8 + e228eff commit 10c7dc3

File tree

12 files changed

+352
-16
lines changed

12 files changed

+352
-16
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ jobs:
3030
run: |
3131
set -e
3232
cd tests/SQLite.Tests
33-
dotnet test /p:AltCover=true /p:AltCoverForce=true "/p:AltCoverTypeFilter=SQLite.Tests.*"
33+
dotnet test /p:AltCover=true /p:AltCoverForce=true /p:AltCoverTypeFilter="SQLite.Tests.*" /p:AltCoverAssemblyFilter="Microsoft.*|System.*|testhost"
3434
3535
- name: Generate Code Coverage Report
36-
uses: danielpalme/ReportGenerator-GitHub-Action@4.8.4
36+
uses: danielpalme/ReportGenerator-GitHub-Action@5.1.26
3737
with:
3838
reports: 'tests/SQLite.Tests/coverage.xml' # REQUIRED # The coverage reports that should be parsed (separated by semicolon). Globbing is supported.
3939
targetdir: 'CoverageReport' # REQUIRED # The directory where the generated report should be saved.

nuget/SQLite-net-base/SQLite-net-base.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
@@ -27,7 +27,8 @@
2727
<DocumentationFile>bin\Debug\netstandard2.0\SQLite-net.xml</DocumentationFile>
2828
</PropertyGroup>
2929
<ItemGroup>
30-
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.2" />
30+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
31+
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.6" />
3132
</ItemGroup>
3233
<ItemGroup>
3334
<Compile Include="..\..\src\SQLite.cs">

nuget/SQLite-net-sqlcipher/SQLite-net-sqlcipher.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
<DocumentationFile>bin\Debug\netstandard2.0\SQLite-net.xml</DocumentationFile>
2828
</PropertyGroup>
2929
<ItemGroup>
30-
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.2" />
30+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
31+
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.6" />
3132
</ItemGroup>
3233
<ItemGroup>
3334
<Compile Include="..\..\src\SQLite.cs">

nuget/SQLite-net-static/SQLite-net-static.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@
3333
</Compile>
3434
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="" />
3535
</ItemGroup>
36+
<ItemGroup>
37+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
38+
</ItemGroup>
3639
</Project>

nuget/SQLite-net-std/SQLite-net-std.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
<DocumentationFile>bin\Debug\netstandard2.0\SQLite-net.xml</DocumentationFile>
2828
</PropertyGroup>
2929
<ItemGroup>
30-
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.2" />
30+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
31+
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.6" />
3132
</ItemGroup>
3233
<ItemGroup>
3334
<Compile Include="..\..\src\SQLite.cs">

src/SQLite.cs

+22-3
Original file line numberDiff line numberDiff line change
@@ -2850,6 +2850,15 @@ public static class Orm
28502850
public const int DefaultMaxStringLength = 140;
28512851
public const string ImplicitPkName = "Id";
28522852
public const string ImplicitIndexSuffix = "Id";
2853+
public static readonly Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings
2854+
{
2855+
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver
2856+
{
2857+
IgnoreSerializableAttribute = true,
2858+
IgnoreSerializableInterface = true,
2859+
IgnoreShouldSerializeMembers = true
2860+
},
2861+
};
28532862

28542863
public static Type GetType (object obj)
28552864
{
@@ -2896,7 +2905,7 @@ public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks,
28962905
if (len.HasValue)
28972906
return "varchar(" + len.Value + ")";
28982907

2899-
return "varchar";
2908+
return "text";
29002909
}
29012910
else if (clrType == typeof (TimeSpan)) {
29022911
return storeTimeSpanAsTicks ? "bigint" : "time";
@@ -2919,8 +2928,9 @@ public static string SqlType (TableMapping.Column p, bool storeDateTimeAsTicks,
29192928
else if (clrType == typeof (Guid)) {
29202929
return "varchar(36)";
29212930
}
2922-
else {
2923-
throw new NotSupportedException ("Don't know about " + clrType);
2931+
else { // fallback to JSON
2932+
return SQLite3.LibVersionNumber () >= 3009000 ? "json" : "text";
2933+
//throw new NotSupportedException ("Don't know about " + clrType);
29242934
}
29252935
}
29262936

@@ -3334,6 +3344,10 @@ internal static void BindParameter (Sqlite3Statement stmt, int index, object val
33343344
else
33353345
SQLite3.BindInt (stmt, index, enumIntValue);
33363346
}
3347+
else if (SQLite3.LibVersionNumber () >= 3009000) {
3348+
// fallback to JSON
3349+
SQLite3.BindText (stmt, index, Newtonsoft.Json.JsonConvert.SerializeObject (value, Orm.JsonSerializerSettings), -1, NegativePointer);
3350+
}
33373351
else {
33383352
throw new NotSupportedException ("Cannot store type: " + Orm.GetType (value));
33393353
}
@@ -3454,6 +3468,11 @@ object ReadCol (Sqlite3Statement stmt, int index, SQLite3.ColType type, Type clr
34543468
var text = SQLite3.ColumnString (stmt, index);
34553469
return new UriBuilder (text);
34563470
}
3471+
else if (SQLite3.LibVersionNumber () >= 3009000) {
3472+
// fallback to JSON
3473+
var text = SQLite3.ColumnString (stmt, index);
3474+
return Newtonsoft.Json.JsonConvert.DeserializeObject(text, clrType, Orm.JsonSerializerSettings);
3475+
}
34573476
else {
34583477
throw new NotSupportedException ("Don't know how to read " + clrType);
34593478
}

tests/ApiDiff/ApiDiff.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -29,6 +29,9 @@
2929
<ExternalConsole>true</ExternalConsole>
3030
</PropertyGroup>
3131
<ItemGroup>
32+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
33+
<HintPath>..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
34+
</Reference>
3235
<Reference Include="System" />
3336
<Reference Include="ListDiff">
3437
<HintPath>..\..\packages\ListDiff.1.0.7\lib\netstandard1.0\ListDiff.dll</HintPath>

tests/ApiDiff/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="ListDiff" version="1.0.7" targetFramework="net461" />
4+
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net461" />
45
</packages>

tests/SQLite.Tests.iOS/SQLiteTestsiOS.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
8686
</PropertyGroup>
8787
<ItemGroup>
88+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
89+
<HintPath>..\..\packages\Newtonsoft.Json.13.0.3\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
90+
</Reference>
8891
<Reference Include="System" />
8992
<Reference Include="System.Xml" />
9093
<Reference Include="System.Core" />
@@ -97,6 +100,7 @@
97100
<ItemGroup>
98101
<None Include="Info.plist" />
99102
<None Include="Entitlements.plist" />
103+
<None Include="packages.config" />
100104
</ItemGroup>
101105
<ItemGroup>
102106
<Compile Include="Main.cs" />
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="xamarinios10" />
4+
</packages>

0 commit comments

Comments
 (0)