Version 4 rc1 (#6)

Changes in this version:
- **BREAKING CHANGE**: All `*byField`/`*ByField` functions are now `*byFields`/`*ByFields`, and take a `FieldMatch` case before the list of fields. The `Compat` namespace in both libraries will assist in this transition. In support of this change, the `Field` parameter name is optional; the library will generate parameter names for it if they are not specified.
- **BREAKING CHANGE**: The `Query` namespaces have had some significant work, particularly from the full-query perspective. Most have been broken up into the base query and modifiers `by*` that will combine the base query with the `WHERE` clause needed to satisfy the criteria.
- **FEATURE / BREAKING CHANGE**: PostgreSQL document fields will now be cast to numeric if the parameter value passed to the query is numeric. This drove the `Query` breaking changes, as the fields need to have their intended value for the library to generate the appropriate SQL. Additionally, if code assumes the library can be given something like `8` and transform it to `"8"`, this is no longer the case.
- **FEATURE**: All `Find` queries (except `byId`/`ById`) now have a version with the `Ordered` suffix. These take a list of fields by which the query should be ordered. A new `Field` method called `Named` can assist with creating these fields. Prefixing the field name with `n:` will cast the field to numeric in PostgreSQL (and will be ignored by SQLite); adding " DESC" to the field name will sort it descending (Z-A, high to low) instead of ascending (A-Z, low to high).
- **BREAKING CHANGE** (PostgreSQL only): `fieldNameParam`/`Parameters.FieldName` are now plural. The function still only generates one parameter, but the name is now the same between PostgreSQL and SQLite. The goal of this library is to abstract the differences away as much as practical, and this furthers that end. There are functions with these names in the `Compat` namespace.
- **FEATURE**: In the F# v3 library, lists of parameters were expected to be F#'s `List` type, and the C# version took either `List<T>` or `IEnumerable<T>`. In this version, these all expect `seq`/`IEnumerable<T>`. F#'s `List` satisfies the `seq` constraints, so this should not be a breaking change.
- **FEATURE**: `Field`s now may have qualifiers; this allows tables to be aliased when joining multiple tables (as all have the same `data` column). F# users can use `with` to specify this at creation, and both F# and C# can use the `WithQualifier` method to create a field with the qualifier specified. Parameter names for fields may be specified in a similar way, substituting `ParameterName` for `Qualifier`.

Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
2024-08-19 23:30:38 +00:00
parent 039761fcca
commit 2c24e2e912
27 changed files with 8162 additions and 4943 deletions

View File

@@ -25,7 +25,7 @@ let integrationTests =
use conn = mkConn db
do! loadDocs conn
let! docs = conn.customList (Query.selectFromTable PostgresDb.TableName) [] fromData<JsonDocument>
let! docs = conn.customList (Query.find PostgresDb.TableName) [] fromData<JsonDocument>
Expect.equal (List.length docs) 5 "There should have been 5 documents returned"
}
testTask "succeeds when data is not found" {
@@ -209,12 +209,12 @@ let integrationTests =
let! theCount = conn.countAll PostgresDb.TableName
Expect.equal theCount 5 "There should have been 5 matching documents"
}
testTask "countByField succeeds" {
testTask "countByFields succeeds" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! theCount = conn.countByField PostgresDb.TableName (Field.EQ "Value" "purple")
let! theCount = conn.countByFields PostgresDb.TableName Any [ Field.EQ "Value" "purple" ]
Expect.equal theCount 2 "There should have been 2 matching documents"
}
testTask "countByContains succeeds" {
@@ -251,13 +251,13 @@ let integrationTests =
Expect.isFalse exists "There should not have been an existing document"
}
]
testList "existsByField" [
testList "existsByFields" [
testTask "succeeds when documents exist" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! exists = conn.existsByField PostgresDb.TableName (Field.EX "Sub")
let! exists = conn.existsByFields PostgresDb.TableName Any [ Field.EX "Sub" ]
Expect.isTrue exists "There should have been existing documents"
}
testTask "succeeds when documents do not exist" {
@@ -265,7 +265,7 @@ let integrationTests =
use conn = mkConn db
do! loadDocs conn
let! exists = conn.existsByField PostgresDb.TableName (Field.EQ "NumValue" "six")
let! exists = conn.existsByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "six" ]
Expect.isFalse exists "There should not have been existing documents"
}
]
@@ -315,12 +315,10 @@ let integrationTests =
do! conn.insert PostgresDb.TableName { Foo = "five"; Bar = "six" }
let! results = conn.findAll<SubDocument> PostgresDb.TableName
let expected = [
{ Foo = "one"; Bar = "two" }
{ Foo = "three"; Bar = "four" }
{ Foo = "five"; Bar = "six" }
]
Expect.equal results expected "There should have been 3 documents returned"
Expect.equal
results
[ { Foo = "one"; Bar = "two" }; { Foo = "three"; Bar = "four" }; { Foo = "five"; Bar = "six" } ]
"There should have been 3 documents returned"
}
testTask "succeeds when there is no data" {
use db = PostgresDb.BuildDb()
@@ -329,6 +327,44 @@ let integrationTests =
Expect.equal results [] "There should have been no documents returned"
}
]
testList "findAllOrdered" [
testTask "succeeds when ordering numerically" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! results = conn.findAllOrdered<JsonDocument> PostgresDb.TableName [ Field.Named "n:NumValue" ]
Expect.hasLength results 5 "There should have been 5 documents returned"
Expect.equal
(results |> List.map _.Id |> String.concat "|")
"one|three|two|four|five"
"The documents were not ordered correctly"
}
testTask "succeeds when ordering numerically descending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! results = conn.findAllOrdered<JsonDocument> PostgresDb.TableName [ Field.Named "n:NumValue DESC" ]
Expect.hasLength results 5 "There should have been 5 documents returned"
Expect.equal
(results |> List.map _.Id |> String.concat "|")
"five|four|two|three|one"
"The documents were not ordered correctly"
}
testTask "succeeds when ordering alphabetically" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! results = conn.findAllOrdered<JsonDocument> PostgresDb.TableName [ Field.Named "Id DESC" ]
Expect.hasLength results 5 "There should have been 5 documents returned"
Expect.equal
(results |> List.map _.Id |> String.concat "|")
"two|three|one|four|five"
"The documents were not ordered correctly"
}
]
testList "findById" [
testTask "succeeds when a document is found" {
use db = PostgresDb.BuildDb()
@@ -348,13 +384,13 @@ let integrationTests =
Expect.isNone doc "There should not have been a document returned"
}
]
testList "findByField" [
testList "findByFields" [
testTask "succeeds when documents are found" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! docs = conn.findByField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "another")
let! docs = conn.findByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "another" ]
Expect.equal (List.length docs) 1 "There should have been one document returned"
}
testTask "succeeds when documents are not found" {
@@ -362,10 +398,36 @@ let integrationTests =
use conn = mkConn db
do! loadDocs conn
let! docs = conn.findByField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "mauve")
let! docs = conn.findByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "mauve" ]
Expect.isEmpty docs "There should have been no documents returned"
}
]
testList "findByFieldsOrdered" [
testTask "succeeds when sorting ascending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! docs =
conn.findByFieldsOrdered<JsonDocument>
PostgresDb.TableName All [ Field.EQ "Value" "purple" ] [ Field.Named "Id" ]
Expect.hasLength docs 2 "There should have been two documents returned"
Expect.equal
(docs |> List.map _.Id |> String.concat "|") "five|four" "Documents not ordered correctly"
}
testTask "succeeds when sorting descending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! docs =
conn.findByFieldsOrdered<JsonDocument>
PostgresDb.TableName All [ Field.EQ "Value" "purple" ] [ Field.Named "Id DESC" ]
Expect.hasLength docs 2 "There should have been two documents returned"
Expect.equal
(docs |> List.map _.Id |> String.concat "|") "four|five" "Documents not ordered correctly"
}
]
testList "findByContains" [
testTask "succeeds when documents are found" {
use db = PostgresDb.BuildDb()
@@ -384,6 +446,33 @@ let integrationTests =
Expect.isEmpty docs "There should have been no documents returned"
}
]
testList "findByContainsOrdered" [
// Id = two, Sub.Bar = blue; Id = four, Sub.Bar = red
testTask "succeeds when sorting ascending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! docs =
conn.findByContainsOrdered<JsonDocument>
PostgresDb.TableName {| Sub = {| Foo = "green" |} |} [ Field.Named "Sub.Bar" ]
Expect.hasLength docs 2 "There should have been two documents returned"
Expect.equal
(docs |> List.map _.Id |> String.concat "|") "two|four" "Documents not ordered correctly"
}
testTask "succeeds when sorting descending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! docs =
conn.findByContainsOrdered<JsonDocument>
PostgresDb.TableName {| Sub = {| Foo = "green" |} |} [ Field.Named "Sub.Bar DESC" ]
Expect.hasLength docs 2 "There should have been two documents returned"
Expect.equal
(docs |> List.map _.Id |> String.concat "|") "four|two" "Documents not ordered correctly"
}
]
testList "findByJsonPath" [
testTask "succeeds when documents are found" {
use db = PostgresDb.BuildDb()
@@ -402,13 +491,40 @@ let integrationTests =
Expect.isEmpty docs "There should have been no documents returned"
}
]
testList "findFirstByField" [
testList "findByJsonPathOrdered" [
// Id = one, NumValue = 0; Id = two, NumValue = 10; Id = three, NumValue = 4
testTask "succeeds when sorting ascending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! docs =
conn.findByJsonPathOrdered<JsonDocument>
PostgresDb.TableName "$.NumValue ? (@ < 15)" [ Field.Named "n:NumValue" ]
Expect.hasLength docs 3 "There should have been 3 documents returned"
Expect.equal
(docs |> List.map _.Id |> String.concat "|") "one|three|two" "Documents not ordered correctly"
}
testTask "succeeds when sorting descending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! docs =
conn.findByJsonPathOrdered<JsonDocument>
PostgresDb.TableName "$.NumValue ? (@ < 15)" [ Field.Named "n:NumValue DESC" ]
Expect.hasLength docs 3 "There should have been 3 documents returned"
Expect.equal
(docs |> List.map _.Id |> String.concat "|") "two|three|one" "Documents not ordered correctly"
}
]
testList "findFirstByFields" [
testTask "succeeds when a document is found" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! doc = conn.findFirstByField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "another")
let! doc = conn.findFirstByFields<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"
}
@@ -417,7 +533,7 @@ let integrationTests =
use conn = mkConn db
do! loadDocs conn
let! doc = conn.findFirstByField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "purple")
let! doc = conn.findFirstByFields<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"
}
@@ -426,10 +542,34 @@ let integrationTests =
use conn = mkConn db
do! loadDocs conn
let! doc = conn.findFirstByField<JsonDocument> PostgresDb.TableName (Field.EQ "Value" "absent")
let! doc = conn.findFirstByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "absent" ]
Expect.isNone doc "There should not have been a document returned"
}
]
testList "findFirstByFieldsOrdered" [
testTask "succeeds when sorting ascending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! doc =
conn.findFirstByFieldsOrdered<JsonDocument>
PostgresDb.TableName Any [ Field.EQ "Value" "purple" ] [ Field.Named "Id" ]
Expect.isSome doc "There should have been a document returned"
Expect.equal "five" doc.Value.Id "An incorrect document was returned"
}
testTask "succeeds when sorting descending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! doc =
conn.findFirstByFieldsOrdered<JsonDocument>
PostgresDb.TableName Any [ Field.EQ "Value" "purple" ] [ Field.Named "Id DESC" ]
Expect.isSome doc "There should have been a document returned"
Expect.equal "four" doc.Value.Id "An incorrect document was returned"
}
]
testList "findFirstByContains" [
testTask "succeeds when a document is found" {
use db = PostgresDb.BuildDb()
@@ -458,6 +598,30 @@ let integrationTests =
Expect.isNone doc "There should not have been a document returned"
}
]
testList "findFirstByContainsOrdered" [
testTask "succeeds when sorting ascending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! doc =
conn.findFirstByContainsOrdered<JsonDocument>
PostgresDb.TableName {| Sub = {| Foo = "green" |} |} [ Field.Named "Value" ]
Expect.isSome doc "There should have been a document returned"
Expect.equal "two" doc.Value.Id "An incorrect document was returned"
}
testTask "succeeds when sorting descending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! doc =
conn.findFirstByContainsOrdered<JsonDocument>
PostgresDb.TableName {| Sub = {| Foo = "green" |} |} [ Field.Named "Value DESC" ]
Expect.isSome doc "There should have been a document returned"
Expect.equal "four" doc.Value.Id "An incorrect document was returned"
}
]
testList "findFirstByJsonPath" [
testTask "succeeds when a document is found" {
use db = PostgresDb.BuildDb()
@@ -486,6 +650,30 @@ let integrationTests =
Expect.isNone doc "There should not have been a document returned"
}
]
testList "findFirstByJsonPathOrdered" [
testTask "succeeds when sorting ascending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! doc =
conn.findFirstByJsonPathOrdered<JsonDocument>
PostgresDb.TableName """$.Sub.Foo ? (@ == "green")""" [ Field.Named "Sub.Bar" ]
Expect.isSome doc "There should have been a document returned"
Expect.equal "two" doc.Value.Id "An incorrect document was returned"
}
testTask "succeeds when sorting descending" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
let! doc =
conn.findFirstByJsonPathOrdered<JsonDocument>
PostgresDb.TableName """$.Sub.Foo ? (@ == "green")""" [ Field.Named "Sub.Bar DESC" ]
Expect.isSome doc "There should have been a document returned"
Expect.equal "four" doc.Value.Id "An incorrect document was returned"
}
]
testList "updateById" [
testTask "succeeds when a document is updated" {
use db = PostgresDb.BuildDb()
@@ -556,14 +744,14 @@ let integrationTests =
do! conn.patchById PostgresDb.TableName "test" {| Foo = "green" |}
}
]
testList "patchByField" [
testList "patchByFields" [
testTask "succeeds when a document is updated" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
do! conn.patchByField PostgresDb.TableName (Field.EQ "Value" "purple") {| NumValue = 77 |}
let! after = conn.countByField PostgresDb.TableName (Field.EQ "NumValue" "77")
do! conn.patchByFields PostgresDb.TableName Any [ Field.EQ "Value" "purple" ] {| NumValue = 77 |}
let! after = conn.countByFields 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" {
@@ -573,7 +761,7 @@ let integrationTests =
Expect.equal before 0 "There should have been no documents returned"
// This not raising an exception is the test
do! conn.patchByField PostgresDb.TableName (Field.EQ "Value" "burgundy") {| Foo = "green" |}
do! conn.patchByFields PostgresDb.TableName Any [ Field.EQ "Value" "burgundy" ] {| Foo = "green" |}
}
]
testList "patchByContains" [
@@ -623,9 +811,9 @@ let integrationTests =
do! loadDocs conn
do! conn.removeFieldsById PostgresDb.TableName "two" [ "Sub"; "Value" ]
let! noSubs = conn.countByField PostgresDb.TableName (Field.NEX "Sub")
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
let! noValue = conn.countByField PostgresDb.TableName (Field.NEX "Value")
let! noValue = conn.countByFields 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" {
@@ -634,9 +822,9 @@ let integrationTests =
do! loadDocs conn
do! conn.removeFieldsById PostgresDb.TableName "two" [ "Sub" ]
let! noSubs = conn.countByField PostgresDb.TableName (Field.NEX "Sub")
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
let! noValue = conn.countByField PostgresDb.TableName (Field.NEX "Value")
let! noValue = conn.countByFields 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" {
@@ -655,16 +843,16 @@ let integrationTests =
do! conn.removeFieldsById PostgresDb.TableName "two" [ "Value" ]
}
]
testList "removeFieldsByField" [
testList "removeFieldsByFields" [
testTask "succeeds when multiple fields are removed" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
do! conn.removeFieldsByField PostgresDb.TableName (Field.EQ "NumValue" "17") [ "Sub"; "Value" ]
let! noSubs = conn.countByField PostgresDb.TableName (Field.NEX "Sub")
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Sub"; "Value" ]
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
let! noValue = conn.countByField PostgresDb.TableName (Field.NEX "Value")
let! noValue = conn.countByFields 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" {
@@ -672,10 +860,10 @@ let integrationTests =
use conn = mkConn db
do! loadDocs conn
do! conn.removeFieldsByField PostgresDb.TableName (Field.EQ "NumValue" "17") [ "Sub" ]
let! noSubs = conn.countByField PostgresDb.TableName (Field.NEX "Sub")
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Sub" ]
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
let! noValue = conn.countByField PostgresDb.TableName (Field.NEX "Value")
let! noValue = conn.countByFields 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" {
@@ -684,14 +872,14 @@ let integrationTests =
do! loadDocs conn
// This not raising an exception is the test
do! conn.removeFieldsByField PostgresDb.TableName (Field.EQ "NumValue" "17") [ "Nothing" ]
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Nothing" ]
}
testTask "succeeds when no document is matched" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
// This not raising an exception is the test
do! conn.removeFieldsByField PostgresDb.TableName (Field.NE "Abracadabra" "apple") [ "Value" ]
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.NE "Abracadabra" "apple" ] [ "Value" ]
}
]
testList "removeFieldsByContains" [
@@ -701,9 +889,9 @@ let integrationTests =
do! loadDocs conn
do! conn.removeFieldsByContains PostgresDb.TableName {| NumValue = 17 |} [ "Sub"; "Value" ]
let! noSubs = conn.countByField PostgresDb.TableName (Field.NEX "Sub")
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
let! noValue = conn.countByField PostgresDb.TableName (Field.NEX "Value")
let! noValue = conn.countByFields 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" {
@@ -712,9 +900,9 @@ let integrationTests =
do! loadDocs conn
do! conn.removeFieldsByContains PostgresDb.TableName {| NumValue = 17 |} [ "Sub" ]
let! noSubs = conn.countByField PostgresDb.TableName (Field.NEX "Sub")
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
let! noValue = conn.countByField PostgresDb.TableName (Field.NEX "Value")
let! noValue = conn.countByFields 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" {
@@ -740,9 +928,9 @@ let integrationTests =
do! loadDocs conn
do! conn.removeFieldsByJsonPath PostgresDb.TableName "$.NumValue ? (@ == 17)" [ "Sub"; "Value" ]
let! noSubs = conn.countByField PostgresDb.TableName (Field.NEX "Sub")
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
let! noValue = conn.countByField PostgresDb.TableName (Field.NEX "Value")
let! noValue = conn.countByFields 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" {
@@ -751,9 +939,9 @@ let integrationTests =
do! loadDocs conn
do! conn.removeFieldsByJsonPath PostgresDb.TableName "$.NumValue ? (@ == 17)" [ "Sub" ]
let! noSubs = conn.countByField PostgresDb.TableName (Field.NEX "Sub")
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
let! noValue = conn.countByField PostgresDb.TableName (Field.NEX "Value")
let! noValue = conn.countByFields 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" {
@@ -792,13 +980,13 @@ let integrationTests =
Expect.equal remaining 5 "There should have been 5 documents remaining"
}
]
testList "deleteByField" [
testList "deleteByFields" [
testTask "succeeds when documents are deleted" {
use db = PostgresDb.BuildDb()
use conn = mkConn db
do! loadDocs conn
do! conn.deleteByField PostgresDb.TableName (Field.EQ "Value" "purple")
do! conn.deleteByFields PostgresDb.TableName Any [ Field.EQ "Value" "purple" ]
let! remaining = conn.countAll PostgresDb.TableName
Expect.equal remaining 3 "There should have been 3 documents remaining"
}
@@ -807,7 +995,7 @@ let integrationTests =
use conn = mkConn db
do! loadDocs conn
do! conn.deleteByField PostgresDb.TableName (Field.EQ "Value" "crimson")
do! conn.deleteByFields PostgresDb.TableName Any [ Field.EQ "Value" "crimson" ]
let! remaining = conn.countAll PostgresDb.TableName
Expect.equal remaining 5 "There should have been 5 documents remaining"
}