RC4 changes (#7)
- Add `In` and `InArray` comparisons - Replace `Op` with `Comparison` (internal API, but was public) - Spell out comparisons in `Field` constructor functions Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
@@ -214,7 +214,7 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
let! theCount = conn.countByFields PostgresDb.TableName Any [ Field.EQ "Value" "purple" ]
|
||||
let! theCount = conn.countByFields PostgresDb.TableName Any [ Field.Equal "Value" "purple" ]
|
||||
Expect.equal theCount 2 "There should have been 2 matching documents"
|
||||
}
|
||||
testTask "countByContains succeeds" {
|
||||
@@ -257,7 +257,7 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
let! exists = conn.existsByFields PostgresDb.TableName Any [ Field.EX "Sub" ]
|
||||
let! exists = conn.existsByFields PostgresDb.TableName Any [ Field.Exists "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.existsByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "six" ]
|
||||
let! exists = conn.existsByFields PostgresDb.TableName Any [ Field.Equal "NumValue" "six" ]
|
||||
Expect.isFalse exists "There should not have been existing documents"
|
||||
}
|
||||
]
|
||||
@@ -390,7 +390,7 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
let! docs = conn.findByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "another" ]
|
||||
let! docs = conn.findByFields<JsonDocument> PostgresDb.TableName Any [ Field.Equal "Value" "another" ]
|
||||
Expect.equal (List.length docs) 1 "There should have been one document returned"
|
||||
}
|
||||
testTask "succeeds when documents are not found" {
|
||||
@@ -398,7 +398,7 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
let! docs = conn.findByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "mauve" ]
|
||||
let! docs = conn.findByFields<JsonDocument> PostgresDb.TableName Any [ Field.Equal "Value" "mauve" ]
|
||||
Expect.isEmpty docs "There should have been no documents returned"
|
||||
}
|
||||
]
|
||||
@@ -410,7 +410,7 @@ let integrationTests =
|
||||
|
||||
let! docs =
|
||||
conn.findByFieldsOrdered<JsonDocument>
|
||||
PostgresDb.TableName All [ Field.EQ "Value" "purple" ] [ Field.Named "Id" ]
|
||||
PostgresDb.TableName All [ Field.Equal "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"
|
||||
@@ -422,7 +422,7 @@ let integrationTests =
|
||||
|
||||
let! docs =
|
||||
conn.findByFieldsOrdered<JsonDocument>
|
||||
PostgresDb.TableName All [ Field.EQ "Value" "purple" ] [ Field.Named "Id DESC" ]
|
||||
PostgresDb.TableName All [ Field.Equal "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"
|
||||
@@ -524,7 +524,8 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
let! doc = conn.findFirstByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "another" ]
|
||||
let! doc =
|
||||
conn.findFirstByFields<JsonDocument> PostgresDb.TableName Any [ Field.Equal "Value" "another" ]
|
||||
Expect.isSome doc "There should have been a document returned"
|
||||
Expect.equal doc.Value.Id "two" "The incorrect document was returned"
|
||||
}
|
||||
@@ -533,7 +534,8 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
let! doc = conn.findFirstByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "purple" ]
|
||||
let! doc =
|
||||
conn.findFirstByFields<JsonDocument> PostgresDb.TableName Any [ Field.Equal "Value" "purple" ]
|
||||
Expect.isSome doc "There should have been a document returned"
|
||||
Expect.contains [ "five"; "four" ] doc.Value.Id "An incorrect document was returned"
|
||||
}
|
||||
@@ -542,7 +544,8 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
let! doc = conn.findFirstByFields<JsonDocument> PostgresDb.TableName Any [ Field.EQ "Value" "absent" ]
|
||||
let! doc =
|
||||
conn.findFirstByFields<JsonDocument> PostgresDb.TableName Any [ Field.Equal "Value" "absent" ]
|
||||
Expect.isNone doc "There should not have been a document returned"
|
||||
}
|
||||
]
|
||||
@@ -554,7 +557,7 @@ let integrationTests =
|
||||
|
||||
let! doc =
|
||||
conn.findFirstByFieldsOrdered<JsonDocument>
|
||||
PostgresDb.TableName Any [ Field.EQ "Value" "purple" ] [ Field.Named "Id" ]
|
||||
PostgresDb.TableName Any [ Field.Equal "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"
|
||||
}
|
||||
@@ -565,7 +568,7 @@ let integrationTests =
|
||||
|
||||
let! doc =
|
||||
conn.findFirstByFieldsOrdered<JsonDocument>
|
||||
PostgresDb.TableName Any [ Field.EQ "Value" "purple" ] [ Field.Named "Id DESC" ]
|
||||
PostgresDb.TableName Any [ Field.Equal "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"
|
||||
}
|
||||
@@ -750,8 +753,8 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.patchByFields PostgresDb.TableName Any [ Field.EQ "Value" "purple" ] {| NumValue = 77 |}
|
||||
let! after = conn.countByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "77" ]
|
||||
do! conn.patchByFields PostgresDb.TableName Any [ Field.Equal "Value" "purple" ] {| NumValue = 77 |}
|
||||
let! after = conn.countByFields PostgresDb.TableName Any [ Field.Equal "NumValue" "77" ]
|
||||
Expect.equal after 2 "There should have been 2 documents returned"
|
||||
}
|
||||
testTask "succeeds when no document is updated" {
|
||||
@@ -761,7 +764,7 @@ let integrationTests =
|
||||
Expect.equal before 0 "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! conn.patchByFields PostgresDb.TableName Any [ Field.EQ "Value" "burgundy" ] {| Foo = "green" |}
|
||||
do! conn.patchByFields PostgresDb.TableName Any [ Field.Equal "Value" "burgundy" ] {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
testList "patchByContains" [
|
||||
@@ -811,9 +814,9 @@ let integrationTests =
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.removeFieldsById PostgresDb.TableName "two" [ "Sub"; "Value" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Value" ]
|
||||
Expect.equal noValue 1 "There should be 1 document without Value fields"
|
||||
}
|
||||
testTask "succeeds when a single field is removed" {
|
||||
@@ -822,9 +825,9 @@ let integrationTests =
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.removeFieldsById PostgresDb.TableName "two" [ "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Value" ]
|
||||
Expect.equal noValue 0 "There should be no documents without Value fields"
|
||||
}
|
||||
testTask "succeeds when a field is not removed" {
|
||||
@@ -849,10 +852,11 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Sub"; "Value" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
do! conn.removeFieldsByFields
|
||||
PostgresDb.TableName Any [ Field.Equal "NumValue" "17" ] [ "Sub"; "Value" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Value" ]
|
||||
Expect.equal noValue 1 "There should be 1 document without Value fields"
|
||||
}
|
||||
testTask "succeeds when a single field is removed" {
|
||||
@@ -860,10 +864,10 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.Equal "NumValue" "17" ] [ "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Value" ]
|
||||
Expect.equal noValue 0 "There should be no documents without Value fields"
|
||||
}
|
||||
testTask "succeeds when a field is not removed" {
|
||||
@@ -872,14 +876,15 @@ let integrationTests =
|
||||
do! loadDocs conn
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.EQ "NumValue" "17" ] [ "Nothing" ]
|
||||
do! conn.removeFieldsByFields PostgresDb.TableName Any [ Field.Equal "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.removeFieldsByFields PostgresDb.TableName Any [ Field.NE "Abracadabra" "apple" ] [ "Value" ]
|
||||
do! conn.removeFieldsByFields
|
||||
PostgresDb.TableName Any [ Field.NotEqual "Abracadabra" "apple" ] [ "Value" ]
|
||||
}
|
||||
]
|
||||
testList "removeFieldsByContains" [
|
||||
@@ -889,9 +894,9 @@ let integrationTests =
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.removeFieldsByContains PostgresDb.TableName {| NumValue = 17 |} [ "Sub"; "Value" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Value" ]
|
||||
Expect.equal noValue 1 "There should be 1 document without Value fields"
|
||||
}
|
||||
testTask "succeeds when a single field is removed" {
|
||||
@@ -900,9 +905,9 @@ let integrationTests =
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.removeFieldsByContains PostgresDb.TableName {| NumValue = 17 |} [ "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Value" ]
|
||||
Expect.equal noValue 0 "There should be no documents without Value fields"
|
||||
}
|
||||
testTask "succeeds when a field is not removed" {
|
||||
@@ -928,9 +933,9 @@ let integrationTests =
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.removeFieldsByJsonPath PostgresDb.TableName "$.NumValue ? (@ == 17)" [ "Sub"; "Value" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Value" ]
|
||||
Expect.equal noValue 1 "There should be 1 document without Value fields"
|
||||
}
|
||||
testTask "succeeds when a single field is removed" {
|
||||
@@ -939,9 +944,9 @@ let integrationTests =
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.removeFieldsByJsonPath PostgresDb.TableName "$.NumValue ? (@ == 17)" [ "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Sub" ]
|
||||
let! noSubs = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Sub" ]
|
||||
Expect.equal noSubs 4 "There should now be 4 documents without Sub fields"
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NEX "Value" ]
|
||||
let! noValue = conn.countByFields PostgresDb.TableName Any [ Field.NotExists "Value" ]
|
||||
Expect.equal noValue 0 "There should be no documents without Value fields"
|
||||
}
|
||||
testTask "succeeds when a field is not removed" {
|
||||
@@ -986,7 +991,7 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.deleteByFields PostgresDb.TableName Any [ Field.EQ "Value" "purple" ]
|
||||
do! conn.deleteByFields PostgresDb.TableName Any [ Field.Equal "Value" "purple" ]
|
||||
let! remaining = conn.countAll PostgresDb.TableName
|
||||
Expect.equal remaining 3 "There should have been 3 documents remaining"
|
||||
}
|
||||
@@ -995,7 +1000,7 @@ let integrationTests =
|
||||
use conn = mkConn db
|
||||
do! loadDocs conn
|
||||
|
||||
do! conn.deleteByFields PostgresDb.TableName Any [ Field.EQ "Value" "crimson" ]
|
||||
do! conn.deleteByFields PostgresDb.TableName Any [ Field.Equal "Value" "crimson" ]
|
||||
let! remaining = conn.countAll PostgresDb.TableName
|
||||
Expect.equal remaining 5 "There should have been 5 documents remaining"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user