Skip to content

Commit eba7edd

Browse files
Update descriminator
1 parent e7ef3a4 commit eba7edd

File tree

9 files changed

+19
-20
lines changed

9 files changed

+19
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public class MyDeathStarContext : CouchContext
523523

524524
If you are not using `CouchContext`, you can still use the database slit feature:
525525
```csharp
526-
var rebels = client.GetDatabase<Rebel>("troups", nameof(Rebel)); // Add [JsonObject("troups")] to Rebel
526+
var rebels = client.GetDatabase<Rebel>("troups", nameof(Rebel));
527527
var vehicles = client.GetDatabase<Vehicle>("troups", nameof(Vehicle));
528528
```
529529

src/CouchDB.Driver/CouchClient.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ private Task<IFlurlResponse> CreateDatabaseAsync(QueryContext queryContext,
199199
#region CRUD reflection
200200

201201
/// <inheritdoc />
202-
public ICouchDatabase<TSource> GetDatabase<TSource>(string? discriminator = null) where TSource : CouchDocument
202+
public ICouchDatabase<TSource> GetDatabase<TSource>() where TSource : CouchDocument
203203
{
204-
return GetDatabase<TSource>(GetClassName<TSource>(), discriminator);
204+
return GetDatabase<TSource>(GetClassName<TSource>());
205205
}
206206

207207
/// <inheritdoc />

src/CouchDB.Driver/CouchDatabase.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public async Task<TSource> AddAsync(TSource document, bool batch = false, Cancel
190190
request = request.SetQueryParam("batch", "ok");
191191
}
192192

193-
document.Discriminator = _discriminator;
193+
document.SplitDiscriminator = _discriminator;
194194
DocumentSaveResponse response = await request
195195
.PostJsonAsync(document, cancellationToken)
196196
.ReceiveJson<DocumentSaveResponse>()
@@ -222,7 +222,7 @@ public async Task<TSource> AddOrUpdateAsync(TSource document, bool batch = false
222222
request = request.SetQueryParam("batch", "ok");
223223
}
224224

225-
document.Discriminator = _discriminator;
225+
document.SplitDiscriminator = _discriminator;
226226
DocumentSaveResponse response = await request
227227
.PutJsonAsync(document, cancellationToken)
228228
.ReceiveJson<DocumentSaveResponse>()
@@ -269,7 +269,7 @@ public async Task<IEnumerable<TSource>> AddOrUpdateRangeAsync(IList<TSource> doc
269269

270270
foreach (TSource? document in documents)
271271
{
272-
document.Discriminator = _discriminator;
272+
document.SplitDiscriminator = _discriminator;
273273
}
274274

275275
DocumentSaveResponse[] response = await NewRequest()

src/CouchDB.Driver/Helpers/MethodCallExpressionBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static MethodCallExpression WrapInDiscriminatorFilter<TSource>(this Expre
114114
{
115115
Check.NotNull(node, nameof(node));
116116

117-
Expression<Func<TSource, bool>> filter = (d) => d.Discriminator == discriminator;
117+
Expression<Func<TSource, bool>> filter = (d) => d.SplitDiscriminator == discriminator;
118118

119119
return Expression.Call(typeof(Queryable), nameof(Queryable.Where),
120120
new[] { typeof(TSource) }, node, filter);

src/CouchDB.Driver/ICouchClient.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ Task<ICouchDatabase<TSource>> GetOrCreateDatabaseAsync<TSource>(string database,
6262
/// If EnsureDatabaseExists is configured, it creates the database if it doesn't exists.
6363
/// </summary>
6464
/// <typeparam name="TSource">The type of database documents.</typeparam>
65-
/// <param name="discriminator">Filters documents by the given discriminator.</param>
6665
/// <returns>The instance of the CouchDB database of the given type.</returns>
67-
ICouchDatabase<TSource> GetDatabase<TSource>(string? discriminator = null) where TSource : CouchDocument;
66+
ICouchDatabase<TSource> GetDatabase<TSource>() where TSource : CouchDocument;
6867

6968
/// <summary>
7069
/// Returns an instance of the CouchDB database with the name type <see cref="TSource"/>.

src/CouchDB.Driver/Types/CouchDocument.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ private Dictionary<string, CouchAttachment> AttachmentsSetter
5858
public CouchAttachmentsCollection Attachments { get; internal set; }
5959

6060
[DataMember]
61-
[JsonProperty("discriminator", NullValueHandling = NullValueHandling.Ignore)]
62-
internal string Discriminator { get; set; }
61+
[JsonProperty("split_discriminator", NullValueHandling = NullValueHandling.Ignore)]
62+
internal string SplitDiscriminator { get; set; }
6363

6464
[OnDeserialized]
6565
internal void OnDeserializedMethod(StreamingContext context)

tests/CouchDB.Driver.UnitTests/CouchDbContext_Tests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ await context.OtherRebels.AddAsync(new OtherRebel
104104
var result = await context.OtherRebels.ToListAsync();
105105
Assert.NotEmpty(result);
106106
Assert.Equal("Luke", result[0].Name);
107-
Assert.Equal(@"{""_conflicts"":[],""name"":""Leia"",""age"":0,""discriminator"":""SimpleRebel""}", httpTest.CallLog[0].RequestBody);
108-
Assert.Equal(@"{""_conflicts"":[],""rebel_bith_date"":""0001-01-01T00:00:00"",""name"":""Luke"",""age"":0,""isJedi"":false,""species"":0,""guid"":""00000000-0000-0000-0000-000000000000"",""discriminator"":""OtherRebel""}", httpTest.CallLog[1].RequestBody);
109-
Assert.Equal(@"{""selector"":{""discriminator"":""OtherRebel""}}", httpTest.CallLog[2].RequestBody);
107+
Assert.Equal(@"{""_conflicts"":[],""name"":""Leia"",""age"":0,""split_discriminator"":""SimpleRebel""}", httpTest.CallLog[0].RequestBody);
108+
Assert.Equal(@"{""_conflicts"":[],""rebel_bith_date"":""0001-01-01T00:00:00"",""name"":""Luke"",""age"":0,""isJedi"":false,""species"":0,""guid"":""00000000-0000-0000-0000-000000000000"",""split_discriminator"":""OtherRebel""}", httpTest.CallLog[1].RequestBody);
109+
Assert.Equal(@"{""selector"":{""split_discriminator"":""OtherRebel""}}", httpTest.CallLog[2].RequestBody);
110110
}
111111
}
112112
}

tests/CouchDB.Driver.UnitTests/Database_Tests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public async Task Create_Discriminator()
123123

124124
var r = new Rebel { Name = "Luke" };
125125
var newR = await rebels.AddAsync(r);
126-
Assert.Equal("myRebels", newR.Discriminator);
126+
Assert.Equal("myRebels", newR.SplitDiscriminator);
127127
httpTest
128128
.ShouldHaveCalled("http://localhost/rebels")
129129
.WithVerb(HttpMethod.Post);
@@ -138,7 +138,7 @@ public async Task CreateOrUpdate_Discriminator()
138138

139139
var r = new Rebel { Name = "Luke", Id = "1" };
140140
var newR = await rebels.AddOrUpdateAsync(r);
141-
Assert.Equal("myRebels", newR.Discriminator);
141+
Assert.Equal("myRebels", newR.SplitDiscriminator);
142142
httpTest
143143
.ShouldHaveCalled("http://localhost/rebels/1")
144144
.WithVerb(HttpMethod.Put);

tests/CouchDB.Driver.UnitTests/Find/Find_Discriminator.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ public void Discriminator_WithoutFilter()
2222
{
2323
var json1 = _rebels.ToString();
2424
var json2 = _simpleRebels.ToString();
25-
Assert.Equal(@"{""selector"":{""discriminator"":""Rebel""}}", json1);
26-
Assert.Equal(@"{""selector"":{""discriminator"":""SimpleRebel""}}", json2);
25+
Assert.Equal(@"{""selector"":{""split_discriminator"":""Rebel""}}", json1);
26+
Assert.Equal(@"{""selector"":{""split_discriminator"":""SimpleRebel""}}", json2);
2727
}
2828

2929
[Fact]
3030
public void Discriminator_WithFilter()
3131
{
3232
var json1 = _rebels.Where(c => c.Age == 19).ToString();
3333
var json2 = _simpleRebels.Where(c => c.Age == 19).ToString();
34-
Assert.Equal(@"{""selector"":{""$and"":[{""age"":19},{""discriminator"":""Rebel""}]}}", json1);
35-
Assert.Equal(@"{""selector"":{""$and"":[{""age"":19},{""discriminator"":""SimpleRebel""}]}}", json2);
34+
Assert.Equal(@"{""selector"":{""$and"":[{""age"":19},{""split_discriminator"":""Rebel""}]}}", json1);
35+
Assert.Equal(@"{""selector"":{""$and"":[{""age"":19},{""split_discriminator"":""SimpleRebel""}]}}", json2);
3636
}
3737
}
3838
}

0 commit comments

Comments
 (0)