Add XML documentation #10
@ -215,104 +215,155 @@ module Query =
|
||||
let whereDataContains paramName =
|
||||
$"data @> %s{paramName}"
|
||||
|
||||
/// Create a WHERE clause fragment to implement a @? (JSON Path match) condition
|
||||
/// <summary>
|
||||
/// Create a <tt>WHERE</tt> clause fragment to implement a <tt>@?</tt> (JSON Path match) condition
|
||||
/// </summary>
|
||||
/// <param name="paramName">The parameter name for the query</param>
|
||||
/// <returns>A <tt>WHERE</tt> clause fragment for the JSON Path match condition</returns>
|
||||
[<CompiledName "WhereJsonPathMatches">]
|
||||
let whereJsonPathMatches paramName =
|
||||
$"data @? %s{paramName}::jsonpath"
|
||||
|
||||
/// Create an UPDATE statement to patch documents
|
||||
/// <summary>Create an <tt>UPDATE</tt> statement to patch documents</summary>
|
||||
/// <param name="tableName">The table to be updated</param>
|
||||
/// <returns>A query to patch documents</returns>
|
||||
[<CompiledName "Patch">]
|
||||
let patch tableName =
|
||||
$"UPDATE %s{tableName} SET data = data || @data"
|
||||
|
||||
/// Create an UPDATE statement to remove fields from documents
|
||||
/// <summary>Create an <tt>UPDATE</tt> statement to remove fields from documents</summary>
|
||||
/// <param name="tableName">The table to be updated</param>
|
||||
/// <returns>A query to remove fields from documents</returns>
|
||||
[<CompiledName "RemoveFields">]
|
||||
let removeFields tableName =
|
||||
$"UPDATE %s{tableName} SET data = data - @name"
|
||||
|
||||
/// Create a query by a document's ID
|
||||
/// <summary>Create a query by a document's ID</summary>
|
||||
/// <param name="statement">The SQL statement to be run against a document by its ID</param>
|
||||
/// <param name="docId">The ID of the document targeted</param>
|
||||
/// <returns>A query addressing a document by its ID</returns>
|
||||
[<CompiledName "ById">]
|
||||
let byId<'TKey> statement (docId: 'TKey) =
|
||||
Query.statementWhere statement (whereById docId)
|
||||
|
||||
/// Create a query on JSON fields
|
||||
/// <summary>Create a query on JSON fields</summary>
|
||||
/// <param name="statement">The SQL statement to be run against matching fields</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to be matched</param>
|
||||
/// <returns>A query addressing documents by field matching conditions</returns>
|
||||
[<CompiledName "ByFields">]
|
||||
let byFields statement howMatched fields =
|
||||
Query.statementWhere statement (whereByFields howMatched fields)
|
||||
|
||||
/// Create a JSON containment query
|
||||
/// <summary>Create a JSON containment query</summary>
|
||||
/// <param name="statement">The SQL statement to be run against the containment query</param>
|
||||
/// <returns>A query addressing documents by a JSON containment query</returns>
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains statement =
|
||||
Query.statementWhere statement (whereDataContains "@criteria")
|
||||
|
||||
/// Create a JSON Path match query
|
||||
/// <summary>Create a JSON Path match query</summary>
|
||||
/// <param name="statement">The SQL statement to run against the JSON Path match</param>
|
||||
/// <returns>A query addressing documents by a JSON Path match</returns>
|
||||
[<CompiledName "ByPathMatch">]
|
||||
let byPathMatch statement =
|
||||
Query.statementWhere statement (whereJsonPathMatches "@path")
|
||||
|
||||
|
||||
/// Functions for dealing with results
|
||||
/// <summary>Functions for dealing with results</summary>
|
||||
[<AutoOpen>]
|
||||
module Results =
|
||||
|
||||
/// Create a domain item from a document, specifying the field in which the document is found
|
||||
/// <summary>Create a domain item from a document, specifying the field in which the document is found</summary>
|
||||
/// <param name="field">The field name containing the JSON document</param>
|
||||
/// <param name="row">A row reader set to the row with the document to be constructed</param>
|
||||
/// <returns>The constructed domain item</returns>
|
||||
[<CompiledName "FromDocument">]
|
||||
let fromDocument<'T> field (row: RowReader) : 'T =
|
||||
Configuration.serializer().Deserialize<'T>(row.string field)
|
||||
|
||||
/// Create a domain item from a document
|
||||
/// <summary>Create a domain item from a document</summary>
|
||||
/// <param name="row">A row reader set to the row with the document to be constructed</param>
|
||||
/// <returns>The constructed domain item</returns>
|
||||
[<CompiledName "FromData">]
|
||||
let fromData<'T> row : 'T =
|
||||
fromDocument "data" row
|
||||
|
||||
/// Extract a count from the column "it"
|
||||
/// <summary>Extract a count from the column <tt>it</tt></summary>
|
||||
/// <param name="row">A row reader set to the row with the count to retrieve</param>
|
||||
/// <returns>The count from the row</returns>
|
||||
[<CompiledName "ToCount">]
|
||||
let toCount (row: RowReader) =
|
||||
row.int "it"
|
||||
|
||||
/// Extract a true/false value from the column "it"
|
||||
/// <summary>Extract a true/false value from the column <tt>it</tt></summary>
|
||||
/// <param name="row">A row reader set to the row with the true/false value to retrieve</param>
|
||||
/// <returns>The true/false value from the row</returns>
|
||||
[<CompiledName "ToExists">]
|
||||
let toExists (row: RowReader) =
|
||||
row.bool "it"
|
||||
|
||||
|
||||
/// Versions of queries that accept SqlProps as the last parameter
|
||||
/// <summary>Versions of queries that accept <tt>SqlProps</tt> as the last parameter</summary>
|
||||
module WithProps =
|
||||
|
||||
module FSharpList = Microsoft.FSharp.Collections.List
|
||||
|
||||
/// Commands to execute custom SQL queries
|
||||
/// <summary>Commands to execute custom SQL queries</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module Custom =
|
||||
|
||||
/// Execute a query that returns a list of results
|
||||
/// <summary>Execute a query that returns a list of results</summary>
|
||||
/// <param name="query">The query to retrieve the results</param>
|
||||
/// <param name="parameters">Parameters to use for the query</param>
|
||||
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>A list of results for the given query</returns>
|
||||
[<CompiledName "FSharpList">]
|
||||
let list<'TDoc> query parameters (mapFunc: RowReader -> 'TDoc) sqlProps =
|
||||
Sql.query query sqlProps
|
||||
|> Sql.parameters (List.ofSeq parameters)
|
||||
|> Sql.executeAsync mapFunc
|
||||
|
||||
/// Execute a query that returns a list of results
|
||||
/// <summary>Execute a query that returns a list of results</summary>
|
||||
/// <param name="query">The query to retrieve the results</param>
|
||||
/// <param name="parameters">Parameters to use for the query</param>
|
||||
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>A list of results for the given query</returns>
|
||||
let List<'TDoc>(query, parameters, mapFunc: System.Func<RowReader, 'TDoc>, sqlProps) = backgroundTask {
|
||||
let! results = list<'TDoc> query parameters mapFunc.Invoke sqlProps
|
||||
return ResizeArray results
|
||||
}
|
||||
|
||||
/// Execute a query that returns one or no results; returns None if not found
|
||||
/// <summary>Execute a query that returns one or no results</summary>
|
||||
/// <param name="query">The query to retrieve the results</param>
|
||||
/// <param name="parameters">Parameters to use for the query</param>
|
||||
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns><tt>Some</tt> with the first matching result, or <tt>None</tt> if not found</returns>
|
||||
[<CompiledName "FSharpSingle">]
|
||||
let single<'TDoc> query parameters mapFunc sqlProps = backgroundTask {
|
||||
let! results = list<'TDoc> query parameters mapFunc sqlProps
|
||||
return FSharp.Collections.List.tryHead results
|
||||
return FSharpList.tryHead results
|
||||
}
|
||||
|
||||
/// Execute a query that returns one or no results; returns null if not found
|
||||
/// <summary>Execute a query that returns one or no results</summary>
|
||||
/// <param name="query">The query to retrieve the results</param>
|
||||
/// <param name="parameters">Parameters to use for the query</param>
|
||||
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The first matching result, or <tt>null</tt> if not found</returns>
|
||||
let Single<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||
query, parameters, mapFunc: System.Func<RowReader, 'TDoc>, sqlProps) = backgroundTask {
|
||||
let! result = single<'TDoc> query parameters mapFunc.Invoke sqlProps
|
||||
return Option.toObj result
|
||||
}
|
||||
|
||||
/// Execute a query that returns no results
|
||||
/// <summary>Execute a query that returns no results</summary>
|
||||
/// <param name="query">The query to retrieve the results</param>
|
||||
/// <param name="parameters">Parameters to use for the query</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "NonQuery">]
|
||||
let nonQuery query parameters sqlProps =
|
||||
Sql.query query sqlProps
|
||||
@ -320,42 +371,64 @@ module WithProps =
|
||||
|> Sql.executeNonQueryAsync
|
||||
|> ignoreTask
|
||||
|
||||
/// Execute a query that returns a scalar value
|
||||
/// <summary>Execute a query that returns a scalar value</summary>
|
||||
/// <param name="query">The query to retrieve the value</param>
|
||||
/// <param name="parameters">Parameters to use for the query</param>
|
||||
/// <param name="mapFunc">The mapping function to obtain the value</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The scalar value for the query</returns>
|
||||
[<CompiledName "FSharpScalar">]
|
||||
let scalar<'T when 'T: struct> query parameters (mapFunc: RowReader -> 'T) sqlProps =
|
||||
Sql.query query sqlProps
|
||||
|> Sql.parameters (FSharpList.ofSeq parameters)
|
||||
|> Sql.executeRowAsync mapFunc
|
||||
|
||||
/// Execute a query that returns a scalar value
|
||||
/// <summary>Execute a query that returns a scalar value</summary>
|
||||
/// <param name="query">The query to retrieve the value</param>
|
||||
/// <param name="parameters">Parameters to use for the query</param>
|
||||
/// <param name="mapFunc">The mapping function to obtain the value</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The scalar value for the query</returns>
|
||||
let Scalar<'T when 'T: struct>(query, parameters, mapFunc: System.Func<RowReader, 'T>, sqlProps) =
|
||||
scalar<'T> query parameters mapFunc.Invoke sqlProps
|
||||
|
||||
/// Table and index definition commands
|
||||
/// <summary>Table and index definition commands</summary>
|
||||
module Definition =
|
||||
|
||||
/// Create a document table
|
||||
/// <summary>Create a document table</summary>
|
||||
/// <param name="name">The table whose existence should be ensured (may include schema)</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "EnsureTable">]
|
||||
let ensureTable name sqlProps = backgroundTask {
|
||||
do! Custom.nonQuery (Query.Definition.ensureTable name) [] sqlProps
|
||||
do! Custom.nonQuery (Query.Definition.ensureKey name PostgreSQL) [] sqlProps
|
||||
}
|
||||
|
||||
/// Create an index on documents in the specified table
|
||||
/// <summary>Create an index on documents in the specified table</summary>
|
||||
/// <param name="name">The table to be indexed (may include schema)</param>
|
||||
/// <param name="idxType">The type of document index to create</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "EnsureDocumentIndex">]
|
||||
let ensureDocumentIndex name idxType sqlProps =
|
||||
Custom.nonQuery (Query.Definition.ensureDocumentIndex name idxType) [] sqlProps
|
||||
|
||||
/// Create an index on field(s) within documents in the specified table
|
||||
/// <summary>Create an index on field(s) within documents in the specified table</summary>
|
||||
/// <param name="tableName">The table to be indexed (may include schema)</param>
|
||||
/// <param name="indexName">The name of the index to create</param>
|
||||
/// <param name="fields">One or more fields to be indexed</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "EnsureFieldIndex">]
|
||||
let ensureFieldIndex tableName indexName fields sqlProps =
|
||||
Custom.nonQuery (Query.Definition.ensureIndexOn tableName indexName fields PostgreSQL) [] sqlProps
|
||||
|
||||
/// Commands to add documents
|
||||
/// <summary>Commands to add documents</summary>
|
||||
[<AutoOpen>]
|
||||
module Document =
|
||||
|
||||
/// Insert a new document
|
||||
/// <summary>Insert a new document</summary>
|
||||
/// <param name="tableName">The table into which the document should be inserted (may include schema)</param>
|
||||
/// <param name="document">The document to be inserted</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "Insert">]
|
||||
let insert<'TDoc> tableName (document: 'TDoc) sqlProps =
|
||||
let query =
|
||||
@ -376,48 +449,78 @@ module WithProps =
|
||||
(Query.insert tableName).Replace("@data", dataParam)
|
||||
Custom.nonQuery query [ jsonParam "@data" document ] sqlProps
|
||||
|
||||
/// <summary>
|
||||
/// Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert")
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table into which the document should be saved (may include schema)</param>
|
||||
/// <param name="document">The document to be saved</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "Save">]
|
||||
let save<'TDoc> tableName (document: 'TDoc) sqlProps =
|
||||
Custom.nonQuery (Query.save tableName) [ jsonParam "@data" document ] sqlProps
|
||||
|
||||
/// Commands to count documents
|
||||
/// <summary>Commands to count documents</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module Count =
|
||||
|
||||
/// Count all documents in a table
|
||||
/// <summary>Count all documents in a table</summary>
|
||||
/// <param name="tableName">The table in which documents should be counted (may include schema)</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The count of the documents in the table</returns>
|
||||
[<CompiledName "All">]
|
||||
let all tableName sqlProps =
|
||||
Custom.scalar (Query.count tableName) [] toCount sqlProps
|
||||
|
||||
/// Count matching documents using JSON field comparisons (->> =)
|
||||
/// <summary>Count matching documents using JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
||||
/// <param name="tableName">The table in which documents should be counted (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The count of matching documents in the table</returns>
|
||||
[<CompiledName "ByFields">]
|
||||
let byFields tableName howMatched fields sqlProps =
|
||||
Custom.scalar
|
||||
(Query.byFields (Query.count tableName) howMatched fields) (addFieldParams fields []) toCount sqlProps
|
||||
|
||||
/// Count matching documents using a JSON containment query (@>)
|
||||
/// <summary>Count matching documents using a JSON containment query (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table in which documents should be counted (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The count of the documents in the table</returns>
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TContains) sqlProps =
|
||||
Custom.scalar
|
||||
(Query.byContains (Query.count tableName)) [ jsonParam "@criteria" criteria ] toCount sqlProps
|
||||
|
||||
/// Count matching documents using a JSON Path match query (@?)
|
||||
/// <summary>Count matching documents using a JSON Path match query (<tt>@?</tt>)</summary>
|
||||
/// <param name="tableName">The table in which documents should be counted (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to be matched</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The count of the documents in the table</returns>
|
||||
[<CompiledName "ByJsonPath">]
|
||||
let byJsonPath tableName jsonPath sqlProps =
|
||||
Custom.scalar
|
||||
(Query.byPathMatch (Query.count tableName)) [ "@path", Sql.string jsonPath ] toCount sqlProps
|
||||
|
||||
/// Commands to determine if documents exist
|
||||
/// <summary>Commands to determine if documents exist</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module Exists =
|
||||
|
||||
/// Determine if a document exists for the given ID
|
||||
/// <summary>Determine if a document exists for the given ID</summary>
|
||||
/// <param name="tableName">The table in which existence should be checked (may include schema)</param>
|
||||
/// <param name="docId">The ID of the document whose existence should be checked</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>True if a document exists, false if not</returns>
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) sqlProps =
|
||||
Custom.scalar (Query.exists tableName (Query.whereById docId)) [ idParam docId ] toExists sqlProps
|
||||
|
||||
/// Determine if a document exists using JSON field comparisons (->> =)
|
||||
/// <summary>Determine if a document exists using JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
||||
/// <param name="tableName">The table in which existence should be checked (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>True if any matching documents exist, false if not</returns>
|
||||
[<CompiledName "ByFields">]
|
||||
let byFields tableName howMatched fields sqlProps =
|
||||
Custom.scalar
|
||||
@ -426,7 +529,11 @@ module WithProps =
|
||||
toExists
|
||||
sqlProps
|
||||
|
||||
/// Determine if a document exists using a JSON containment query (@>)
|
||||
/// <summary>Determine if a document exists using a JSON containment query (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table in which existence should be checked (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>True if any matching documents exist, false if not</returns>
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TContains) sqlProps =
|
||||
Custom.scalar
|
||||
@ -435,7 +542,11 @@ module WithProps =
|
||||
toExists
|
||||
sqlProps
|
||||
|
||||
/// Determine if a document exists using a JSON Path match query (@?)
|
||||
/// <summary>Determine if a document exists using a JSON Path match query (<tt>@?</tt>)</summary>
|
||||
/// <param name="tableName">The table in which existence should be checked (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to be matched</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>True if any matching documents exist, false if not</returns>
|
||||
[<CompiledName "ByJsonPath">]
|
||||
let byJsonPath tableName jsonPath sqlProps =
|
||||
Custom.scalar
|
||||
@ -444,40 +555,67 @@ module WithProps =
|
||||
toExists
|
||||
sqlProps
|
||||
|
||||
/// Commands to determine if documents exist
|
||||
/// <summary>Commands to determine if documents exist</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module Find =
|
||||
|
||||
/// Retrieve all documents in the given table
|
||||
/// <summary>Retrieve all documents in the given table</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents from the given table</returns>
|
||||
[<CompiledName "FSharpAll">]
|
||||
let all<'TDoc> tableName sqlProps =
|
||||
Custom.list<'TDoc> (Query.find tableName) [] fromData<'TDoc> sqlProps
|
||||
|
||||
/// Retrieve all documents in the given table
|
||||
/// <summary>Retrieve all documents in the given table</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents from the given table</returns>
|
||||
let All<'TDoc>(tableName, sqlProps) =
|
||||
Custom.List<'TDoc>(Query.find tableName, [], fromData<'TDoc>, sqlProps)
|
||||
|
||||
/// Retrieve all documents in the given table ordered by the given fields in the document
|
||||
/// <summary>Retrieve all documents in the given table ordered by the given fields in the document</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents from the given table, ordered by the given fields</returns>
|
||||
[<CompiledName "FSharpAllOrdered">]
|
||||
let allOrdered<'TDoc> tableName orderFields sqlProps =
|
||||
Custom.list<'TDoc> (Query.find tableName + Query.orderBy orderFields PostgreSQL) [] fromData<'TDoc> sqlProps
|
||||
|
||||
/// Retrieve all documents in the given table ordered by the given fields in the document
|
||||
/// <summary>Retrieve all documents in the given table ordered by the given fields in the document</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents from the given table, ordered by the given fields</returns>
|
||||
let AllOrdered<'TDoc>(tableName, orderFields, sqlProps) =
|
||||
Custom.List<'TDoc>(
|
||||
Query.find tableName + Query.orderBy orderFields PostgreSQL, [], fromData<'TDoc>, sqlProps)
|
||||
|
||||
/// Retrieve a document by its ID (returns None if not found)
|
||||
/// <summary>Retrieve a document by its ID</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="docId">The ID of the document to retrieve</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns><tt>Some</tt> with the document if found, <tt>None</tt> otherwise</returns>
|
||||
[<CompiledName "FSharpById">]
|
||||
let byId<'TKey, 'TDoc> tableName (docId: 'TKey) sqlProps =
|
||||
Custom.single (Query.byId (Query.find tableName) docId) [ idParam docId ] fromData<'TDoc> sqlProps
|
||||
|
||||
/// Retrieve a document by its ID (returns null if not found)
|
||||
/// <summary>Retrieve a document by its ID</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="docId">The ID of the document to retrieve</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The document if found, <tt>null</tt> otherwise</returns>
|
||||
let ById<'TKey, 'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, docId: 'TKey, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
Query.byId (Query.find tableName) docId, [ idParam docId ], fromData<'TDoc>, sqlProps)
|
||||
|
||||
/// Retrieve documents matching JSON field comparisons (->> =)
|
||||
/// <summary>Retrieve documents matching JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given fields</returns>
|
||||
[<CompiledName "FSharpByFields">]
|
||||
let byFields<'TDoc> tableName howMatched fields sqlProps =
|
||||
Custom.list<'TDoc>
|
||||
@ -486,7 +624,12 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve documents matching JSON field comparisons (->> =)
|
||||
/// <summary>Retrieve documents matching JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given fields</returns>
|
||||
let ByFields<'TDoc>(tableName, howMatched, fields, sqlProps) =
|
||||
Custom.List<'TDoc>(
|
||||
Query.byFields (Query.find tableName) howMatched fields,
|
||||
@ -494,7 +637,16 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve documents matching JSON field comparisons (->> =) ordered by the given fields in the document
|
||||
/// <summary>
|
||||
/// Retrieve documents matching JSON field comparisons (<tt>->> =</tt>, etc.) ordered by the given fields
|
||||
/// in the document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="queryFields">The field conditions to match</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given fields, ordered by the other given fields</returns>
|
||||
[<CompiledName "FSharpByFieldsOrdered">]
|
||||
let byFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields sqlProps =
|
||||
Custom.list<'TDoc>
|
||||
@ -503,7 +655,16 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve documents matching JSON field comparisons (->> =) ordered by the given fields in the document
|
||||
/// <summary>
|
||||
/// Retrieve documents matching JSON field comparisons (<tt>->> =</tt>, etc.) ordered by the given fields
|
||||
/// in the document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="queryFields">The field conditions to match</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given fields, ordered by the other given fields</returns>
|
||||
let ByFieldsOrdered<'TDoc>(tableName, howMatched, queryFields, orderFields, sqlProps) =
|
||||
Custom.List<'TDoc>(
|
||||
Query.byFields (Query.find tableName) howMatched queryFields + Query.orderBy orderFields PostgreSQL,
|
||||
@ -511,13 +672,21 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>)
|
||||
/// <summary>Retrieve documents matching a JSON containment query (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given containment query</returns>
|
||||
[<CompiledName "FSharpByContains">]
|
||||
let byContains<'TDoc> tableName (criteria: obj) sqlProps =
|
||||
Custom.list<'TDoc>
|
||||
(Query.byContains (Query.find tableName)) [ jsonParam "@criteria" criteria ] fromData<'TDoc> sqlProps
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>)
|
||||
/// <summary>Retrieve documents matching a JSON containment query (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given containment query</returns>
|
||||
let ByContains<'TDoc>(tableName, criteria: obj, sqlProps) =
|
||||
Custom.List<'TDoc>(
|
||||
Query.byContains (Query.find tableName),
|
||||
@ -525,7 +694,15 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>) ordered by the given fields in the document
|
||||
/// <summary>
|
||||
/// Retrieve documents matching a JSON containment query (<tt>@></tt>) ordered by the given fields in the
|
||||
/// document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given containment query, ordered by the given fields</returns>
|
||||
[<CompiledName "FSharpByContainsOrdered">]
|
||||
let byContainsOrdered<'TDoc> tableName (criteria: obj) orderFields sqlProps =
|
||||
Custom.list<'TDoc>
|
||||
@ -534,7 +711,15 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>) ordered by the given fields in the document
|
||||
/// <summary>
|
||||
/// Retrieve documents matching a JSON containment query (<tt>@></tt>) ordered by the given fields in the
|
||||
/// document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given containment query, ordered by the given fields</returns>
|
||||
let ByContainsOrdered<'TDoc>(tableName, criteria: obj, orderFields, sqlProps) =
|
||||
Custom.List<'TDoc>(
|
||||
Query.byContains (Query.find tableName) + Query.orderBy orderFields PostgreSQL,
|
||||
@ -542,13 +727,21 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve documents matching a JSON Path match query (@?)
|
||||
/// <summary>Retrieve documents matching a JSON Path match query (<tt>@?</tt>)</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given JSON Path expression</returns>
|
||||
[<CompiledName "FSharpByJsonPath">]
|
||||
let byJsonPath<'TDoc> tableName jsonPath sqlProps =
|
||||
Custom.list<'TDoc>
|
||||
(Query.byPathMatch (Query.find tableName)) [ "@path", Sql.string jsonPath ] fromData<'TDoc> sqlProps
|
||||
|
||||
/// Retrieve documents matching a JSON Path match query (@?)
|
||||
/// <summary>Retrieve documents matching a JSON Path match query (<tt>@?</tt>)</summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given JSON Path expression</returns>
|
||||
let ByJsonPath<'TDoc>(tableName, jsonPath, sqlProps) =
|
||||
Custom.List<'TDoc>(
|
||||
Query.byPathMatch (Query.find tableName),
|
||||
@ -556,7 +749,15 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve documents matching a JSON Path match query (@?) ordered by the given fields in the document
|
||||
/// <summary>
|
||||
/// Retrieve documents matching a JSON Path match query (<tt>@?</tt>) ordered by the given fields in the
|
||||
/// document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given JSON Path expression, ordered by the given fields</returns>
|
||||
[<CompiledName "FSharpByJsonPathOrdered">]
|
||||
let byJsonPathOrdered<'TDoc> tableName jsonPath orderFields sqlProps =
|
||||
Custom.list<'TDoc>
|
||||
@ -565,7 +766,15 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve documents matching a JSON Path match query (@?) ordered by the given fields in the document
|
||||
/// <summary>
|
||||
/// Retrieve documents matching a JSON Path match query (<tt>@?</tt>) ordered by the given fields in the
|
||||
/// document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>All documents matching the given JSON Path expression, ordered by the given fields</returns>
|
||||
let ByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, sqlProps) =
|
||||
Custom.List<'TDoc>(
|
||||
Query.byPathMatch (Query.find tableName) + Query.orderBy orderFields PostgreSQL,
|
||||
@ -573,7 +782,12 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve the first document matching JSON field comparisons (->> =); returns None if not found
|
||||
/// <summary>Retrieve the first document matching JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns><tt>Some</tt> with the first document, or <tt>None</tt> if not found</returns>
|
||||
[<CompiledName "FSharpFirstByFields">]
|
||||
let firstByFields<'TDoc> tableName howMatched fields sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
@ -582,7 +796,12 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve the first document matching JSON field comparisons (->> =); returns null if not found
|
||||
/// <summary>Retrieve the first document matching JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The first document, or <tt>null</tt> 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",
|
||||
@ -590,8 +809,18 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve the first document matching JSON field comparisons (->> =) ordered by the given fields in the
|
||||
/// document; returns None if not found
|
||||
/// <summary>
|
||||
/// Retrieve the first document matching JSON field comparisons (<tt>->> =</tt>, etc.) ordered by the
|
||||
/// given fields in the document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="queryFields">The field conditions to match</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>
|
||||
/// <tt>Some</tt> with the first document ordered by the given fields, or <tt>None</tt> if not found
|
||||
/// </returns>
|
||||
[<CompiledName "FSharpFirstByFieldsOrdered">]
|
||||
let firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
@ -600,8 +829,16 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve the first document matching JSON field comparisons (->> =) ordered by the given fields in the
|
||||
/// document; returns null if not found
|
||||
/// <summary>
|
||||
/// Retrieve the first document matching JSON field comparisons (<tt>->> =</tt>, etc.) ordered by the
|
||||
/// given fields in the document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="queryFields">The field conditions to match</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The first document ordered by the given fields, or <tt>null</tt> if not found</returns>
|
||||
let FirstByFieldsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||
tableName, howMatched, queryFields, orderFields, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
@ -610,7 +847,11 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>); returns None if not found
|
||||
/// <summary>Retrieve the first document matching a JSON containment query (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns><tt>Some</tt> with the first document, or <tt>None</tt> if not found</returns>
|
||||
[<CompiledName "FSharpFirstByContains">]
|
||||
let firstByContains<'TDoc> tableName (criteria: obj) sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
@ -619,7 +860,11 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>); returns null if not found
|
||||
/// <summary>Retrieve the first document matching a JSON containment query (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The first document, or <tt>null</tt> 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",
|
||||
@ -627,8 +872,17 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>) ordered by the given fields in the
|
||||
/// document; returns None if not found
|
||||
/// <summary>
|
||||
/// Retrieve the first document matching a JSON containment query (<tt>@></tt>) ordered by the given fields
|
||||
/// in the document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>
|
||||
/// <tt>Some</tt> with the first document ordered by the given fields, or <tt>None</tt> if not found
|
||||
/// </returns>
|
||||
[<CompiledName "FSharpFirstByContainsOrdered">]
|
||||
let firstByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
@ -637,8 +891,15 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>) ordered by the given fields in the
|
||||
/// document; returns null if not found
|
||||
/// <summary>
|
||||
/// Retrieve the first document matching a JSON containment query (<tt>@></tt>) ordered by the given fields
|
||||
/// in the document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="criteria">The document to match with the containment query</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The first document ordered by the given fields, or <tt>null</tt> if not found</returns>
|
||||
let FirstByContainsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||
tableName, criteria: obj, orderFields, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
@ -647,7 +908,11 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve the first document matching a JSON Path match query (@?); returns None if not found
|
||||
/// <summary>Retrieve the first document matching a JSON Path match query (<tt>@?</tt>)</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns><tt>Some</tt> with the first document, or <tt>None</tt> if not found</returns>
|
||||
[<CompiledName "FSharpFirstByJsonPath">]
|
||||
let firstByJsonPath<'TDoc> tableName jsonPath sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
@ -656,7 +921,11 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve the first document matching a JSON Path match query (@?); returns null if not found
|
||||
/// <summary>Retrieve the first document matching a JSON Path match query (<tt>@?</tt>)</summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The first document, or <tt>null</tt> 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",
|
||||
@ -664,8 +933,17 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Retrieve the first document matching a JSON Path match query (@?) ordered by the given fields in the
|
||||
/// document; returns None if not found
|
||||
/// <summary>
|
||||
/// Retrieve the first document matching a JSON Path match query (<tt>@?</tt>) ordered by the given fields in
|
||||
/// the document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>
|
||||
/// <tt>Some</tt> with the first document ordered by the given fields, or <tt>None</tt> if not found
|
||||
/// </returns>
|
||||
[<CompiledName "FSharpFirstByJsonPathOrdered">]
|
||||
let firstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields sqlProps =
|
||||
Custom.single<'TDoc>
|
||||
@ -674,8 +952,15 @@ module WithProps =
|
||||
fromData<'TDoc>
|
||||
sqlProps
|
||||
|
||||
/// Retrieve the first document matching a JSON Path match query (@?) ordered by the given fields in the
|
||||
/// document; returns null if not found
|
||||
/// <summary>
|
||||
/// Retrieve the first document matching a JSON Path match query (<tt>@?</tt>) ordered by the given fields in
|
||||
/// the document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
/// <returns>The first document ordered by the given fields, or <tt>null</tt> if not found</returns>
|
||||
let FirstByJsonPathOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||
tableName, jsonPath, orderFields, sqlProps) =
|
||||
Custom.Single<'TDoc>(
|
||||
@ -684,36 +969,66 @@ module WithProps =
|
||||
fromData<'TDoc>,
|
||||
sqlProps)
|
||||
|
||||
/// Commands to update documents
|
||||
/// <summary>Commands to update documents</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module Update =
|
||||
|
||||
/// Update an entire document by its ID
|
||||
/// <summary>Update (replace) an entire document by its ID</summary>
|
||||
/// <param name="tableName">The table in which a document should be updated (may include schema)</param>
|
||||
/// <param name="docId">The ID of the document to be updated (replaced)</param>
|
||||
/// <param name="document">The new document</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) (document: 'TDoc) sqlProps =
|
||||
Custom.nonQuery
|
||||
(Query.byId (Query.update tableName) docId) [ idParam docId; jsonParam "@data" document ] sqlProps
|
||||
|
||||
/// Update an entire document by its ID, using the provided function to obtain the ID from the document
|
||||
/// <summary>
|
||||
/// Update (replace) an entire document by its ID, using the provided function to obtain the ID from the
|
||||
/// document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table in which a document should be updated (may include schema)</param>
|
||||
/// <param name="idFunc">The function to obtain the ID of the document</param>
|
||||
/// <param name="document">The new document</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "FSharpByFunc">]
|
||||
let byFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) sqlProps =
|
||||
byId tableName (idFunc document) document sqlProps
|
||||
|
||||
/// Update an entire document by its ID, using the provided function to obtain the ID from the document
|
||||
/// <summary>
|
||||
/// Update (replace) an entire document by its ID, using the provided function to obtain the ID from the
|
||||
/// document
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table in which a document should be updated (may include schema)</param>
|
||||
/// <param name="idFunc">The function to obtain the ID of the document</param>
|
||||
/// <param name="document">The new document</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
let ByFunc(tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc, sqlProps) =
|
||||
byFunc tableName idFunc.Invoke document sqlProps
|
||||
|
||||
/// Commands to patch (partially update) documents
|
||||
/// <summary>Commands to patch (partially update) documents</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module Patch =
|
||||
|
||||
/// Patch a document by its ID
|
||||
/// <summary>Patch a document by its ID</summary>
|
||||
/// <param name="tableName">The table in which a document should be patched (may include schema)</param>
|
||||
/// <param name="docId">The ID of the document to patch</param>
|
||||
/// <param name="patch">The partial document to patch the existing document</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) (patch: 'TPatch) sqlProps =
|
||||
Custom.nonQuery
|
||||
(Query.byId (Query.patch tableName) docId) [ idParam docId; jsonParam "@data" patch ] sqlProps
|
||||
|
||||
/// Patch documents using a JSON field comparison query in the WHERE clause (->> =)
|
||||
/// <summary>
|
||||
/// Patch documents using a JSON field comparison query in the <tt>WHERE</tt> clause (<tt>->> =</tt>,
|
||||
/// etc.)
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table in which documents should be patched (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="patch">The partial document to patch the existing document</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ByFields">]
|
||||
let byFields tableName howMatched fields (patch: 'TPatch) sqlProps =
|
||||
Custom.nonQuery
|
||||
@ -721,7 +1036,11 @@ module WithProps =
|
||||
(addFieldParams fields [ jsonParam "@data" patch ])
|
||||
sqlProps
|
||||
|
||||
/// Patch documents using a JSON containment query in the WHERE clause (@>)
|
||||
/// <summary>Patch documents using a JSON containment query in the WHERE clause (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table in which documents should be patched (may include schema)</param>
|
||||
/// <param name="criteria">The document to match the containment query</param>
|
||||
/// <param name="patch">The partial document to patch the existing document</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TContains) (patch: 'TPatch) sqlProps =
|
||||
Custom.nonQuery
|
||||
@ -729,7 +1048,11 @@ module WithProps =
|
||||
[ jsonParam "@data" patch; jsonParam "@criteria" criteria ]
|
||||
sqlProps
|
||||
|
||||
/// Patch documents using a JSON Path match query in the WHERE clause (@?)
|
||||
/// <summary>Patch documents using a JSON Path match query in the WHERE clause (<tt>@?</tt>)</summary>
|
||||
/// <param name="tableName">The table in which documents should be patched (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="patch">The partial document to patch the existing document</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ByJsonPath">]
|
||||
let byJsonPath tableName jsonPath (patch: 'TPatch) sqlProps =
|
||||
Custom.nonQuery
|
||||
@ -737,17 +1060,26 @@ module WithProps =
|
||||
[ jsonParam "@data" patch; "@path", Sql.string jsonPath ]
|
||||
sqlProps
|
||||
|
||||
/// Commands to remove fields from documents
|
||||
/// <summary>Commands to remove fields from documents</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module RemoveFields =
|
||||
|
||||
/// Remove fields from a document by the document's ID
|
||||
/// <summary>Remove fields from a document by the document's ID</summary>
|
||||
/// <param name="tableName">The table in which a document should be modified (may include schema)</param>
|
||||
/// <param name="docId">The ID of the document to modify</param>
|
||||
/// <param name="fieldNames">One or more field names to remove from the document</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) fieldNames sqlProps =
|
||||
Custom.nonQuery
|
||||
(Query.byId (Query.removeFields tableName) docId) [ idParam docId; fieldNameParams fieldNames ] sqlProps
|
||||
|
||||
/// Remove fields from documents via a comparison on JSON fields in the document
|
||||
/// <summary>Remove fields from documents via a comparison on JSON fields in the document</summary>
|
||||
/// <param name="tableName">The table in which documents should be modified (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="fieldNames">One or more field names to remove from the matching documents</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ByFields">]
|
||||
let byFields tableName howMatched fields fieldNames sqlProps =
|
||||
Custom.nonQuery
|
||||
@ -755,7 +1087,11 @@ module WithProps =
|
||||
(addFieldParams fields [ fieldNameParams fieldNames ])
|
||||
sqlProps
|
||||
|
||||
/// Remove fields from documents via a JSON containment query (@>)
|
||||
/// <summary>Remove fields from documents via a JSON containment query (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table in which documents should be modified (may include schema)</param>
|
||||
/// <param name="criteria">The document to match the containment query</param>
|
||||
/// <param name="fieldNames">One or more field names to remove from the matching documents</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TContains) fieldNames sqlProps =
|
||||
Custom.nonQuery
|
||||
@ -763,7 +1099,11 @@ module WithProps =
|
||||
[ jsonParam "@criteria" criteria; fieldNameParams fieldNames ]
|
||||
sqlProps
|
||||
|
||||
/// Remove fields from documents via a JSON Path match query (@?)
|
||||
/// <summary>Remove fields from documents via a JSON Path match query (<tt>@?</tt>)</summary>
|
||||
/// <param name="tableName">The table in which documents should be modified (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="fieldNames">One or more field names to remove from the matching documents</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "FSharpByJsonPath">]
|
||||
let byJsonPath tableName jsonPath fieldNames sqlProps =
|
||||
Custom.nonQuery
|
||||
@ -771,30 +1111,43 @@ module WithProps =
|
||||
[ "@path", Sql.string jsonPath; fieldNameParams fieldNames ]
|
||||
sqlProps
|
||||
|
||||
/// Commands to delete documents
|
||||
/// <summary>Commands to delete documents</summary>
|
||||
[<RequireQualifiedAccess>]
|
||||
module Delete =
|
||||
|
||||
/// Delete a document by its ID
|
||||
/// <summary>Delete a document by its ID</summary>
|
||||
/// <param name="tableName">The table in which a document should be deleted (may include schema)</param>
|
||||
/// <param name="docId">The ID of the document to delete</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) sqlProps =
|
||||
Custom.nonQuery (Query.byId (Query.delete tableName) docId) [ idParam docId ] sqlProps
|
||||
|
||||
/// Delete documents by matching a JSON field comparison query (->> =)
|
||||
/// <summary>Delete documents by matching a JSON field comparison query (<tt>->> =</tt>, etc.)</summary>
|
||||
/// <param name="tableName">The table in which documents should be deleted (may include schema)</param>
|
||||
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
|
||||
/// <param name="fields">The field conditions to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ByFields">]
|
||||
let byFields tableName howMatched fields sqlProps =
|
||||
Custom.nonQuery
|
||||
(Query.byFields (Query.delete tableName) howMatched fields) (addFieldParams fields []) sqlProps
|
||||
|
||||
/// Delete documents by matching a JSON contains query (@>)
|
||||
/// <summary>Delete documents by matching a JSON contains query (<tt>@></tt>)</summary>
|
||||
/// <param name="tableName">The table in which documents should be deleted (may include schema)</param>
|
||||
/// <param name="criteria">The document to match the containment query</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ByContains">]
|
||||
let byContains tableName (criteria: 'TCriteria) sqlProps =
|
||||
Custom.nonQuery (Query.byContains (Query.delete tableName)) [ jsonParam "@criteria" criteria ] sqlProps
|
||||
|
||||
/// Delete documents by matching a JSON Path match query (@?)
|
||||
/// <summary>Delete documents by matching a JSON Path match query (@?)</summary>
|
||||
/// <param name="tableName">The table in which documents should be deleted (may include schema)</param>
|
||||
/// <param name="jsonPath">The JSON Path expression to match</param>
|
||||
/// <param name="sqlProps">The <tt>SqlProps</tt> to use to execute the query</param>
|
||||
[<CompiledName "ByJsonPath">]
|
||||
let byJsonPath tableName path sqlProps =
|
||||
Custom.nonQuery (Query.byPathMatch (Query.delete tableName)) [ "@path", Sql.string path ] sqlProps
|
||||
let byJsonPath tableName jsonPath sqlProps =
|
||||
Custom.nonQuery (Query.byPathMatch (Query.delete tableName)) [ "@path", Sql.string jsonPath ] sqlProps
|
||||
|
||||
|
||||
/// Commands to execute custom SQL queries
|
||||
|
Loading…
x
Reference in New Issue
Block a user