Version 4 #6
@ -426,12 +426,6 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison (->> =)
|
||||
[<CompiledName "FSharpByField">]
|
||||
[<System.Obsolete "Use byFields instead; will be removed in v4">]
|
||||
let byField<'TDoc> tableName field sqlProps =
|
||||
byFields<'TDoc> tableName Any [ field ] sqlProps
|
||||
|
||||
/// Retrieve documents matching JSON field comparisons (->> =)
|
||||
let ByFields<'TDoc>(tableName, howMatched, fields, sqlProps) =
|
||||
Custom.List<'TDoc>(
|
||||
@ -439,11 +433,6 @@ module WithProps =
|
||||
addFieldParams fields [],
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison (->> =)
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let ByField<'TDoc>(tableName, field, sqlProps) =
|
||||
ByFields<'TDoc>(tableName, Any, Seq.singleton field, sqlProps)
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>)
|
||||
[<CompiledName "FSharpByContains">]
|
||||
@ -481,13 +470,7 @@ module WithProps =
|
||||
(addFieldParams fields [])
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison (->> =); returns None if not found
|
||||
[<CompiledName "FSharpFirstByField">]
|
||||
[<System.Obsolete "Use firstByFields instead; will be removed in v4">]
|
||||
let firstByField<'TDoc> tableName field sqlProps =
|
||||
firstByFields<'TDoc> tableName Any [ field ] sqlProps
|
||||
|
||||
|
||||
/// Retrieve the first document matching JSON field comparisons (->> =); returns null if not found
|
||||
let FirstByFields<'TDoc when 'TDoc: null>(tableName, howMatched, fields, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
@ -495,12 +478,7 @@ module WithProps =
|
||||
addFieldParams fields [],
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison (->> =); returns null if not found
|
||||
[<System.Obsolete "Use FirstByFields instead; will be removed in v4">]
|
||||
let FirstByField<'TDoc when 'TDoc: null>(tableName, field, sqlProps) =
|
||||
FirstByFields<'TDoc>(tableName, Any, Seq.singleton field, sqlProps)
|
||||
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>); returns None if not found
|
||||
[<CompiledName "FSharpFirstByContains">]
|
||||
let firstByContains<'TDoc> tableName (criteria: obj) sqlProps =
|
||||
@ -571,12 +549,6 @@ module WithProps =
|
||||
(Query.byFields (Query.patch tableName) howMatched fields)
|
||||
(addFieldParams fields [ jsonParam "@data" patch ])
|
||||
sqlProps
|
||||
|
||||
/// Patch documents using a JSON field comparison query in the WHERE clause (->> =)
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field (patch: 'TPatch) sqlProps =
|
||||
byFields tableName Any [ field ] patch sqlProps
|
||||
|
||||
/// Patch documents using a JSON containment query in the WHERE clause (@>)
|
||||
[<CompiledName "ByContains">]
|
||||
@ -611,12 +583,6 @@ module WithProps =
|
||||
(Query.byFields (Query.removeFields tableName) howMatched fields)
|
||||
(addFieldParams fields [ fieldNameParams fieldNames ])
|
||||
sqlProps
|
||||
|
||||
/// Remove fields from documents via a comparison on a JSON field in the document
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use byFields instead; will be removed in v4">]
|
||||
let byField tableName field fieldNames sqlProps =
|
||||
byFields tableName Any [ field ] fieldNames sqlProps
|
||||
|
||||
/// Remove fields from documents via a JSON containment query (@>)
|
||||
[<CompiledName "ByContains">]
|
||||
@ -649,12 +615,6 @@ module WithProps =
|
||||
Custom.nonQuery
|
||||
(Query.byFields (Query.delete tableName) howMatched fields) (addFieldParams fields []) sqlProps
|
||||
|
||||
/// Delete documents by matching a JSON field comparison query (->> =)
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field sqlProps =
|
||||
byFields tableName Any [ field ] sqlProps
|
||||
|
||||
/// Delete documents by matching a JSON contains query (@>)
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TCriteria) sqlProps =
|
||||
@ -752,12 +712,6 @@ module Count =
|
||||
let byFields tableName howMatched fields =
|
||||
WithProps.Count.byFields tableName howMatched fields (fromDataSource ())
|
||||
|
||||
/// Count matching documents using a JSON field comparison query (->> =)
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field =
|
||||
byFields tableName Any [ field ]
|
||||
|
||||
/// Count matching documents using a JSON containment query (@>)
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName criteria =
|
||||
@ -783,12 +737,6 @@ module Exists =
|
||||
let byFields tableName howMatched fields =
|
||||
WithProps.Exists.byFields tableName howMatched fields (fromDataSource ())
|
||||
|
||||
/// Determine if documents exist using a JSON field comparison query (->> =)
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field =
|
||||
byFields tableName Any [ field ]
|
||||
|
||||
/// Determine if documents exist using a JSON containment query (@>)
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName criteria =
|
||||
@ -827,21 +775,10 @@ module Find =
|
||||
let byFields<'TDoc> tableName howMatched fields =
|
||||
WithProps.Find.byFields<'TDoc> tableName howMatched fields (fromDataSource ())
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison query (->> =)
|
||||
[<CompiledName "FSharpByField">]
|
||||
[<System.Obsolete "Use byFields instead; will be removed in v4">]
|
||||
let byField<'TDoc> tableName field =
|
||||
byFields<'TDoc> tableName Any [ field ]
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison query (->> =)
|
||||
let ByFields<'TDoc>(tableName, howMatched, fields) =
|
||||
WithProps.Find.ByFields<'TDoc>(tableName, howMatched, fields, fromDataSource ())
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison query (->> =)
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let ByField<'TDoc>(tableName, field) =
|
||||
ByFields<'TDoc>(tableName, Any, Seq.singleton field)
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>)
|
||||
[<CompiledName "FSharpByContains">]
|
||||
let byContains<'TDoc> tableName (criteria: obj) =
|
||||
@ -865,21 +802,10 @@ module Find =
|
||||
let firstByFields<'TDoc> tableName howMatched fields =
|
||||
WithProps.Find.firstByFields<'TDoc> tableName howMatched fields (fromDataSource ())
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison query (->> =); returns None if not found
|
||||
[<CompiledName "FSharpFirstByField">]
|
||||
[<System.Obsolete "Use firstByFields instead; will be removed in v4">]
|
||||
let firstByField<'TDoc> tableName field =
|
||||
firstByFields<'TDoc> tableName Any [ field ]
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison query (->> =); returns null if not found
|
||||
let FirstByFields<'TDoc when 'TDoc: null>(tableName, howMatched, fields) =
|
||||
WithProps.Find.FirstByFields<'TDoc>(tableName, howMatched, fields, fromDataSource ())
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison query (->> =); returns null if not found
|
||||
[<System.Obsolete "Use FirstByFields instead; will be removed in v4">]
|
||||
let FirstByField<'TDoc when 'TDoc: null>(tableName, field) =
|
||||
FirstByFields<'TDoc>(tableName, Any, Seq.singleton field)
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>); returns None if not found
|
||||
[<CompiledName "FSharpFirstByContains">]
|
||||
let firstByContains<'TDoc> tableName (criteria: obj) =
|
||||
@ -932,12 +858,6 @@ module Patch =
|
||||
let byFields tableName howMatched fields (patch: 'TPatch) =
|
||||
WithProps.Patch.byFields tableName howMatched fields patch (fromDataSource ())
|
||||
|
||||
/// Patch documents using a JSON field comparison query in the WHERE clause (->> =)
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field (patch: 'TPatch) =
|
||||
byFields tableName Any [ field ] patch
|
||||
|
||||
/// Patch documents using a JSON containment query in the WHERE clause (@>)
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TCriteria) (patch: 'TPatch) =
|
||||
@ -963,12 +883,6 @@ module RemoveFields =
|
||||
let byFields tableName howMatched fields fieldNames =
|
||||
WithProps.RemoveFields.byFields tableName howMatched fields fieldNames (fromDataSource ())
|
||||
|
||||
/// Remove fields from documents via a comparison on a JSON field in the document
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use byFields instead; will be removed in v4">]
|
||||
let byField tableName field fieldNames =
|
||||
byFields tableName Any [ field ] fieldNames
|
||||
|
||||
/// Remove fields from documents via a JSON containment query (@>)
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TContains) fieldNames =
|
||||
@ -994,12 +908,6 @@ module Delete =
|
||||
let byFields tableName howMatched fields =
|
||||
WithProps.Delete.byFields tableName howMatched fields (fromDataSource ())
|
||||
|
||||
/// Delete documents by matching a JSON field comparison query (->> =)
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field =
|
||||
byFields tableName Any [ field ]
|
||||
|
||||
/// Delete documents by matching a JSON containment query (@>)
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TContains) =
|
||||
|
@ -332,12 +332,6 @@ module WithConn =
|
||||
fromData<'TDoc>
|
||||
conn
|
||||
|
||||
/// Retrieve documents via a comparison on a JSON field
|
||||
[<CompiledName "FSharpByField">]
|
||||
[<System.Obsolete "Use byFields instead; will be removed in v4">]
|
||||
let byField<'TDoc> tableName field conn =
|
||||
byFields<'TDoc> tableName Any [ field ] conn
|
||||
|
||||
/// Retrieve documents via a comparison on JSON fields
|
||||
let ByFields<'TDoc>(tableName, howMatched, fields, conn) =
|
||||
Custom.List<'TDoc>(
|
||||
@ -346,11 +340,6 @@ module WithConn =
|
||||
fromData<'TDoc>,
|
||||
conn)
|
||||
|
||||
/// Retrieve documents via a comparison on a JSON field
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let ByField<'TDoc>(tableName, field, conn) =
|
||||
ByFields<'TDoc>(tableName, Any, [ field ], conn)
|
||||
|
||||
/// Retrieve documents via a comparison on JSON fields, returning only the first result
|
||||
[<CompiledName "FSharpFirstByFields">]
|
||||
let firstByFields<'TDoc> tableName howMatched fields conn =
|
||||
@ -359,12 +348,6 @@ module WithConn =
|
||||
(addFieldParams fields [])
|
||||
fromData<'TDoc>
|
||||
conn
|
||||
|
||||
/// Retrieve documents via a comparison on a JSON field, returning only the first result
|
||||
[<CompiledName "FSharpFirstByField">]
|
||||
[<System.Obsolete "Use firstByFields instead; will be removed in v4">]
|
||||
let firstByField<'TDoc> tableName field conn =
|
||||
firstByFields<'TDoc> tableName Any [ field ] conn
|
||||
|
||||
/// Retrieve documents via a comparison on JSON fields, returning only the first result
|
||||
let FirstByFields<'TDoc when 'TDoc: null>(tableName, howMatched, fields, conn) =
|
||||
@ -373,11 +356,6 @@ module WithConn =
|
||||
addFieldParams fields [],
|
||||
fromData<'TDoc>,
|
||||
conn)
|
||||
|
||||
/// Retrieve documents via a comparison on a JSON field, returning only the first result
|
||||
[<System.Obsolete "Use FirstByFields instead; will be removed in v4">]
|
||||
let FirstByField<'TDoc when 'TDoc: null>(tableName, field, conn) =
|
||||
FirstByFields(tableName, Any, [ field ], conn)
|
||||
|
||||
/// Commands to update documents
|
||||
[<RequireQualifiedAccess>]
|
||||
@ -417,13 +395,7 @@ module WithConn =
|
||||
(Query.byFields (Query.patch tableName) howMatched fields)
|
||||
(addFieldParams fields [ jsonParam "@data" patch ])
|
||||
conn
|
||||
|
||||
/// Patch documents using a comparison on a JSON field
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field (patch: 'TPatch) conn =
|
||||
byFields tableName Any [ field ] patch conn
|
||||
|
||||
|
||||
/// Commands to remove fields from documents
|
||||
[<RequireQualifiedAccess>]
|
||||
module RemoveFields =
|
||||
@ -445,12 +417,6 @@ module WithConn =
|
||||
(Query.byFields (Query.removeFields tableName nameParams) howMatched fields)
|
||||
(addFieldParams fields nameParams)
|
||||
conn
|
||||
|
||||
/// Remove fields from documents via a comparison on a JSON field in the document
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field fieldNames conn =
|
||||
byFields tableName Any [ field ] fieldNames conn
|
||||
|
||||
/// Commands to delete documents
|
||||
[<RequireQualifiedAccess>]
|
||||
@ -465,12 +431,6 @@ module WithConn =
|
||||
[<CompiledName "ByFields">]
|
||||
let byFields tableName howMatched fields conn =
|
||||
Custom.nonQuery (Query.byFields (Query.delete tableName) howMatched fields) (addFieldParams fields []) conn
|
||||
|
||||
/// Delete documents by matching a comparison on a JSON field
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field conn =
|
||||
byFields tableName Any [ field ] conn
|
||||
|
||||
|
||||
/// Commands to execute custom SQL queries
|
||||
@ -516,6 +476,7 @@ module Custom =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Custom.Scalar<'T>(query, parameters, mapFunc, conn)
|
||||
|
||||
|
||||
/// Functions to create tables and indexes
|
||||
[<RequireQualifiedAccess>]
|
||||
module Definition =
|
||||
@ -532,6 +493,7 @@ module Definition =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Definition.ensureFieldIndex tableName indexName fields conn
|
||||
|
||||
|
||||
/// Document insert/save functions
|
||||
[<AutoOpen>]
|
||||
module Document =
|
||||
@ -548,6 +510,7 @@ module Document =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.save tableName document conn
|
||||
|
||||
|
||||
/// Commands to count documents
|
||||
[<RequireQualifiedAccess>]
|
||||
module Count =
|
||||
@ -563,12 +526,7 @@ module Count =
|
||||
let byFields tableName howMatched fields =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Count.byFields tableName howMatched fields conn
|
||||
|
||||
/// Count matching documents using a comparison on a JSON field
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field =
|
||||
byFields tableName Any [ field ]
|
||||
|
||||
|
||||
/// Commands to determine if documents exist
|
||||
[<RequireQualifiedAccess>]
|
||||
@ -585,12 +543,7 @@ module Exists =
|
||||
let byFields tableName howMatched fields =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Exists.byFields tableName howMatched fields conn
|
||||
|
||||
/// Determine if a document exists using a comparison on a JSON field
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field =
|
||||
byFields tableName Any [ field ]
|
||||
|
||||
|
||||
/// Commands to determine if documents exist
|
||||
[<RequireQualifiedAccess>]
|
||||
@ -623,44 +576,23 @@ module Find =
|
||||
let byFields<'TDoc> tableName howMatched fields =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Find.byFields<'TDoc> tableName howMatched fields conn
|
||||
|
||||
/// Retrieve documents via a comparison on a JSON field
|
||||
[<CompiledName "FSharpByField">]
|
||||
[<System.Obsolete "Use byFields instead; will be removed in v4">]
|
||||
let byField<'TDoc> tableName field =
|
||||
byFields tableName Any [ field ]
|
||||
|
||||
/// Retrieve documents via a comparison on JSON fields
|
||||
let ByFields<'TDoc>(tableName, howMatched, fields) =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Find.ByFields<'TDoc>(tableName, howMatched, fields, conn)
|
||||
|
||||
/// Retrieve documents via a comparison on a JSON field
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let ByField<'TDoc>(tableName, field) =
|
||||
ByFields<'TDoc>(tableName, Any, [ field ])
|
||||
|
||||
|
||||
/// Retrieve documents via a comparison on JSON fields, returning only the first result
|
||||
[<CompiledName "FSharpFirstByFields">]
|
||||
let firstByFields<'TDoc> tableName howMatched fields =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Find.firstByFields<'TDoc> tableName howMatched fields conn
|
||||
|
||||
/// Retrieve documents via a comparison on a JSON field, returning only the first result
|
||||
[<CompiledName "FSharpFirstByField">]
|
||||
[<System.Obsolete "Use firstByFields instead; will be removed in v4">]
|
||||
let firstByField<'TDoc> tableName field =
|
||||
firstByFields<'TDoc> tableName Any [ field ]
|
||||
|
||||
/// Retrieve documents via a comparison on JSON fields, returning only the first result
|
||||
let FirstByFields<'TDoc when 'TDoc: null>(tableName, howMatched, fields) =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Find.FirstByFields<'TDoc>(tableName, howMatched, fields, conn)
|
||||
|
||||
/// Retrieve documents via a comparison on a JSON field, returning only the first result
|
||||
[<System.Obsolete "Use FirstByFields instead; will be removed in v4">]
|
||||
let FirstByField<'TDoc when 'TDoc: null>(tableName, field) =
|
||||
FirstByFields<'TDoc>(tableName, Any, [ field ])
|
||||
|
||||
|
||||
/// Commands to update documents
|
||||
[<RequireQualifiedAccess>]
|
||||
@ -683,6 +615,7 @@ module Update =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Update.ByFunc(tableName, idFunc, document, conn)
|
||||
|
||||
|
||||
/// Commands to patch (partially update) documents
|
||||
[<RequireQualifiedAccess>]
|
||||
module Patch =
|
||||
@ -698,12 +631,7 @@ module Patch =
|
||||
let byFields tableName howMatched fields (patch: 'TPatch) =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Patch.byFields tableName howMatched fields patch conn
|
||||
|
||||
/// Patch documents using a comparison on a JSON field in the WHERE clause
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field (patch: 'TPatch) =
|
||||
byFields tableName Any [ field ] patch
|
||||
|
||||
|
||||
/// Commands to remove fields from documents
|
||||
[<RequireQualifiedAccess>]
|
||||
@ -720,12 +648,7 @@ module RemoveFields =
|
||||
let byFields tableName howMatched fields fieldNames =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.RemoveFields.byFields tableName howMatched fields fieldNames conn
|
||||
|
||||
/// Remove field from documents via a comparison on a JSON field in the document
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field fieldNames =
|
||||
byFields tableName Any [ field ] fieldNames
|
||||
|
||||
|
||||
/// Commands to delete documents
|
||||
[<RequireQualifiedAccess>]
|
||||
@ -742,9 +665,3 @@ module Delete =
|
||||
let byFields tableName howMatched fields =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Delete.byFields tableName howMatched fields conn
|
||||
|
||||
/// Delete documents by matching a comparison on a JSON field
|
||||
[<CompiledName "ByField">]
|
||||
[<System.Obsolete "Use ByFields instead; will be removed in v4">]
|
||||
let byField tableName field =
|
||||
byFields tableName Any [ field ]
|
||||
|
@ -602,24 +602,27 @@ public static class PostgresCSharpTests
|
||||
var theCount = await Count.All(PostgresDb.TableName);
|
||||
Expect.equal(theCount, 5, "There should have been 5 matching documents");
|
||||
}),
|
||||
#pragma warning disable CS0618
|
||||
TestCase("ByField succeeds for numeric range", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds for numeric range", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var theCount = await Count.ByField(PostgresDb.TableName, Field.BT("NumValue", 10, 20));
|
||||
Expect.equal(theCount, 3, "There should have been 3 matching documents");
|
||||
}),
|
||||
TestCase("ByField succeeds for non-numeric range", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
var theCount = await Count.ByFields(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.BT("NumValue", 10, 20)]);
|
||||
Expect.equal(theCount, 3, "There should have been 3 matching documents");
|
||||
}),
|
||||
TestCase("succeeds for non-numeric range", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var theCount = await Count.ByField(PostgresDb.TableName, Field.BT("Value", "aardvark", "apple"));
|
||||
Expect.equal(theCount, 1, "There should have been 1 matching document");
|
||||
}),
|
||||
#pragma warning restore CS0618
|
||||
var theCount = await Count.ByFields(PostgresDb.TableName, FieldMatch.All,
|
||||
[Field.BT("Value", "aardvark", "apple")]);
|
||||
Expect.equal(theCount, 1, "There should have been 1 matching document");
|
||||
})
|
||||
]),
|
||||
TestCase("ByContains succeeds", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
@ -658,15 +661,14 @@ public static class PostgresCSharpTests
|
||||
Expect.isFalse(exists, "There should not have been an existing document");
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when documents exist", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var exists = await Exists.ByField(PostgresDb.TableName, Field.NEX("Sub"));
|
||||
var exists = await Exists.ByFields(PostgresDb.TableName, FieldMatch.Any, [Field.NEX("Sub")]);
|
||||
Expect.isTrue(exists, "There should have been existing documents");
|
||||
}),
|
||||
TestCase("succeeds when documents do not exist", async () =>
|
||||
@ -674,11 +676,11 @@ public static class PostgresCSharpTests
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var exists = await Exists.ByField(PostgresDb.TableName, Field.EQ("NumValue", "six"));
|
||||
var exists = await Exists.ByFields(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("NumValue", "six")]);
|
||||
Expect.isFalse(exists, "There should not have been existing documents");
|
||||
})
|
||||
]),
|
||||
#pragma warning restore CS0618
|
||||
TestList("ByContains",
|
||||
[
|
||||
TestCase("succeeds when documents exist", async () =>
|
||||
@ -760,15 +762,15 @@ public static class PostgresCSharpTests
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when documents are found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await Find.ByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "another"));
|
||||
var docs = await Find.ByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "another")]);
|
||||
Expect.equal(docs.Count, 1, "There should have been one document returned");
|
||||
}),
|
||||
TestCase("succeeds when documents are not found", async () =>
|
||||
@ -776,11 +778,11 @@ public static class PostgresCSharpTests
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await Find.ByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "mauve"));
|
||||
var docs = await Find.ByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "mauve")]);
|
||||
Expect.isEmpty(docs, "There should have been no documents returned");
|
||||
})
|
||||
]),
|
||||
#pragma warning restore CS0618
|
||||
TestList("ByContains",
|
||||
[
|
||||
TestCase("succeeds when documents are found", async () =>
|
||||
@ -820,15 +822,15 @@ public static class PostgresCSharpTests
|
||||
Expect.isEmpty(docs, "There should have been no documents returned");
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("FirstByField",
|
||||
TestList("FirstByFields",
|
||||
[
|
||||
TestCase("succeeds when a document is found", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await Find.FirstByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "another"));
|
||||
var doc = await Find.FirstByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "another")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal(doc.Id, "two", "The incorrect document was returned");
|
||||
}),
|
||||
@ -837,7 +839,8 @@ public static class PostgresCSharpTests
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await Find.FirstByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "purple"));
|
||||
var doc = await Find.FirstByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "purple")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.contains(new[] { "five", "four" }, doc.Id, "An incorrect document was returned");
|
||||
}),
|
||||
@ -846,11 +849,11 @@ public static class PostgresCSharpTests
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await Find.FirstByField<JsonDocument>(PostgresDb.TableName, Field.EQ("Value", "absent"));
|
||||
var doc = await Find.FirstByFields<JsonDocument>(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "absent")]);
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
]),
|
||||
#pragma warning restore CS0618
|
||||
TestList("FirstByContains",
|
||||
[
|
||||
TestCase("succeeds when a document is found", async () =>
|
||||
@ -999,16 +1002,17 @@ public static class PostgresCSharpTests
|
||||
await Patch.ById(PostgresDb.TableName, "test", new { Foo = "green" });
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Patch.ByField(PostgresDb.TableName, Field.EQ("Value", "purple"), new { NumValue = 77 });
|
||||
var after = await Count.ByField(PostgresDb.TableName, Field.EQ("NumValue", "77"));
|
||||
await Patch.ByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("Value", "purple")],
|
||||
new { NumValue = 77 });
|
||||
var after = await Count.ByFields(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("NumValue", "77")]);
|
||||
Expect.equal(after, 2, "There should have been 2 documents returned");
|
||||
}),
|
||||
TestCase("succeeds when no document is updated", async () =>
|
||||
@ -1019,10 +1023,10 @@ public static class PostgresCSharpTests
|
||||
Expect.equal(before, 0, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await Patch.ByField(PostgresDb.TableName, Field.EQ("Value", "burgundy"), new { Foo = "green" });
|
||||
await Patch.ByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("Value", "burgundy")],
|
||||
new { Foo = "green" });
|
||||
})
|
||||
]),
|
||||
#pragma warning restore CS0618
|
||||
TestList("ByContains",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
@ -1110,15 +1114,14 @@ public static class PostgresCSharpTests
|
||||
await RemoveFields.ById(PostgresDb.TableName, "two", new[] { "Value" });
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when multiple fields are removed", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await RemoveFields.ByField(PostgresDb.TableName, Field.EQ("NumValue", "17"),
|
||||
await RemoveFields.ByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", "17")],
|
||||
new[] { "Sub", "Value" });
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
@ -1130,7 +1133,8 @@ public static class PostgresCSharpTests
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await RemoveFields.ByField(PostgresDb.TableName, Field.EQ("NumValue", "17"), new[] { "Sub" });
|
||||
await RemoveFields.ByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", "17")],
|
||||
new[] { "Sub" });
|
||||
var updated = await Find.ById<string, JsonDocument>(PostgresDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.notEqual(updated.Value, "", "The string value should not have been removed");
|
||||
@ -1142,18 +1146,18 @@ public static class PostgresCSharpTests
|
||||
await LoadDocs();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await RemoveFields.ByField(PostgresDb.TableName, Field.EQ("NumValue", "17"), new[] { "Nothing" });
|
||||
await RemoveFields.ByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", "17")],
|
||||
new[] { "Nothing" });
|
||||
}),
|
||||
TestCase("succeeds when no document is matched", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await RemoveFields.ByField(PostgresDb.TableName, Field.NE("Abracadabra", "apple"),
|
||||
new[] { "Value" });
|
||||
await RemoveFields.ByFields(PostgresDb.TableName, FieldMatch.Any,
|
||||
[Field.NE("Abracadabra", "apple")], new[] { "Value" });
|
||||
})
|
||||
]),
|
||||
#pragma warning restore CS0618
|
||||
TestList("ByContains",
|
||||
[
|
||||
TestCase("succeeds when multiple fields are removed", async () =>
|
||||
@ -1262,15 +1266,14 @@ public static class PostgresCSharpTests
|
||||
Expect.equal(remaining, 5, "There should have been 5 documents remaining");
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when documents are deleted", async () =>
|
||||
{
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Delete.ByField(PostgresDb.TableName, Field.EQ("Value", "purple"));
|
||||
await Delete.ByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("Value", "purple")]);
|
||||
var remaining = await Count.All(PostgresDb.TableName);
|
||||
Expect.equal(remaining, 3, "There should have been 3 documents remaining");
|
||||
}),
|
||||
@ -1279,12 +1282,11 @@ public static class PostgresCSharpTests
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Delete.ByField(PostgresDb.TableName, Field.EQ("Value", "crimson"));
|
||||
await Delete.ByFields(PostgresDb.TableName, FieldMatch.Any, [Field.EQ("Value", "crimson")]);
|
||||
var remaining = await Count.All(PostgresDb.TableName);
|
||||
Expect.equal(remaining, 5, "There should have been 5 documents remaining");
|
||||
})
|
||||
]),
|
||||
#pragma warning restore CS0618
|
||||
TestList("ByContains",
|
||||
[
|
||||
TestCase("succeeds when documents are deleted", async () =>
|
||||
|
@ -355,24 +355,27 @@ public static class SqliteCSharpTests
|
||||
var theCount = await Count.All(SqliteDb.TableName);
|
||||
Expect.equal(theCount, 5L, "There should have been 5 matching documents");
|
||||
}),
|
||||
#pragma warning disable CS0618
|
||||
TestCase("ByField succeeds for numeric range", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds for numeric range", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var theCount = await Count.ByField(SqliteDb.TableName, Field.BT("NumValue", 10, 20));
|
||||
Expect.equal(theCount, 3L, "There should have been 3 matching documents");
|
||||
}),
|
||||
TestCase("ByField succeeds for non-numeric range", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
var theCount = await Count.ByFields(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.BT("NumValue", 10, 20)]);
|
||||
Expect.equal(theCount, 3L, "There should have been 3 matching documents");
|
||||
}),
|
||||
TestCase("succeeds for non-numeric range", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var theCount = await Count.ByField(SqliteDb.TableName, Field.BT("Value", "aardvark", "apple"));
|
||||
Expect.equal(theCount, 1L, "There should have been 1 matching document");
|
||||
})
|
||||
#pragma warning restore CS0618
|
||||
var theCount = await Count.ByFields(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.BT("Value", "aardvark", "apple")]);
|
||||
Expect.equal(theCount, 1L, "There should have been 1 matching document");
|
||||
})
|
||||
])
|
||||
]),
|
||||
TestList("Exists",
|
||||
[
|
||||
@ -395,15 +398,14 @@ public static class SqliteCSharpTests
|
||||
Expect.isFalse(exists, "There should not have been an existing document");
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when documents exist", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var exists = await Exists.ByField(SqliteDb.TableName, Field.GE("NumValue", 10));
|
||||
var exists = await Exists.ByFields(SqliteDb.TableName, FieldMatch.Any, [Field.GE("NumValue", 10)]);
|
||||
Expect.isTrue(exists, "There should have been existing documents");
|
||||
}),
|
||||
TestCase("succeeds when no matching documents exist", async () =>
|
||||
@ -411,11 +413,11 @@ public static class SqliteCSharpTests
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var exists = await Exists.ByField(SqliteDb.TableName, Field.EQ("Nothing", "none"));
|
||||
var exists = await Exists.ByFields(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Nothing", "none")]);
|
||||
Expect.isFalse(exists, "There should not have been any existing documents");
|
||||
})
|
||||
])
|
||||
#pragma warning restore CS0618
|
||||
]),
|
||||
TestList("Find",
|
||||
[
|
||||
@ -459,15 +461,15 @@ public static class SqliteCSharpTests
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when documents are found", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await Find.ByField<JsonDocument>(SqliteDb.TableName, Field.GT("NumValue", 15));
|
||||
var docs = await Find.ByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.GT("NumValue", 15)]);
|
||||
Expect.equal(docs.Count, 2, "There should have been two documents returned");
|
||||
}),
|
||||
TestCase("succeeds when documents are not found", async () =>
|
||||
@ -475,18 +477,20 @@ public static class SqliteCSharpTests
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var docs = await Find.ByField<JsonDocument>(SqliteDb.TableName, Field.EQ("Value", "mauve"));
|
||||
var docs = await Find.ByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "mauve")]);
|
||||
Expect.isEmpty(docs, "There should have been no documents returned");
|
||||
})
|
||||
]),
|
||||
TestList("FirstByField",
|
||||
TestList("FirstByFields",
|
||||
[
|
||||
TestCase("succeeds when a document is found", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await Find.FirstByField<JsonDocument>(SqliteDb.TableName, Field.EQ("Value", "another"));
|
||||
var doc = await Find.FirstByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "another")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.equal(doc!.Id, "two", "The incorrect document was returned");
|
||||
}),
|
||||
@ -495,7 +499,8 @@ public static class SqliteCSharpTests
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await Find.FirstByField<JsonDocument>(SqliteDb.TableName, Field.EQ("Sub.Foo", "green"));
|
||||
var doc = await Find.FirstByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Sub.Foo", "green")]);
|
||||
Expect.isNotNull(doc, "There should have been a document returned");
|
||||
Expect.contains(new[] { "two", "four" }, doc!.Id, "An incorrect document was returned");
|
||||
}),
|
||||
@ -504,11 +509,11 @@ public static class SqliteCSharpTests
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var doc = await Find.FirstByField<JsonDocument>(SqliteDb.TableName, Field.EQ("Value", "absent"));
|
||||
var doc = await Find.FirstByFields<JsonDocument>(SqliteDb.TableName, FieldMatch.Any,
|
||||
[Field.EQ("Value", "absent")]);
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
])
|
||||
#pragma warning restore CS0618
|
||||
]),
|
||||
TestList("Update",
|
||||
[
|
||||
@ -595,16 +600,16 @@ public static class SqliteCSharpTests
|
||||
await Patch.ById(SqliteDb.TableName, "test", new { Foo = "green" });
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Patch.ByField(SqliteDb.TableName, Field.EQ("Value", "purple"), new { NumValue = 77 });
|
||||
var after = await Count.ByField(SqliteDb.TableName, Field.EQ("NumValue", 77));
|
||||
await Patch.ByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("Value", "purple")],
|
||||
new { NumValue = 77 });
|
||||
var after = await Count.ByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", 77)]);
|
||||
Expect.equal(after, 2L, "There should have been 2 documents returned");
|
||||
}),
|
||||
TestCase("succeeds when no document is updated", async () =>
|
||||
@ -615,10 +620,10 @@ public static class SqliteCSharpTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await Patch.ByField(SqliteDb.TableName, Field.EQ("Value", "burgundy"), new { Foo = "green" });
|
||||
await Patch.ByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("Value", "burgundy")],
|
||||
new { Foo = "green" });
|
||||
})
|
||||
])
|
||||
#pragma warning restore CS0618
|
||||
]),
|
||||
TestList("RemoveFields",
|
||||
[
|
||||
@ -651,15 +656,15 @@ public static class SqliteCSharpTests
|
||||
await RemoveFields.ById(SqliteDb.TableName, "two", new[] { "Value" });
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when a field is removed", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await RemoveFields.ByField(SqliteDb.TableName, Field.EQ("NumValue", 17), new[] { "Sub" });
|
||||
await RemoveFields.ByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", 17)],
|
||||
new[] { "Sub" });
|
||||
var updated = await Find.ById<string, JsonDocument>(SqliteDb.TableName, "four");
|
||||
Expect.isNotNull(updated, "The updated document should have been retrieved");
|
||||
Expect.isNull(updated.Sub, "The sub-document should have been removed");
|
||||
@ -670,17 +675,18 @@ public static class SqliteCSharpTests
|
||||
await LoadDocs();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await RemoveFields.ByField(SqliteDb.TableName, Field.EQ("NumValue", 17), new[] { "Nothing" });
|
||||
await RemoveFields.ByFields(SqliteDb.TableName, FieldMatch.Any, [Field.EQ("NumValue", 17)],
|
||||
new[] { "Nothing" });
|
||||
}),
|
||||
TestCase("succeeds when no document is matched", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
|
||||
// This not raising an exception is the test
|
||||
await RemoveFields.ByField(SqliteDb.TableName, Field.NE("Abracadabra", "apple"), new[] { "Value" });
|
||||
await RemoveFields.ByFields(SqliteDb.TableName, FieldMatch.Any, [Field.NE("Abracadabra", "apple")],
|
||||
new[] { "Value" });
|
||||
})
|
||||
])
|
||||
#pragma warning restore CS0618
|
||||
]),
|
||||
TestList("Delete",
|
||||
[
|
||||
@ -705,15 +711,14 @@ public static class SqliteCSharpTests
|
||||
Expect.equal(remaining, 5L, "There should have been 5 documents remaining");
|
||||
})
|
||||
]),
|
||||
#pragma warning disable CS0618
|
||||
TestList("ByField",
|
||||
TestList("ByFields",
|
||||
[
|
||||
TestCase("succeeds when documents are deleted", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Delete.ByField(SqliteDb.TableName, Field.NE("Value", "purple"));
|
||||
await Delete.ByFields(SqliteDb.TableName, FieldMatch.Any, [Field.NE("Value", "purple")]);
|
||||
var remaining = await Count.All(SqliteDb.TableName);
|
||||
Expect.equal(remaining, 2L, "There should have been 2 documents remaining");
|
||||
}),
|
||||
@ -722,12 +727,11 @@ public static class SqliteCSharpTests
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Delete.ByField(SqliteDb.TableName, Field.EQ("Value", "crimson"));
|
||||
await Delete.ByFields(SqliteDb.TableName, FieldMatch.All, [Field.EQ("Value", "crimson")]);
|
||||
var remaining = await Count.All(SqliteDb.TableName);
|
||||
Expect.equal(remaining, 5L, "There should have been 5 documents remaining");
|
||||
})
|
||||
])
|
||||
#pragma warning restore CS0618
|
||||
]),
|
||||
TestCase("Clean up database", () => Sqlite.Configuration.UseConnectionString("data source=:memory:"))
|
||||
]);
|
||||
|
@ -497,22 +497,6 @@ let integrationTests =
|
||||
Expect.equal theCount 0 "There should have been no matching documents"
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testTask "succeeds for numeric range" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! theCount = Count.byField PostgresDb.TableName (Field.BT "NumValue" 10 20)
|
||||
Expect.equal theCount 3 "There should have been 3 matching documents"
|
||||
}
|
||||
testTask "succeeds for non-numeric range" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! theCount = Count.byField PostgresDb.TableName (Field.BT "Value" "aardvark" "apple")
|
||||
Expect.equal theCount 1 "There should have been 1 matching document"
|
||||
}
|
||||
]
|
||||
testTask "byContains succeeds" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
@ -562,22 +546,6 @@ let integrationTests =
|
||||
Expect.isFalse exists "There should not have been existing documents"
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testTask "succeeds when documents exist" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! exists = Exists.byField PostgresDb.TableName (Field.EX "Sub")
|
||||
Expect.isTrue exists "There should have been existing documents"
|
||||
}
|
||||
testTask "succeeds when documents do not exist" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! exists = Exists.byField PostgresDb.TableName (Field.EQ "NumValue" "six")
|
||||
Expect.isFalse exists "There should not have been existing documents"
|
||||
}
|
||||
]
|
||||
testList "byContains" [
|
||||
testTask "succeeds when documents exist" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
@ -671,22 +639,6 @@ let integrationTests =
|
||||
Expect.isEmpty docs "There should have been no documents returned"
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testTask "succeeds when documents are found" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! docs = Find.byField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "another")
|
||||
Expect.equal (List.length docs) 1 "There should have been one document returned"
|
||||
}
|
||||
testTask "succeeds when documents are not found" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! docs = Find.byField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "mauve")
|
||||
Expect.isEmpty docs "There should have been no documents returned"
|
||||
}
|
||||
]
|
||||
testList "byContains" [
|
||||
testTask "succeeds when documents are found" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
@ -719,12 +671,12 @@ let integrationTests =
|
||||
Expect.isEmpty docs "There should have been no documents returned"
|
||||
}
|
||||
]
|
||||
testList "firstByField" [
|
||||
testList "firstByFields" [
|
||||
testTask "succeeds when a document is found" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! doc = Find.firstByField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "another")
|
||||
let! doc = Find.firstByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "another" ]
|
||||
Expect.isSome doc "There should have been a document returned"
|
||||
Expect.equal doc.Value.Id "two" "The incorrect document was returned"
|
||||
}
|
||||
@ -732,7 +684,7 @@ let integrationTests =
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! doc = Find.firstByField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "purple")
|
||||
let! doc = Find.firstByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "purple" ]
|
||||
Expect.isSome doc "There should have been a document returned"
|
||||
Expect.contains [ "five"; "four" ] doc.Value.Id "An incorrect document was returned"
|
||||
}
|
||||
@ -740,7 +692,7 @@ let integrationTests =
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! doc = Find.firstByField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "absent")
|
||||
let! doc = Find.firstByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "absent" ]
|
||||
Expect.isNone doc "There should not have been a document returned"
|
||||
}
|
||||
]
|
||||
@ -867,13 +819,13 @@ let integrationTests =
|
||||
do! Patch.byId PostgresDb.TableName "test" {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testList "byFields" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Patch.byField PostgresDb.TableName (Field.EQ "Value" "purple") {| NumValue = 77 |}
|
||||
let! after = Count.byField PostgresDb.TableName (Field.EQ "NumValue" "77")
|
||||
do! Patch.byFields PostgresDb.TableName Any [ Field.EQ "Value" "purple" ] {| NumValue = 77 |}
|
||||
let! after = Count.byFields PostgresDb.TableName Any [ Field.EQ "NumValue" 77 ]
|
||||
Expect.equal after 2 "There should have been 2 documents returned"
|
||||
}
|
||||
testTask "succeeds when no document is updated" {
|
||||
@ -883,7 +835,7 @@ let integrationTests =
|
||||
Expect.equal before 0 "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! Patch.byField PostgresDb.TableName (Field.EQ "Value" "burgundy") {| Foo = "green" |}
|
||||
do! Patch.byFields PostgresDb.TableName Any [ Field.EQ "Value" "burgundy" ] {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
testList "byContains" [
|
||||
@ -932,9 +884,9 @@ let integrationTests =
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byId PostgresDb.TableName "two" [ "Sub"; "Value" ]
|
||||
let! noSubs = Count.byField PostgresDb.TableName (Field.NEX "Sub")
|
||||
let! noSubs = Count.byFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = Count.byField PostgresDb.TableName (Field.NEX "Value")
|
||||
let! noValue = Count.byFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
Expect.equal noValue 1 "There should be 1 document without Value fields"
|
||||
}
|
||||
testTask "succeeds when a single field is removed" {
|
||||
@ -942,9 +894,9 @@ let integrationTests =
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byId PostgresDb.TableName "two" [ "Sub" ]
|
||||
let! noSubs = Count.byField PostgresDb.TableName (Field.NEX "Sub")
|
||||
let! noSubs = Count.byFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = Count.byField PostgresDb.TableName (Field.NEX "Value")
|
||||
let! noValue = Count.byFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
Expect.equal noValue 0 "There should be no documents without Value fields"
|
||||
}
|
||||
testTask "succeeds when a field is not removed" {
|
||||
@ -961,25 +913,25 @@ let integrationTests =
|
||||
do! RemoveFields.byId PostgresDb.TableName "two" [ "Value" ]
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testList "byFields" [
|
||||
testTask "succeeds when multiple fields are removed" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byField PostgresDb.TableName (Field.EQ "NumValue" "17") [ "Sub"; "Value" ]
|
||||
let! noSubs = Count.byField PostgresDb.TableName (Field.NEX "Sub")
|
||||
do! RemoveFields.byFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Sub"; "Value" ]
|
||||
let! noSubs = Count.byFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = Count.byField PostgresDb.TableName (Field.NEX "Value")
|
||||
let! noValue = Count.byFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
Expect.equal noValue 1 "There should be 1 document without Value fields"
|
||||
}
|
||||
testTask "succeeds when a single field is removed" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byField PostgresDb.TableName (Field.EQ "NumValue" "17") [ "Sub" ]
|
||||
let! noSubs = Count.byField PostgresDb.TableName (Field.NEX "Sub")
|
||||
do! RemoveFields.byFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Sub" ]
|
||||
let! noSubs = Count.byFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = Count.byField PostgresDb.TableName (Field.NEX "Value")
|
||||
let! noValue = Count.byFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
Expect.equal noValue 0 "There should be no documents without Value fields"
|
||||
}
|
||||
testTask "succeeds when a field is not removed" {
|
||||
@ -987,13 +939,13 @@ let integrationTests =
|
||||
do! loadDocs ()
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! RemoveFields.byField PostgresDb.TableName (Field.EQ "NumValue" "17") [ "Nothing" ]
|
||||
do! RemoveFields.byFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Nothing" ]
|
||||
}
|
||||
testTask "succeeds when no document is matched" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! RemoveFields.byField PostgresDb.TableName (Field.NE "Abracadabra" "apple") [ "Value" ]
|
||||
do! RemoveFields.byFields PostgresDb.TableName Any [ Field.NE "Abracadabra" "apple" ] [ "Value" ]
|
||||
}
|
||||
]
|
||||
testList "byContains" [
|
||||
@ -1002,9 +954,9 @@ let integrationTests =
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byContains PostgresDb.TableName {| NumValue = 17 |} [ "Sub"; "Value" ]
|
||||
let! noSubs = Count.byField PostgresDb.TableName (Field.NEX "Sub")
|
||||
let! noSubs = Count.byFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = Count.byField PostgresDb.TableName (Field.NEX "Value")
|
||||
let! noValue = Count.byFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
Expect.equal noValue 1 "There should be 1 document without Value fields"
|
||||
}
|
||||
testTask "succeeds when a single field is removed" {
|
||||
@ -1012,9 +964,9 @@ let integrationTests =
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byContains PostgresDb.TableName {| NumValue = 17 |} [ "Sub" ]
|
||||
let! noSubs = Count.byField PostgresDb.TableName (Field.NEX "Sub")
|
||||
let! noSubs = Count.byFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = Count.byField PostgresDb.TableName (Field.NEX "Value")
|
||||
let! noValue = Count.byFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
Expect.equal noValue 0 "There should be no documents without Value fields"
|
||||
}
|
||||
testTask "succeeds when a field is not removed" {
|
||||
@ -1037,9 +989,9 @@ let integrationTests =
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byJsonPath PostgresDb.TableName "$.NumValue ? (@ == 17)" [ "Sub"; "Value" ]
|
||||
let! noSubs = Count.byField PostgresDb.TableName (Field.NEX "Sub")
|
||||
let! noSubs = Count.byFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = Count.byField PostgresDb.TableName (Field.NEX "Value")
|
||||
let! noValue = Count.byFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
Expect.equal noValue 1 "There should be 1 document without Value fields"
|
||||
}
|
||||
testTask "succeeds when a single field is removed" {
|
||||
@ -1047,9 +999,9 @@ let integrationTests =
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byJsonPath PostgresDb.TableName "$.NumValue ? (@ == 17)" [ "Sub" ]
|
||||
let! noSubs = Count.byField PostgresDb.TableName (Field.NEX "Sub")
|
||||
let! noSubs = Count.byFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = Count.byField PostgresDb.TableName (Field.NEX "Value")
|
||||
let! noValue = Count.byFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
Expect.equal noValue 0 "There should be no documents without Value fields"
|
||||
}
|
||||
testTask "succeeds when a field is not removed" {
|
||||
@ -1086,12 +1038,12 @@ let integrationTests =
|
||||
Expect.equal remaining 5 "There should have been 5 documents remaining"
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testList "byFields" [
|
||||
testTask "succeeds when documents are deleted" {
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Delete.byField PostgresDb.TableName (Field.EQ "Value" "purple")
|
||||
do! Delete.byFields PostgresDb.TableName Any [ Field.EQ "Value" "purple" ]
|
||||
let! remaining = Count.all PostgresDb.TableName
|
||||
Expect.equal remaining 3 "There should have been 3 documents remaining"
|
||||
}
|
||||
@ -1099,7 +1051,7 @@ let integrationTests =
|
||||
use db = PostgresDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Delete.byField PostgresDb.TableName (Field.EQ "Value" "crimson")
|
||||
do! Delete.byFields PostgresDb.TableName Any [ Field.EQ "Value" "crimson" ]
|
||||
let! remaining = Count.all PostgresDb.TableName
|
||||
Expect.equal remaining 5 "There should have been 5 documents remaining"
|
||||
}
|
||||
|
@ -332,20 +332,22 @@ let integrationTests =
|
||||
let! theCount = Count.all SqliteDb.TableName
|
||||
Expect.equal theCount 5L "There should have been 5 matching documents"
|
||||
}
|
||||
testTask "byField succeeds for a numeric range" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! theCount = Count.byField SqliteDb.TableName (Field.BT "NumValue" 10 20)
|
||||
Expect.equal theCount 3L "There should have been 3 matching documents"
|
||||
}
|
||||
testTask "byField succeeds for a non-numeric range" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! theCount = Count.byField SqliteDb.TableName (Field.BT "Value" "aardvark" "apple")
|
||||
Expect.equal theCount 1L "There should have been 1 matching document"
|
||||
}
|
||||
testList "byFields" [
|
||||
testTask "succeeds for a numeric range" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! theCount = Count.byFields SqliteDb.TableName Any [ Field.BT "NumValue" 10 20 ]
|
||||
Expect.equal theCount 3L "There should have been 3 matching documents"
|
||||
}
|
||||
testTask "succeeds for a non-numeric range" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! theCount = Count.byFields SqliteDb.TableName Any [ Field.BT "Value" "aardvark" "apple" ]
|
||||
Expect.equal theCount 1L "There should have been 1 matching document"
|
||||
}
|
||||
]
|
||||
]
|
||||
testList "Exists" [
|
||||
testList "byId" [
|
||||
@ -364,19 +366,19 @@ let integrationTests =
|
||||
Expect.isFalse exists "There should not have been an existing document"
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testList "byFields" [
|
||||
testTask "succeeds when documents exist" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! exists = Exists.byField SqliteDb.TableName (Field.EQ "NumValue" 10)
|
||||
let! exists = Exists.byFields SqliteDb.TableName Any [ Field.EQ "NumValue" 10 ]
|
||||
Expect.isTrue exists "There should have been existing documents"
|
||||
}
|
||||
testTask "succeeds when no matching documents exist" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! exists = Exists.byField SqliteDb.TableName (Field.LT "Nothing" "none")
|
||||
let! exists = Exists.byFields SqliteDb.TableName Any [ Field.LT "Nothing" "none" ]
|
||||
Expect.isFalse exists "There should not have been any existing documents"
|
||||
}
|
||||
]
|
||||
@ -421,28 +423,28 @@ let integrationTests =
|
||||
Expect.isFalse (Option.isSome doc) "There should not have been a document returned"
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testList "byFields" [
|
||||
testTask "succeeds when documents are found" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! docs = Find.byField<JsonDocument> SqliteDb.TableName (Field.GT "NumValue" 15)
|
||||
let! docs = Find.byFields<JsonDocument> SqliteDb.TableName Any [ Field.GT "NumValue" 15 ]
|
||||
Expect.equal (List.length docs) 2 "There should have been two documents returned"
|
||||
}
|
||||
testTask "succeeds when documents are not found" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! docs = Find.byField<JsonDocument> SqliteDb.TableName (Field.GT "NumValue" 100)
|
||||
let! docs = Find.byFields<JsonDocument> SqliteDb.TableName Any [ Field.GT "NumValue" 100 ]
|
||||
Expect.isTrue (List.isEmpty docs) "There should have been no documents returned"
|
||||
}
|
||||
]
|
||||
testList "firstByField" [
|
||||
testList "firstByFields" [
|
||||
testTask "succeeds when a document is found" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! doc = Find.firstByField<JsonDocument> SqliteDb.TableName (Field.EQ "Value" "another")
|
||||
let! doc = Find.firstByFields<JsonDocument> SqliteDb.TableName Any [ Field.EQ "Value" "another" ]
|
||||
Expect.isTrue (Option.isSome doc) "There should have been a document returned"
|
||||
Expect.equal doc.Value.Id "two" "The incorrect document was returned"
|
||||
}
|
||||
@ -450,7 +452,7 @@ let integrationTests =
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! doc = Find.firstByField<JsonDocument> SqliteDb.TableName (Field.EQ "Sub.Foo" "green")
|
||||
let! doc = Find.firstByFields<JsonDocument> SqliteDb.TableName Any [ Field.EQ "Sub.Foo" "green" ]
|
||||
Expect.isTrue (Option.isSome doc) "There should have been a document returned"
|
||||
Expect.contains [ "two"; "four" ] doc.Value.Id "An incorrect document was returned"
|
||||
}
|
||||
@ -458,7 +460,7 @@ let integrationTests =
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let! doc = Find.firstByField<JsonDocument> SqliteDb.TableName (Field.EQ "Value" "absent")
|
||||
let! doc = Find.firstByFields<JsonDocument> SqliteDb.TableName Any [ Field.EQ "Value" "absent" ]
|
||||
Expect.isFalse (Option.isSome doc) "There should not have been a document returned"
|
||||
}
|
||||
]
|
||||
@ -535,13 +537,13 @@ let integrationTests =
|
||||
do! Patch.byId SqliteDb.TableName "test" {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testList "byFields" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Patch.byField SqliteDb.TableName (Field.EQ "Value" "purple") {| NumValue = 77 |}
|
||||
let! after = Count.byField SqliteDb.TableName (Field.EQ "NumValue" 77)
|
||||
do! Patch.byFields SqliteDb.TableName Any [ Field.EQ "Value" "purple" ] {| NumValue = 77 |}
|
||||
let! after = Count.byFields SqliteDb.TableName Any [ Field.EQ "NumValue" 77 ]
|
||||
Expect.equal after 2L "There should have been 2 documents returned"
|
||||
}
|
||||
testTask "succeeds when no document is updated" {
|
||||
@ -551,7 +553,7 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! Patch.byField SqliteDb.TableName (Field.EQ "Value" "burgundy") {| Foo = "green" |}
|
||||
do! Patch.byFields SqliteDb.TableName Any [ Field.EQ "Value" "burgundy" ] {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
]
|
||||
@ -583,12 +585,12 @@ let integrationTests =
|
||||
do! RemoveFields.byId SqliteDb.TableName "two" [ "Value" ]
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testList "byFields" [
|
||||
testTask "succeeds when a field is removed" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! RemoveFields.byField SqliteDb.TableName (Field.EQ "NumValue" 17) [ "Sub" ]
|
||||
do! RemoveFields.byFields SqliteDb.TableName Any [ Field.EQ "NumValue" 17 ] [ "Sub" ]
|
||||
try
|
||||
let! _ = Find.byId<string, JsonDocument> SqliteDb.TableName "four"
|
||||
Expect.isTrue false "The updated document should have failed to parse"
|
||||
@ -601,13 +603,13 @@ let integrationTests =
|
||||
do! loadDocs ()
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! RemoveFields.byField SqliteDb.TableName (Field.EQ "NumValue" 17) [ "Nothing" ]
|
||||
do! RemoveFields.byFields SqliteDb.TableName Any [ Field.EQ "NumValue" 17 ] [ "Nothing" ]
|
||||
}
|
||||
testTask "succeeds when no document is matched" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! RemoveFields.byField SqliteDb.TableName (Field.NE "Abracadabra" "apple") [ "Value" ]
|
||||
do! RemoveFields.byFields SqliteDb.TableName Any [ Field.NE "Abracadabra" "apple" ] [ "Value" ]
|
||||
}
|
||||
]
|
||||
]
|
||||
@ -630,12 +632,12 @@ let integrationTests =
|
||||
Expect.equal remaining 5L "There should have been 5 documents remaining"
|
||||
}
|
||||
]
|
||||
testList "byField" [
|
||||
testList "byFields" [
|
||||
testTask "succeeds when documents are deleted" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Delete.byField SqliteDb.TableName (Field.NE "Value" "purple")
|
||||
do! Delete.byFields SqliteDb.TableName Any [ Field.NE "Value" "purple" ]
|
||||
let! remaining = Count.all SqliteDb.TableName
|
||||
Expect.equal remaining 2L "There should have been 2 documents remaining"
|
||||
}
|
||||
@ -643,7 +645,7 @@ let integrationTests =
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Delete.byField SqliteDb.TableName (Field.EQ "Value" "crimson")
|
||||
do! Delete.byFields SqliteDb.TableName Any [ Field.EQ "Value" "crimson" ]
|
||||
let! remaining = Count.all SqliteDb.TableName
|
||||
Expect.equal remaining 5L "There should have been 5 documents remaining"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user