Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit fa61794

Browse files
committed
Fix the postgresql json test.
Use CustomField as an indicator for the underlying postgresql type.
1 parent 75b7831 commit fa61794

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/ServiceStack.OrmLite.PostgreSQL.Tests/PostgreSqlJsonTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ public void Can_save_complex_types_as_JSON()
5555
db.Insert(row);
5656

5757
var result = db.Select<ModelWithJsonType>(
58-
"complex_type_json->'sub_type'->>'name' = 'SubType2'");
58+
"complex_type_json->'SubType'->>'Name' = 'SubType2'");
59+
60+
db.GetLastSql().Print();
5961

6062
Assert.That(result.Count, Is.EqualTo(1));
61-
Assert.That(result[0].Id, Is.EqualTo(2));
62-
Assert.That(result[0].ComplexTypeJson.SubType, Is.EqualTo("SubType2"));
63+
Assert.That(result[0].Id, Is.EqualTo(1));
64+
Assert.That(result[0].ComplexTypeJson.Id, Is.EqualTo(2));
65+
Assert.That(result[0].ComplexTypeJson.SubType.Name, Is.EqualTo("SubType2"));
6366
}
6467
}
6568
}

src/ServiceStack.OrmLite.PostgreSQL/PostgreSQLDialectProvider.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Data;
44
using System.Text;
55
using Npgsql;
6+
using NpgsqlTypes;
67
using ServiceStack.Text;
78

89
namespace ServiceStack.OrmLite.PostgreSQL
@@ -324,5 +325,15 @@ public override long InsertAndGetLastInsertId<T>(IDbCommand dbCmd)
324325

325326
return dbCmd.ExecLongScalar();
326327
}
328+
public override void SetParameter(FieldDefinition fieldDef, IDbDataParameter p)
329+
{
330+
if (fieldDef.CustomFieldDefinition == "json")
331+
{
332+
p.ParameterName = this.GetParam(SanitizeFieldNameForParamName(fieldDef.FieldName));
333+
((NpgsqlParameter) p).NpgsqlDbType = NpgsqlDbType.Json;
334+
return;
335+
}
336+
base.SetParameter(fieldDef, p);
337+
}
327338
}
328339
}

0 commit comments

Comments
 (0)