Version 4 #6
|
@ -121,15 +121,17 @@ module Query =
|
||||||
|> Seq.map (fun it ->
|
|> Seq.map (fun it ->
|
||||||
match it.Op with
|
match it.Op with
|
||||||
| EX | NEX -> $"{it.PgSqlPath} {it.Op}"
|
| EX | NEX -> $"{it.PgSqlPath} {it.Op}"
|
||||||
| BT ->
|
| _ ->
|
||||||
let p = name.Derive it.ParameterName
|
let p = name.Derive it.ParameterName
|
||||||
let names = $"{p}min AND {p}max"
|
let path, value =
|
||||||
let values = it.Value :?> obj list
|
match it.Op with
|
||||||
match values[0] with
|
| BT -> $"{p}min AND {p}max", (it.Value :?> obj list)[0]
|
||||||
|
| _ -> p, it.Value
|
||||||
|
printfn $"%A{value}"
|
||||||
|
match value with
|
||||||
| :? int8 | :? uint8 | :? int16 | :? uint16 | :? int | :? uint32 | :? int64 | :? uint64
|
| :? int8 | :? uint8 | :? int16 | :? uint16 | :? int | :? uint32 | :? int64 | :? uint64
|
||||||
| :? decimal | :? single | :? double -> $"({it.PgSqlPath})::numeric {it.Op} {names}"
|
| :? decimal | :? single | :? double -> $"({it.PgSqlPath})::numeric {it.Op} {path}"
|
||||||
| _ -> $"{it.PgSqlPath} {it.Op} {names}"
|
| _ -> $"{it.PgSqlPath} {it.Op} {path}")
|
||||||
| _ -> $"{it.PgSqlPath} {it.Op} {name.Derive it.ParameterName}")
|
|
||||||
|> String.concat (match howMatched with Any -> " OR " | All -> " AND ")
|
|> String.concat (match howMatched with Any -> " OR " | All -> " AND ")
|
||||||
|
|
||||||
/// Create a WHERE clause fragment to implement a comparison on a field in a JSON document
|
/// Create a WHERE clause fragment to implement a comparison on a field in a JSON document
|
||||||
|
|
|
@ -664,20 +664,39 @@ let integrationTests =
|
||||||
let! theCount = Count.all PostgresDb.TableName
|
let! theCount = Count.all PostgresDb.TableName
|
||||||
Expect.equal theCount 5 "There should have been 5 matching documents"
|
Expect.equal theCount 5 "There should have been 5 matching documents"
|
||||||
}
|
}
|
||||||
testTask "byField succeeds for numeric range" {
|
testList "byFields" [
|
||||||
use db = PostgresDb.BuildDb()
|
testTask "succeeds when items are found" {
|
||||||
do! loadDocs ()
|
use db = PostgresDb.BuildDb()
|
||||||
|
do! loadDocs ()
|
||||||
|
|
||||||
let! theCount = Count.byField PostgresDb.TableName (Field.BT "NumValue" 10 20)
|
let! theCount =
|
||||||
Expect.equal theCount 3 "There should have been 3 matching documents"
|
Count.byFields PostgresDb.TableName Any [ Field.BT "NumValue" 15 20; Field.EQ "NumValue" 0 ]
|
||||||
}
|
Expect.equal theCount 3 "There should have been 3 matching documents"
|
||||||
testTask "byField succeeds for non-numeric range" {
|
}
|
||||||
use db = PostgresDb.BuildDb()
|
testTask "succeeds when items are not found" {
|
||||||
do! loadDocs ()
|
use db = PostgresDb.BuildDb()
|
||||||
|
do! loadDocs ()
|
||||||
|
|
||||||
let! theCount = Count.byField PostgresDb.TableName (Field.BT "Value" "aardvark" "apple")
|
let! theCount = Count.byFields PostgresDb.TableName All [ Field.EX "Sub"; Field.GT "NumValue" 100 ]
|
||||||
Expect.equal theCount 1 "There should have been 1 matching document"
|
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" {
|
testTask "byContains succeeds" {
|
||||||
use db = PostgresDb.BuildDb()
|
use db = PostgresDb.BuildDb()
|
||||||
do! loadDocs ()
|
do! loadDocs ()
|
||||||
|
@ -710,6 +729,23 @@ let integrationTests =
|
||||||
Expect.isFalse exists "There should not have been an existing document"
|
Expect.isFalse exists "There should not have been an existing document"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
testList "byFields" [
|
||||||
|
testTask "succeeds when documents exist" {
|
||||||
|
use db = PostgresDb.BuildDb()
|
||||||
|
do! loadDocs ()
|
||||||
|
|
||||||
|
let! exists = Exists.byFields PostgresDb.TableName Any [ Field.EX "Sub"; Field.EX "Boo" ]
|
||||||
|
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.byFields PostgresDb.TableName All [ Field.EQ "NumValue" "six"; Field.EX "Nope" ]
|
||||||
|
Expect.isFalse exists "There should not have been existing documents"
|
||||||
|
}
|
||||||
|
]
|
||||||
testList "byField" [
|
testList "byField" [
|
||||||
testTask "succeeds when documents exist" {
|
testTask "succeeds when documents exist" {
|
||||||
use db = PostgresDb.BuildDb()
|
use db = PostgresDb.BuildDb()
|
||||||
|
@ -782,7 +818,7 @@ let integrationTests =
|
||||||
Expect.equal results [] "There should have been no documents returned"
|
Expect.equal results [] "There should have been no documents returned"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
testList "byId" [
|
ftestList "byId" [
|
||||||
testTask "succeeds when a document is found" {
|
testTask "succeeds when a document is found" {
|
||||||
use db = PostgresDb.BuildDb()
|
use db = PostgresDb.BuildDb()
|
||||||
do! loadDocs ()
|
do! loadDocs ()
|
||||||
|
@ -799,6 +835,26 @@ let integrationTests =
|
||||||
Expect.isNone doc "There should not have been a document returned"
|
Expect.isNone doc "There should not have been a document returned"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
testList "byFields" [
|
||||||
|
testTask "succeeds when documents are found" {
|
||||||
|
use db = PostgresDb.BuildDb()
|
||||||
|
do! loadDocs ()
|
||||||
|
|
||||||
|
let! docs =
|
||||||
|
Find.byFields<JsonDocument>
|
||||||
|
PostgresDb.TableName All [ Field.EQ "Value" "purple"; Field.EX "Sub" ]
|
||||||
|
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.byFields<JsonDocument>
|
||||||
|
PostgresDb.TableName All [ Field.EQ "Value" "mauve"; Field.NE "NumValue" 40 ]
|
||||||
|
Expect.isEmpty docs "There should have been no documents returned"
|
||||||
|
}
|
||||||
|
]
|
||||||
testList "byField" [
|
testList "byField" [
|
||||||
testTask "succeeds when documents are found" {
|
testTask "succeeds when documents are found" {
|
||||||
use db = PostgresDb.BuildDb()
|
use db = PostgresDb.BuildDb()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user