Add Custom Json tests
This commit is contained in:
@@ -45,7 +45,7 @@ module Custom =
|
||||
/// <param name="mapFunc">The mapping function to extract the document</param>
|
||||
[<CompiledName "FSharpWriteJsonArray">]
|
||||
let writeJsonArray query parameters writer mapFunc =
|
||||
WithProps.Custom.writeJsonArray query parameters writer mapFunc
|
||||
WithProps.Custom.writeJsonArray query parameters writer mapFunc (fromDataSource ())
|
||||
|
||||
/// <summary>Execute a query, writing its results to the given <c>StreamWriter</c></summary>
|
||||
/// <param name="query">The query to retrieve the results</param>
|
||||
|
||||
@@ -109,7 +109,7 @@ module Custom =
|
||||
[<CompiledName "FSharpJsonSingle">]
|
||||
let jsonSingle query parameters mapFunc sqlProps =
|
||||
let results = jsonArray $"%s{query} LIMIT 1" parameters mapFunc sqlProps
|
||||
if results = "[]" then "{}" else results[1..results.Length - 1]
|
||||
if results = "[]" then "{}" else results[1..results.Length - 2]
|
||||
|
||||
/// <summary>Execute a query that returns one or no JSON documents</summary>
|
||||
/// <param name="query">The query to retrieve the results</param>
|
||||
@@ -545,7 +545,7 @@ module Find =
|
||||
[<CompiledName "FSharpFirstByFields">]
|
||||
let firstByFields<'TDoc> tableName howMatched fields sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
$"{Query.byFields (Query.find tableName) howMatched fields} LIMIT 1"
|
||||
(Query.byFields (Query.find tableName) howMatched fields)
|
||||
(addFieldParams fields [])
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
@@ -558,7 +558,7 @@ module Find =
|
||||
/// <returns>The first document, or <c>null</c> if not found</returns>
|
||||
let FirstByFields<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, howMatched, fields, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
$"{Query.byFields (Query.find tableName) howMatched fields} LIMIT 1",
|
||||
Query.byFields (Query.find tableName) howMatched fields,
|
||||
addFieldParams fields [],
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
@@ -576,7 +576,7 @@ module Find =
|
||||
[<CompiledName "FSharpFirstByFieldsOrdered">]
|
||||
let firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
$"{Query.byFields (Query.find tableName) howMatched queryFields}{Query.orderBy orderFields PostgreSQL} LIMIT 1"
|
||||
(Query.byFields (Query.find tableName) howMatched queryFields + Query.orderBy orderFields PostgreSQL)
|
||||
(addFieldParams queryFields [])
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
@@ -594,7 +594,7 @@ module Find =
|
||||
let FirstByFieldsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||
tableName, howMatched, queryFields, orderFields, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
$"{Query.byFields (Query.find tableName) howMatched queryFields}{Query.orderBy orderFields PostgreSQL} LIMIT 1",
|
||||
Query.byFields (Query.find tableName) howMatched queryFields + Query.orderBy orderFields PostgreSQL,
|
||||
addFieldParams queryFields [],
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
@@ -607,10 +607,7 @@ module Find =
|
||||
[<CompiledName "FSharpFirstByContains">]
|
||||
let firstByContains<'TDoc> tableName (criteria: obj) sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
$"{Query.byContains (Query.find tableName)} LIMIT 1"
|
||||
[ jsonParam "@criteria" criteria ]
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
(Query.byContains (Query.find tableName)) [ jsonParam "@criteria" criteria ] fromData<'TDoc> sqlProps
|
||||
|
||||
/// <summary>Retrieve the first document matching a JSON containment query (<c>@></c>)</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
@@ -619,10 +616,7 @@ module Find =
|
||||
/// <returns>The first document, or <c>null</c> if not found</returns>
|
||||
let FirstByContains<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, criteria: obj, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
$"{Query.byContains (Query.find tableName)} LIMIT 1",
|
||||
[ jsonParam "@criteria" criteria ],
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
Query.byContains (Query.find tableName), [ jsonParam "@criteria" criteria ], fromData<'TDoc>, sqlProps)
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the first document matching a JSON containment query (<c>@></c>) ordered by the given fields in the
|
||||
@@ -636,7 +630,7 @@ module Find =
|
||||
[<CompiledName "FSharpFirstByContainsOrdered">]
|
||||
let firstByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
$"{Query.byContains (Query.find tableName)}{Query.orderBy orderFields PostgreSQL} LIMIT 1"
|
||||
(Query.byContains (Query.find tableName) + Query.orderBy orderFields PostgreSQL)
|
||||
[ jsonParam "@criteria" criteria ]
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
@@ -653,7 +647,7 @@ module Find =
|
||||
let FirstByContainsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||
tableName, criteria: obj, orderFields, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
$"{Query.byContains (Query.find tableName)}{Query.orderBy orderFields PostgreSQL} LIMIT 1",
|
||||
Query.byContains (Query.find tableName) + Query.orderBy orderFields PostgreSQL,
|
||||
[ jsonParam "@criteria" criteria ],
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
@@ -666,7 +660,7 @@ module Find =
|
||||
[<CompiledName "FSharpFirstByJsonPath">]
|
||||
let firstByJsonPath<'TDoc> tableName jsonPath sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
$"{Query.byPathMatch (Query.find tableName)} LIMIT 1"
|
||||
(Query.byPathMatch (Query.find tableName))
|
||||
[ "@path", Sql.string jsonPath ]
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
@@ -678,7 +672,7 @@ module Find =
|
||||
/// <returns>The first document, or <c>null</c> if not found</returns>
|
||||
let FirstByJsonPath<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, jsonPath, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
$"{Query.byPathMatch (Query.find tableName)} LIMIT 1",
|
||||
Query.byPathMatch (Query.find tableName),
|
||||
[ "@path", Sql.string jsonPath ],
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
@@ -695,7 +689,7 @@ module Find =
|
||||
[<CompiledName "FSharpFirstByJsonPathOrdered">]
|
||||
let firstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
$"{Query.byPathMatch (Query.find tableName)}{Query.orderBy orderFields PostgreSQL} LIMIT 1"
|
||||
(Query.byPathMatch (Query.find tableName) + Query.orderBy orderFields PostgreSQL)
|
||||
[ "@path", Sql.string jsonPath ]
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
@@ -712,7 +706,7 @@ module Find =
|
||||
let FirstByJsonPathOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||
tableName, jsonPath, orderFields, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
$"{Query.byPathMatch (Query.find tableName)}{Query.orderBy orderFields PostgreSQL} LIMIT 1",
|
||||
Query.byPathMatch (Query.find tableName) + Query.orderBy orderFields PostgreSQL,
|
||||
[ "@path", Sql.string jsonPath ],
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
@@ -994,7 +988,7 @@ module Json =
|
||||
[<CompiledName "FirstByFieldsOrdered">]
|
||||
let firstByFieldsOrdered tableName howMatched queryFields orderFields sqlProps =
|
||||
Custom.jsonSingle
|
||||
$"{Query.byFields (Query.find tableName) howMatched queryFields}{Query.orderBy orderFields PostgreSQL}"
|
||||
(Query.byFields (Query.find tableName) howMatched queryFields + Query.orderBy orderFields PostgreSQL)
|
||||
(addFieldParams queryFields [])
|
||||
jsonFromData
|
||||
sqlProps
|
||||
@@ -1046,7 +1040,7 @@ module Json =
|
||||
[<CompiledName "FirstByContainsOrdered">]
|
||||
let firstByContainsOrdered tableName (criteria: obj) orderFields sqlProps =
|
||||
Custom.jsonSingle
|
||||
$"{Query.byContains (Query.find tableName)}{Query.orderBy orderFields PostgreSQL}"
|
||||
(Query.byContains (Query.find tableName) + Query.orderBy orderFields PostgreSQL)
|
||||
[ jsonParam "@criteria" criteria ]
|
||||
jsonFromData
|
||||
sqlProps
|
||||
@@ -1097,7 +1091,7 @@ module Json =
|
||||
[<CompiledName "FirstByJsonPathOrdered">]
|
||||
let firstByJsonPathOrdered tableName jsonPath orderFields sqlProps =
|
||||
Custom.jsonSingle
|
||||
$"{Query.byPathMatch (Query.find tableName)}{Query.orderBy orderFields PostgreSQL}"
|
||||
(Query.byPathMatch (Query.find tableName) + Query.orderBy orderFields PostgreSQL)
|
||||
[ "@path", Sql.string jsonPath ]
|
||||
jsonFromData
|
||||
sqlProps
|
||||
|
||||
Reference in New Issue
Block a user