Files
BitBadger.Documents/src/Postgres/Extensions.fs
Daniel J. Summers 43fed5789a v4.1 (#11)
- Add `Json` module to return JSON strings and write JSON as it's read to a `PipeWriter`
- Add `docfx`-based documentation to allow how-to docs and API docs to be generated on the same site

Reviewed-on: #11
2025-04-19 19:50:16 +00:00

1513 lines
102 KiB
Forth

namespace BitBadger.Documents.Postgres
open Npgsql
open Npgsql.FSharp
open WithProps
/// <summary>F# Extensions for the NpgsqlConnection type</summary>
[<AutoOpen>]
module Extensions =
type NpgsqlConnection with
/// <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>
/// <returns>A list of results for the given query</returns>
member conn.customList<'TDoc> query parameters (mapFunc: RowReader -> 'TDoc) =
Custom.list<'TDoc> query parameters mapFunc (Sql.existingConnection conn)
/// <summary>Execute a query that returns a JSON array 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 to extract the document</param>
/// <returns>A JSON array of results for the given query</returns>
member conn.customJsonArray query parameters mapFunc =
Custom.jsonArray query parameters mapFunc (Sql.existingConnection conn)
/// <summary>Execute a query, writing its results to the given <c>PipeWriter</c></summary>
/// <param name="query">The query to retrieve the results</param>
/// <param name="parameters">Parameters to use for the query</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="mapFunc">The mapping function to extract the document</param>
member conn.writeCustomJsonArray query parameters writer mapFunc =
Custom.writeJsonArray query parameters writer mapFunc (Sql.existingConnection conn)
/// <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>
/// <returns><c>Some</c> with the first matching result, or <c>None</c> if not found</returns>
member conn.customSingle<'TDoc> query parameters (mapFunc: RowReader -> 'TDoc) =
Custom.single<'TDoc> query parameters mapFunc (Sql.existingConnection conn)
/// <summary>Execute a query that returns one or no JSON documents</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 to extract the document</param>
/// <returns>The JSON document with the first matching result, or an empty document if not found</returns>
member conn.customJsonSingle query parameters mapFunc =
Custom.jsonSingle query parameters mapFunc (Sql.existingConnection conn)
/// <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>
member conn.customNonQuery query parameters =
Custom.nonQuery query parameters (Sql.existingConnection conn)
/// <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>
/// <returns>The scalar value for the query</returns>
member conn.customScalar<'T when 'T: struct> query parameters (mapFunc: RowReader -> 'T) =
Custom.scalar query parameters mapFunc (Sql.existingConnection conn)
/// <summary>Create a document table</summary>
/// <param name="name">The table whose existence should be ensured (may include schema)</param>
member conn.ensureTable name =
Definition.ensureTable name (Sql.existingConnection conn)
/// <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>
member conn.ensureDocumentIndex name idxType =
Definition.ensureDocumentIndex name idxType (Sql.existingConnection conn)
/// <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>
member conn.ensureFieldIndex tableName indexName fields =
Definition.ensureFieldIndex tableName indexName fields (Sql.existingConnection conn)
/// <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>
member conn.insert<'TDoc> tableName (document: 'TDoc) =
insert<'TDoc> tableName document (Sql.existingConnection conn)
/// <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>
member conn.save<'TDoc> tableName (document: 'TDoc) =
save<'TDoc> tableName document (Sql.existingConnection conn)
/// <summary>Count all documents in a table</summary>
/// <param name="tableName">The table in which documents should be counted (may include schema)</param>
/// <returns>The count of the documents in the table</returns>
member conn.countAll tableName =
Count.all tableName (Sql.existingConnection conn)
/// <summary>Count matching documents using JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>The count of matching documents in the table</returns>
member conn.countByFields tableName howMatched fields =
Count.byFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>Count matching documents using a JSON containment query (<c>@&gt;</c>)</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>
/// <returns>The count of the documents in the table</returns>
member conn.countByContains tableName criteria =
Count.byContains tableName criteria (Sql.existingConnection conn)
/// <summary>Count matching documents using a JSON Path match query (<c>@?</c>)</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>
/// <returns>The count of the documents in the table</returns>
member conn.countByJsonPath tableName jsonPath =
Count.byJsonPath tableName jsonPath (Sql.existingConnection conn)
/// <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>
/// <returns>True if a document exists, false if not</returns>
member conn.existsById tableName docId =
Exists.byId tableName docId (Sql.existingConnection conn)
/// <summary>Determine if a document exists using JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>True if any matching documents exist, false if not</returns>
member conn.existsByFields tableName howMatched fields =
Exists.byFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>Determine if a document exists using a JSON containment query (<c>@&gt;</c>)</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>
/// <returns>True if any matching documents exist, false if not</returns>
member conn.existsByContains tableName criteria =
Exists.byContains tableName criteria (Sql.existingConnection conn)
/// <summary>Determine if a document exists using a JSON Path match query (<c>@?</c>)</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>
/// <returns>True if any matching documents exist, false if not</returns>
member conn.existsByJsonPath tableName jsonPath =
Exists.byJsonPath tableName jsonPath (Sql.existingConnection conn)
/// <summary>Retrieve all documents in the given table</summary>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <returns>All documents from the given table</returns>
member conn.findAll<'TDoc> tableName =
Find.all<'TDoc> tableName (Sql.existingConnection conn)
/// <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>
/// <returns>All documents from the given table, ordered by the given fields</returns>
member conn.findAllOrdered<'TDoc> tableName orderFields =
Find.allOrdered<'TDoc> tableName orderFields (Sql.existingConnection conn)
/// <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>
/// <returns><c>Some</c> with the document if found, <c>None</c> otherwise</returns>
member conn.findById<'TKey, 'TDoc> tableName docId =
Find.byId<'TKey, 'TDoc> tableName docId (Sql.existingConnection conn)
/// <summary>Retrieve documents matching JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>All documents matching the given fields</returns>
member conn.findByFields<'TDoc> tableName howMatched fields =
Find.byFields<'TDoc> tableName howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Retrieve documents matching JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>All documents matching the given fields, ordered by the other given fields</returns>
member conn.findByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields =
Find.byFieldsOrdered<'TDoc>
tableName howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>Retrieve documents matching a JSON containment query (<c>@&gt;</c>)</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>
/// <returns>All documents matching the given containment query</returns>
member conn.findByContains<'TDoc> tableName (criteria: obj) =
Find.byContains<'TDoc> tableName criteria (Sql.existingConnection conn)
/// <summary>
/// Retrieve documents matching a JSON containment query (<c>@&gt;</c>) 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>
/// <returns>All documents matching the given containment query, ordered by the given fields</returns>
member conn.findByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields =
Find.byContainsOrdered<'TDoc> tableName criteria orderFields (Sql.existingConnection conn)
/// <summary>Retrieve documents matching a JSON Path match query (<c>@?</c>)</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>
/// <returns>All documents matching the given JSON Path expression</returns>
member conn.findByJsonPath<'TDoc> tableName jsonPath =
Find.byJsonPath<'TDoc> tableName jsonPath (Sql.existingConnection conn)
/// <summary>
/// Retrieve documents matching a JSON Path match query (<c>@?</c>) 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>
/// <returns>All documents matching the given JSON Path expression, ordered by the given fields</returns>
member conn.findByJsonPathOrdered<'TDoc> tableName jsonPath orderFields =
Find.byJsonPathOrdered<'TDoc> tableName jsonPath orderFields (Sql.existingConnection conn)
/// <summary>Retrieve the first document matching JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns><c>Some</c> with the first document, or <c>None</c> if not found</returns>
member conn.findFirstByFields<'TDoc> tableName howMatched fields =
Find.firstByFields<'TDoc> tableName howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first document matching JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>
/// <c>Some</c> with the first document ordered by the given fields, or <c>None</c> if not found
/// </returns>
member conn.findFirstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields =
Find.firstByFieldsOrdered<'TDoc>
tableName howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>Retrieve the first document matching a JSON containment query (<c>@&gt;</c>)</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>
/// <returns><c>Some</c> with the first document, or <c>None</c> if not found</returns>
member conn.findFirstByContains<'TDoc> tableName (criteria: obj) =
Find.firstByContains<'TDoc> tableName criteria (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first document matching a JSON containment query (<c>@&gt;</c>) 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>
/// <returns>
/// <c>Some</c> with the first document ordered by the given fields, or <c>None</c> if not found
/// </returns>
member conn.findFirstByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields =
Find.firstByContainsOrdered<'TDoc> tableName criteria orderFields (Sql.existingConnection conn)
/// <summary>Retrieve the first document matching a JSON Path match query (<c>@?</c>)</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>
/// <returns><c>Some</c> with the first document, or <c>None</c> if not found</returns>
member conn.findFirstByJsonPath<'TDoc> tableName jsonPath =
Find.firstByJsonPath<'TDoc> tableName jsonPath (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first document matching a JSON Path match query (<c>@?</c>) 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>
/// <returns>
/// <c>Some</c> with the first document ordered by the given fields, or <c>None</c> if not found
/// </returns>
member conn.findFirstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields =
Find.firstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields (Sql.existingConnection conn)
/// <summary>Retrieve all documents in the given table as a JSON array</summary>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <returns>All documents from the given table as a JSON array</returns>
member conn.jsonAll tableName =
Json.all tableName (Sql.existingConnection conn)
/// <summary>Write all documents in the given table to the given <c>PipeWriter</c></summary>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
member conn.writeJsonAll tableName writer =
Json.writeAll tableName writer (Sql.existingConnection conn)
/// <summary>
/// Retrieve all documents in the given table as a JSON array, 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>
/// <returns>All documents from the given table as a JSON array, ordered by the given fields</returns>
member conn.jsonAllOrdered tableName orderFields =
Json.allOrdered tableName orderFields (Sql.existingConnection conn)
/// <summary>
/// Write all documents in the given table to the given <c>PipeWriter</c>, 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="writer">The PipeWriter to which the results should be written</param>
/// <param name="orderFields">Fields by which the results should be ordered</param>
member conn.writeJsonAllOrdered tableName writer orderFields =
Json.writeAllOrdered tableName writer orderFields (Sql.existingConnection conn)
/// <summary>Retrieve a JSON 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>
/// <returns>The JSON document if found, an empty JSON document otherwise</returns>
member conn.jsonById<'TKey> tableName (docId: 'TKey) =
Json.byId tableName docId (Sql.existingConnection conn)
/// <summary>Write a JSON document to the given <c>PipeWriter</c> by its ID</summary>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="docId">The ID of the document to retrieve</param>
member conn.writeJsonById<'TKey> tableName writer (docId: 'TKey) =
Json.writeById tableName writer docId (Sql.existingConnection conn)
/// <summary>Retrieve JSON documents matching JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>All JSON documents matching the given fields</returns>
member conn.jsonByFields tableName howMatched fields =
Json.byFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching JSON field comparisons (<c>-&gt;&gt; =</c>,
/// etc.)
/// </summary>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
/// <param name="fields">The field conditions to match</param>
member conn.writeJsonByFields tableName writer howMatched fields =
Json.writeByFields tableName writer howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Retrieve JSON documents matching JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>All JSON documents matching the given fields, ordered by the other given fields</returns>
member conn.jsonByFieldsOrdered tableName howMatched queryFields orderFields =
Json.byFieldsOrdered tableName howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching JSON field comparisons (<c>-&gt;&gt; =</c>,
/// 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="writer">The PipeWriter to which the results should be written</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>
member conn.writeJsonByFieldsOrdered tableName writer howMatched queryFields orderFields =
Json.writeByFieldsOrdered tableName writer howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>Retrieve JSON documents matching a JSON containment query (<c>@&gt;</c>)</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>
/// <returns>All JSON documents matching the given containment query</returns>
member conn.jsonByContains tableName (criteria: obj) =
Json.byContains tableName criteria (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching a JSON containment query (<c>@&gt;</c>)
/// </summary>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="criteria">The document to match with the containment query</param>
member conn.writeJsonByContains tableName writer (criteria: obj) =
Json.writeByContains tableName writer criteria (Sql.existingConnection conn)
/// <summary>
/// Retrieve JSON documents matching a JSON containment query (<c>@&gt;</c>) 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>
/// <returns>All documents matching the given containment query, ordered by the given fields</returns>
member conn.jsonByContainsOrdered tableName (criteria: obj) orderFields =
Json.byContainsOrdered tableName criteria orderFields (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching a JSON containment query (<c>@&gt;</c>) 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="writer">The PipeWriter to which the results should be written</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>
member conn.writeJsonByContainsOrdered tableName writer (criteria: obj) orderFields =
Json.writeByContainsOrdered tableName writer criteria orderFields (Sql.existingConnection conn)
/// <summary>Retrieve JSON documents matching a JSON Path match query (<c>@?</c>)</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>
/// <returns>All JSON documents matching the given JSON Path expression</returns>
member conn.jsonByJsonPath tableName jsonPath =
Json.byJsonPath tableName jsonPath (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching a JSON Path match query (<c>@?</c>)
/// </summary>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="jsonPath">The JSON Path expression to match</param>
member conn.writeJsonByJsonPath tableName writer jsonPath =
Json.writeByJsonPath tableName writer jsonPath (Sql.existingConnection conn)
/// <summary>
/// Retrieve JSON documents matching a JSON Path match query (<c>@?</c>) 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>
/// <returns>All JSON documents matching the given JSON Path expression, ordered by the given fields</returns>
member conn.jsonByJsonPathOrdered tableName jsonPath orderFields =
Json.byJsonPathOrdered tableName jsonPath orderFields (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching a JSON Path match query (<c>@?</c>) 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="writer">The PipeWriter to which the results should be written</param>
/// <param name="jsonPath">The JSON Path expression to match</param>
/// <param name="orderFields">Fields by which the results should be ordered</param>
member conn.writeJsonByJsonPathOrdered tableName writer jsonPath orderFields =
Json.writeByJsonPathOrdered tableName writer jsonPath orderFields (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first JSON document matching JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
member conn.jsonFirstByFields tableName howMatched fields =
Json.firstByFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching JSON field comparisons
/// (<c>-&gt;&gt; =</c>, etc.)
/// </summary>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
/// <param name="fields">The field conditions to match</param>
member conn.writeJsonFirstByFields tableName writer howMatched fields =
Json.writeFirstByFields tableName writer howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first JSON document matching JSON field comparisons (<c>-&gt;&gt; =</c>, 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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
member conn.jsonFirstByFieldsOrdered tableName howMatched queryFields orderFields =
Json.firstByFieldsOrdered tableName howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching JSON field comparisons
/// (<c>-&gt;&gt; =</c>, 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="writer">The PipeWriter to which the results should be written</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>
member conn.writeJsonFirstByFieldsOrdered tableName writer howMatched queryFields orderFields =
Json.writeFirstByFieldsOrdered
tableName writer howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>Retrieve the first JSON document matching a JSON containment query (<c>@&gt;</c>)</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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
member conn.jsonFirstByContains tableName (criteria: obj) =
Json.firstByContains tableName criteria (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching a JSON containment query
/// (<c>@&gt;</c>)
/// </summary>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="criteria">The document to match with the containment query</param>
member conn.writeJsonFirstByContains tableName writer (criteria: obj) =
Json.writeFirstByContains tableName writer criteria (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first JSON document matching a JSON containment query (<c>@&gt;</c>) 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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
member conn.jsonFirstByContainsOrdered tableName (criteria: obj) orderFields =
Json.firstByContainsOrdered tableName criteria orderFields (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching a JSON containment query
/// (<c>@&gt;</c>) 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="writer">The PipeWriter to which the results should be written</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>
member conn.writeJsonFirstByContainsOrdered tableName writer (criteria: obj) orderFields =
Json.writeFirstByContainsOrdered tableName writer criteria orderFields (Sql.existingConnection conn)
/// <summary>Retrieve the first JSON document matching a JSON Path match query (<c>@?</c>)</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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
member conn.jsonFirstByJsonPath tableName jsonPath =
Json.firstByJsonPath tableName jsonPath (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching a JSON Path match query (<c>@?</c>)
/// </summary>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="jsonPath">The JSON Path expression to match</param>
member conn.writeJsonFirstByJsonPath tableName writer jsonPath =
Json.writeFirstByJsonPath tableName writer jsonPath (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first JSON document matching a JSON Path match query (<c>@?</c>) 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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
member conn.jsonFirstByJsonPathOrdered tableName jsonPath orderFields =
Json.firstByJsonPathOrdered tableName jsonPath orderFields (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching a JSON Path match query (<c>@?</c>)
/// 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="writer">The PipeWriter to which the results should be written</param>
/// <param name="jsonPath">The JSON Path expression to match</param>
/// <param name="orderFields">Fields by which the results should be ordered</param>
member conn.writeJsonFirstByJsonPathOrdered tableName writer jsonPath orderFields =
Json.writeFirstByJsonPathOrdered tableName writer jsonPath orderFields (Sql.existingConnection conn)
/// <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>
member conn.updateById tableName (docId: 'TKey) (document: 'TDoc) =
Update.byId tableName docId document (Sql.existingConnection conn)
/// <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>
member conn.updateByFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) =
Update.byFunc tableName idFunc document (Sql.existingConnection conn)
/// <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>
member conn.patchById tableName (docId: 'TKey) (patch: 'TPatch) =
Patch.byId tableName docId patch (Sql.existingConnection conn)
/// <summary>
/// Patch documents using a JSON field comparison query in the <c>WHERE</c> clause (<c>-&gt;&gt; =</c>,
/// 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>
member conn.patchByFields tableName howMatched fields (patch: 'TPatch) =
Patch.byFields tableName howMatched fields patch (Sql.existingConnection conn)
/// <summary>
/// Patch documents using a JSON containment query in the <c>WHERE</c> clause (<c>@&gt;</c>)
/// </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>
member conn.patchByContains tableName (criteria: 'TCriteria) (patch: 'TPatch) =
Patch.byContains tableName criteria patch (Sql.existingConnection conn)
/// <summary>Patch documents using a JSON Path match query in the <c>WHERE</c> clause (<c>@?</c>)</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>
member conn.patchByJsonPath tableName jsonPath (patch: 'TPatch) =
Patch.byJsonPath tableName jsonPath patch (Sql.existingConnection conn)
/// <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>
member conn.removeFieldsById tableName (docId: 'TKey) fieldNames =
RemoveFields.byId tableName docId fieldNames (Sql.existingConnection conn)
/// <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>
member conn.removeFieldsByFields tableName howMatched fields fieldNames =
RemoveFields.byFields tableName howMatched fields fieldNames (Sql.existingConnection conn)
/// <summary>Remove fields from documents via a JSON containment query (<c>@&gt;</c>)</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>
member conn.removeFieldsByContains tableName (criteria: 'TContains) fieldNames =
RemoveFields.byContains tableName criteria fieldNames (Sql.existingConnection conn)
/// <summary>Remove fields from documents via a JSON Path match query (<c>@?</c>)</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>
member conn.removeFieldsByJsonPath tableName jsonPath fieldNames =
RemoveFields.byJsonPath tableName jsonPath fieldNames (Sql.existingConnection conn)
/// <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>
member conn.deleteById tableName (docId: 'TKey) =
Delete.byId tableName docId (Sql.existingConnection conn)
/// <summary>Delete documents by matching a JSON field comparison query (<c>-&gt;&gt; =</c>, 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>
member conn.deleteByFields tableName howMatched fields =
Delete.byFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>Delete documents by matching a JSON contains query (<c>@&gt;</c>)</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>
member conn.deleteByContains tableName (criteria: 'TContains) =
Delete.byContains tableName criteria (Sql.existingConnection conn)
/// <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>
member conn.deleteByJsonPath tableName jsonPath =
Delete.byJsonPath tableName jsonPath (Sql.existingConnection conn)
open System.Runtime.CompilerServices
/// <summary>C# extensions on the NpgsqlConnection type</summary>
type NpgsqlConnectionCSharpExtensions =
/// <summary>Execute a query that returns a list of results</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>A list of results for the given query</returns>
[<Extension>]
static member inline CustomList<'TDoc>(conn, query, parameters, mapFunc: System.Func<RowReader, 'TDoc>) =
Custom.List<'TDoc>(query, parameters, mapFunc, Sql.existingConnection conn)
/// <summary>Execute a query that returns a JSON array of results</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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 to extract the document</param>
/// <returns>A JSON array of results for the given query</returns>
[<Extension>]
static member inline CustomJsonArray(conn, query, parameters, mapFunc) =
Custom.JsonArray(query, parameters, mapFunc, Sql.existingConnection conn)
/// <summary>Execute a query, writing its results to the given <c>PipeWriter</c></summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="query">The query to retrieve the results</param>
/// <param name="parameters">Parameters to use for the query</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="mapFunc">The mapping function to extract the document</param>
[<Extension>]
static member inline WriteCustomJsonArray(conn, query, parameters, writer, mapFunc) =
Custom.WriteJsonArray(query, parameters, writer, mapFunc, Sql.existingConnection conn)
/// <summary>Execute a query that returns one or no results</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first matching result, or <c>null</c> if not found</returns>
[<Extension>]
static member inline CustomSingle<'TDoc when 'TDoc: null and 'TDoc: not struct>(
conn, query, parameters, mapFunc: System.Func<RowReader, 'TDoc>) =
Custom.Single<'TDoc>(query, parameters, mapFunc, Sql.existingConnection conn)
/// <summary>Execute a query that returns one or no JSON documents</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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 to extract the document</param>
/// <returns>The JSON document with the first matching result, or an empty document if not found</returns>
[<Extension>]
static member inline CustomJsonSingle(conn, query, parameters, mapFunc) =
Custom.JsonSingle(query, parameters, mapFunc, Sql.existingConnection conn)
/// <summary>Execute a query that returns no results</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="query">The query to retrieve the results</param>
/// <param name="parameters">Parameters to use for the query</param>
[<Extension>]
static member inline CustomNonQuery(conn, query, parameters) =
Custom.nonQuery query parameters (Sql.existingConnection conn)
/// <summary>Execute a query that returns a scalar value</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The scalar value for the query</returns>
[<Extension>]
static member inline CustomScalar<'T when 'T: struct>(
conn, query, parameters, mapFunc: System.Func<RowReader, 'T>) =
Custom.Scalar(query, parameters, mapFunc, Sql.existingConnection conn)
/// <summary>Create a document table</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="name">The table whose existence should be ensured (may include schema)</param>
[<Extension>]
static member inline EnsureTable(conn, name) =
Definition.ensureTable name (Sql.existingConnection conn)
/// <summary>Create an index on documents in the specified table</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="name">The table to be indexed (may include schema)</param>
/// <param name="idxType">The type of document index to create</param>
[<Extension>]
static member inline EnsureDocumentIndex(conn, name, idxType) =
Definition.ensureDocumentIndex name idxType (Sql.existingConnection conn)
/// <summary>Create an index on field(s) within documents in the specified table</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline EnsureFieldIndex(conn, tableName, indexName, fields) =
Definition.ensureFieldIndex tableName indexName fields (Sql.existingConnection conn)
/// <summary>Insert a new document</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline Insert<'TDoc>(conn, tableName, document: 'TDoc) =
insert<'TDoc> tableName document (Sql.existingConnection conn)
/// <summary>Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert")</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline Save<'TDoc>(conn, tableName, document: 'TDoc) =
save<'TDoc> tableName document (Sql.existingConnection conn)
/// <summary>Count all documents in a table</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table in which documents should be counted (may include schema)</param>
/// <returns>The count of the documents in the table</returns>
[<Extension>]
static member inline CountAll(conn, tableName) =
Count.all tableName (Sql.existingConnection conn)
/// <summary>Count matching documents using JSON field comparisons (<c>-&gt;&gt; =</c>, etc.)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The count of matching documents in the table</returns>
[<Extension>]
static member inline CountByFields(conn, tableName, howMatched, fields) =
Count.byFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>Count matching documents using a JSON containment query (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The count of the documents in the table</returns>
[<Extension>]
static member inline CountByContains(conn, tableName, criteria: 'TCriteria) =
Count.byContains tableName criteria (Sql.existingConnection conn)
/// <summary>Count matching documents using a JSON Path match query (<c>@?</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The count of the documents in the table</returns>
[<Extension>]
static member inline CountByJsonPath(conn, tableName, jsonPath) =
Count.byJsonPath tableName jsonPath (Sql.existingConnection conn)
/// <summary>Determine if a document exists for the given ID</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>True if a document exists, false if not</returns>
[<Extension>]
static member inline ExistsById(conn, tableName, docId) =
Exists.byId tableName docId (Sql.existingConnection conn)
/// <summary>Determine if a document exists using JSON field comparisons (<c>-&gt;&gt; =</c>, etc.)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>True if any matching documents exist, false if not</returns>
[<Extension>]
static member inline ExistsByFields(conn, tableName, howMatched, fields) =
Exists.byFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>Determine if a document exists using a JSON containment query (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>True if any matching documents exist, false if not</returns>
[<Extension>]
static member inline ExistsByContains(conn, tableName, criteria: 'TCriteria) =
Exists.byContains tableName criteria (Sql.existingConnection conn)
/// <summary>Determine if a document exists using a JSON Path match query (<c>@?</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>True if any matching documents exist, false if not</returns>
[<Extension>]
static member inline ExistsByJsonPath(conn, tableName, jsonPath) =
Exists.byJsonPath tableName jsonPath (Sql.existingConnection conn)
/// <summary>Retrieve all documents in the given table</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <returns>All documents from the given table</returns>
[<Extension>]
static member inline FindAll<'TDoc>(conn, tableName) =
Find.All<'TDoc>(tableName, Sql.existingConnection conn)
/// <summary>Retrieve all documents in the given table ordered by the given fields in the document</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents from the given table, ordered by the given fields</returns>
[<Extension>]
static member inline FindAllOrdered<'TDoc>(conn, tableName, orderFields) =
Find.AllOrdered<'TDoc>(tableName, orderFields, Sql.existingConnection conn)
/// <summary>Retrieve a document by its ID</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The document if found, <c>null</c> otherwise</returns>
[<Extension>]
static member inline FindById<'TKey, 'TDoc when 'TDoc: null and 'TDoc: not struct>(conn, tableName, docId: 'TKey) =
Find.ById<'TKey, 'TDoc>(tableName, docId, Sql.existingConnection conn)
/// <summary>Retrieve documents matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents matching the given fields</returns>
[<Extension>]
static member inline FindByFields<'TDoc>(conn, tableName, howMatched, fields) =
Find.ByFields<'TDoc>(tableName, howMatched, fields, Sql.existingConnection conn)
/// <summary>
/// Retrieve documents matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.) ordered by the given fields in the
/// document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents matching the given fields, ordered by the other given fields</returns>
[<Extension>]
static member inline FindByFieldsOrdered<'TDoc>(conn, tableName, howMatched, queryFields, orderFields) =
Find.ByFieldsOrdered<'TDoc>(
tableName, howMatched, queryFields, orderFields, Sql.existingConnection conn)
/// <summary>Retrieve documents matching a JSON containment query (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents matching the given containment query</returns>
[<Extension>]
static member inline FindByContains<'TDoc>(conn, tableName, criteria: obj) =
Find.ByContains<'TDoc>(tableName, criteria, Sql.existingConnection conn)
/// <summary>
/// Retrieve documents matching a JSON containment query (<c>@&gt;</c>) ordered by the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents matching the given containment query, ordered by the given fields</returns>
[<Extension>]
static member inline FindByContainsOrdered<'TDoc>(conn, tableName, criteria: obj, orderFields) =
Find.ByContainsOrdered<'TDoc>(tableName, criteria, orderFields, Sql.existingConnection conn)
/// <summary>Retrieve documents matching a JSON Path match query (<c>@?</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents matching the given JSON Path expression</returns>
[<Extension>]
static member inline FindByJsonPath<'TDoc>(conn, tableName, jsonPath) =
Find.ByJsonPath<'TDoc>(tableName, jsonPath, Sql.existingConnection conn)
/// <summary>
/// Retrieve documents matching a JSON Path match query (<c>@?</c>) ordered by the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents matching the given JSON Path expression, ordered by the given fields</returns>
[<Extension>]
static member inline FindByJsonPathOrdered<'TDoc>(conn, tableName, jsonPath, orderFields) =
Find.ByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, Sql.existingConnection conn)
/// <summary>Retrieve the first document matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first document, or <c>null</c> if not found</returns>
[<Extension>]
static member inline FindFirstByFields<'TDoc when 'TDoc: null and 'TDoc: not struct>(
conn, tableName, howMatched, fields) =
Find.FirstByFields<'TDoc>(tableName, howMatched, fields, Sql.existingConnection conn)
/// <summary>
/// Retrieve the first document matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.) ordered by the given
/// fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first document ordered by the given fields, or <c>null</c> if not found</returns>
[<Extension>]
static member inline FindFirstByFieldsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
conn, tableName, howMatched, queryFields, orderFields) =
Find.FirstByFieldsOrdered<'TDoc>(
tableName, howMatched, queryFields, orderFields, Sql.existingConnection conn)
/// <summary>Retrieve the first document matching a JSON containment query (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first document, or <c>null</c> if not found</returns>
[<Extension>]
static member inline FindFirstByContains<'TDoc when 'TDoc: null and 'TDoc: not struct>(
conn, tableName, criteria: obj) =
Find.FirstByContains<'TDoc>(tableName, criteria, Sql.existingConnection conn)
/// <summary>
/// Retrieve the first document matching a JSON containment query (<c>@&gt;</c>) ordered by the given fields in the
/// document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first document ordered by the given fields, or <c>null</c> if not found</returns>
[<Extension>]
static member inline FindFirstByContainsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
conn, tableName, criteria: obj, orderFields) =
Find.FirstByContainsOrdered<'TDoc>(tableName, criteria, orderFields, Sql.existingConnection conn)
/// <summary>Retrieve the first document matching a JSON Path match query (<c>@?</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first document, or <c>null</c> if not found</returns>
[<Extension>]
static member inline FindFirstByJsonPath<'TDoc when 'TDoc: null and 'TDoc: not struct>(conn, tableName, jsonPath) =
Find.FirstByJsonPath<'TDoc>(tableName, jsonPath, Sql.existingConnection conn)
/// <summary>
/// Retrieve the first document matching a JSON Path match query (<c>@?</c>) ordered by the given fields in the
/// document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first document ordered by the given fields, or <c>null</c> if not found</returns>
[<Extension>]
static member inline FindFirstByJsonPathOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
conn, tableName, jsonPath, orderFields) =
Find.FirstByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, Sql.existingConnection conn)
/// <summary>Retrieve all documents in the given table as a JSON array</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <returns>All documents from the given table as a JSON array</returns>
[<Extension>]
static member inline JsonAll(conn, tableName) =
Json.all tableName (Sql.existingConnection conn)
/// <summary>Write all documents in the given table to the given <c>PipeWriter</c></summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
[<Extension>]
static member inline WriteJsonAll(conn, tableName, writer) =
Json.writeAll tableName writer (Sql.existingConnection conn)
/// <summary>
/// Retrieve all documents in the given table as a JSON array, ordered by the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents from the given table as a JSON array, ordered by the given fields</returns>
[<Extension>]
static member inline JsonAllOrdered(conn, tableName, orderFields) =
Json.allOrdered tableName orderFields (Sql.existingConnection conn)
/// <summary>
/// Write all documents in the given table to the given <c>PipeWriter</c>, ordered by the given fields in the
/// document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="orderFields">Fields by which the results should be ordered</param>
[<Extension>]
static member inline WriteJsonAllOrdered(conn, tableName, writer, orderFields) =
Json.writeAllOrdered tableName writer orderFields (Sql.existingConnection conn)
/// <summary>Retrieve a JSON document by its ID</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The JSON document if found, an empty JSON document otherwise</returns>
[<Extension>]
static member inline JsonById<'TKey>(conn, tableName, docId: 'TKey) =
Json.byId tableName docId (Sql.existingConnection conn)
/// <summary>Write a JSON document to the given <c>PipeWriter</c> by its ID</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="docId">The ID of the document to retrieve</param>
[<Extension>]
static member inline WriteJsonById<'TKey>(conn, tableName, writer, docId) =
Json.writeById tableName writer docId (Sql.existingConnection conn)
/// <summary>Retrieve JSON documents matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All JSON documents matching the given fields</returns>
[<Extension>]
static member inline JsonByFields(conn, tableName, howMatched, fields) =
Json.byFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.)
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
/// <param name="fields">The field conditions to match</param>
[<Extension>]
static member inline WriteJsonByFields(conn, tableName, writer, howMatched, fields) =
Json.writeByFields tableName writer howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Retrieve JSON documents matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.) ordered by the given fields
/// in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All JSON documents matching the given fields, ordered by the other given fields</returns>
[<Extension>]
static member inline JsonByFieldsOrdered(conn, tableName, howMatched, queryFields, orderFields) =
Json.byFieldsOrdered tableName howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.)
/// ordered by the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</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>
[<Extension>]
static member inline WriteJsonByFieldsOrdered(conn, tableName, writer, howMatched, queryFields, orderFields) =
Json.writeByFieldsOrdered tableName writer howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>Retrieve JSON documents matching a JSON containment query (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All JSON documents matching the given containment query</returns>
[<Extension>]
static member inline JsonByContains(conn, tableName, criteria: obj) =
Json.byContains tableName criteria (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching a JSON containment query (<c>@&gt;</c>)
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="criteria">The document to match with the containment query</param>
[<Extension>]
static member inline WriteJsonByContains(conn, tableName, writer, criteria: obj) =
Json.writeByContains tableName writer criteria (Sql.existingConnection conn)
/// <summary>
/// Retrieve JSON documents matching a JSON containment query (<c>@&gt;</c>) ordered by the given fields in the
/// document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All documents matching the given containment query, ordered by the given fields</returns>
[<Extension>]
static member inline JsonByContainsOrdered(conn, tableName, criteria: obj, orderFields) =
Json.byContainsOrdered tableName criteria orderFields (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching a JSON containment query (<c>@&gt;</c>) ordered by
/// the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</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>
[<Extension>]
static member inline WriteJsonByContainsOrdered(conn, tableName, writer, criteria: obj, orderFields) =
Json.writeByContainsOrdered tableName writer criteria orderFields (Sql.existingConnection conn)
/// <summary>Retrieve JSON documents matching a JSON Path match query (<c>@?</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All JSON documents matching the given JSON Path expression</returns>
[<Extension>]
static member inline JsonByJsonPath(conn, tableName, jsonPath) =
Json.byJsonPath tableName jsonPath (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching a JSON Path match query (<c>@?</c>)
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="jsonPath">The JSON Path expression to match</param>
[<Extension>]
static member inline WriteJsonByJsonPath(conn, tableName, writer, jsonPath) =
Json.writeByJsonPath tableName writer jsonPath (Sql.existingConnection conn)
/// <summary>
/// Retrieve JSON documents matching a JSON Path match query (<c>@?</c>) ordered by the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>All JSON documents matching the given JSON Path expression, ordered by the given fields</returns>
[<Extension>]
static member inline JsonByJsonPathOrdered(conn, tableName, jsonPath, orderFields) =
Json.byJsonPathOrdered tableName jsonPath orderFields (Sql.existingConnection conn)
/// <summary>
/// Write JSON documents to the given <c>PipeWriter</c> matching a JSON Path match query (<c>@?</c>) ordered by the
/// given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="jsonPath">The JSON Path expression to match</param>
/// <param name="orderFields">Fields by which the results should be ordered</param>
[<Extension>]
static member inline WriteJsonByJsonPathOrdered(conn, tableName, writer, jsonPath, orderFields) =
Json.writeByJsonPathOrdered tableName writer jsonPath orderFields (Sql.existingConnection conn)
/// <summary>Retrieve the first JSON document matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
[<Extension>]
static member inline JsonFirstByFields(conn, tableName, howMatched, fields) =
Json.firstByFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching JSON field comparisons
/// (<c>-&gt;&gt; =</c>, etc.)
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="howMatched">Whether to match any or all of the field conditions</param>
/// <param name="fields">The field conditions to match</param>
[<Extension>]
static member inline WriteJsonFirstByFields(conn, tableName, writer, howMatched, fields) =
Json.writeFirstByFields tableName writer howMatched fields (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first JSON document matching JSON field comparisons (<c>-&gt;&gt; =</c>, etc.) ordered by the
/// given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
[<Extension>]
static member inline JsonFirstByFieldsOrdered(conn, tableName, howMatched, queryFields, orderFields) =
Json.firstByFieldsOrdered tableName howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching JSON field comparisons
/// (<c>-&gt;&gt; =</c>, etc.) ordered by the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</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>
[<Extension>]
static member inline WriteJsonFirstByFieldsOrdered(conn, tableName, writer, howMatched, queryFields, orderFields) =
Json.writeFirstByFieldsOrdered
tableName writer howMatched queryFields orderFields (Sql.existingConnection conn)
/// <summary>Retrieve the first JSON document matching a JSON containment query (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
[<Extension>]
static member inline JsonFirstByContains(conn, tableName, criteria: obj) =
Json.firstByContains tableName criteria (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching a JSON containment query (<c>@&gt;</c>)
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="criteria">The document to match with the containment query</param>
[<Extension>]
static member inline WriteJsonFirstByContains(conn, tableName, writer, criteria: obj) =
Json.writeFirstByContains tableName writer criteria (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first JSON document matching a JSON containment query (<c>@&gt;</c>) ordered by the given fields in
/// the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
[<Extension>]
static member inline JsonFirstByContainsOrdered(conn, tableName, criteria: obj, orderFields) =
Json.firstByContainsOrdered tableName criteria orderFields (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching a JSON containment query (<c>@&gt;</c>)
/// ordered by the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</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>
[<Extension>]
static member inline WriteJsonFirstByContainsOrdered(conn, tableName, writer, criteria: obj, orderFields) =
Json.writeFirstByContainsOrdered tableName writer criteria orderFields (Sql.existingConnection conn)
/// <summary>Retrieve the first JSON document matching a JSON Path match query (<c>@?</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
[<Extension>]
static member inline JsonFirstByJsonPath(conn, tableName, jsonPath) =
Json.firstByJsonPath tableName jsonPath (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching a JSON Path match query (<c>@?</c>)
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="jsonPath">The JSON Path expression to match</param>
[<Extension>]
static member inline WriteJsonFirstByJsonPath(conn, tableName, writer, jsonPath) =
Json.writeFirstByJsonPath tableName writer jsonPath (Sql.existingConnection conn)
/// <summary>
/// Retrieve the first JSON document matching a JSON Path match query (<c>@?</c>) ordered by the given fields in the
/// document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
/// <returns>The first matching JSON document if found, an empty JSON document otherwise</returns>
[<Extension>]
static member inline JsonFirstByJsonPathOrdered(conn, tableName, jsonPath, orderFields) =
Json.firstByJsonPathOrdered tableName jsonPath orderFields (Sql.existingConnection conn)
/// <summary>
/// Write the first JSON document to the given <c>PipeWriter</c> matching a JSON Path match query (<c>@?</c>)
/// ordered by the given fields in the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
/// <param name="writer">The PipeWriter to which the results should be written</param>
/// <param name="jsonPath">The JSON Path expression to match</param>
/// <param name="orderFields">Fields by which the results should be ordered</param>
[<Extension>]
static member inline WriteJsonFirstByJsonPathOrdered(conn, tableName, writer, jsonPath, orderFields) =
Json.writeFirstByJsonPathOrdered tableName writer jsonPath orderFields (Sql.existingConnection conn)
/// <summary>Update (replace) an entire document by its ID</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline UpdateById(conn, tableName, docId: 'TKey, document: 'TDoc) =
Update.byId tableName docId document (Sql.existingConnection conn)
/// <summary>
/// Update (replace) an entire document by its ID, using the provided function to obtain the ID from the document
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline UpdateByFunc(conn, tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc) =
Update.ByFunc(tableName, idFunc, document, Sql.existingConnection conn)
/// <summary>Patch a document by its ID</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline PatchById(conn, tableName, docId: 'TKey, patch: 'TPatch) =
Patch.byId tableName docId patch (Sql.existingConnection conn)
/// <summary>
/// Patch documents using a JSON field comparison query in the <c>WHERE</c> clause (<c>-&gt;&gt; =</c>, etc.)
/// </summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline PatchByFields(conn, tableName, howMatched, fields, patch: 'TPatch) =
Patch.byFields tableName howMatched fields patch (Sql.existingConnection conn)
/// <summary>Patch documents using a JSON containment query in the <c>WHERE</c> clause (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline PatchByContains(conn, tableName, criteria: 'TCriteria, patch: 'TPatch) =
Patch.byContains tableName criteria patch (Sql.existingConnection conn)
/// <summary>Patch documents using a JSON Path match query in the <c>WHERE</c> clause (<c>@?</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline PatchByJsonPath(conn, tableName, jsonPath, patch: 'TPatch) =
Patch.byJsonPath tableName jsonPath patch (Sql.existingConnection conn)
/// <summary>Remove fields from a document by the document's ID</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline RemoveFieldsById(conn, tableName, docId: 'TKey, fieldNames) =
RemoveFields.byId tableName docId fieldNames (Sql.existingConnection conn)
/// <summary>Remove fields from documents via a comparison on JSON fields in the document</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline RemoveFieldsByFields(conn, tableName, howMatched, fields, fieldNames) =
RemoveFields.byFields tableName howMatched fields fieldNames (Sql.existingConnection conn)
/// <summary>Remove fields from documents via a JSON containment query (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline RemoveFieldsByContains(conn, tableName, criteria: 'TContains, fieldNames) =
RemoveFields.byContains tableName criteria fieldNames (Sql.existingConnection conn)
/// <summary>Remove fields from documents via a JSON Path match query (<c>@?</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline RemoveFieldsByJsonPath(conn, tableName, jsonPath, fieldNames) =
RemoveFields.byJsonPath tableName jsonPath fieldNames (Sql.existingConnection conn)
/// <summary>Delete a document by its ID</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline DeleteById(conn, tableName, docId: 'TKey) =
Delete.byId tableName docId (Sql.existingConnection conn)
/// <summary>Delete documents by matching a JSON field comparison query (<c>-&gt;&gt; =</c>, etc.)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline DeleteByFields(conn, tableName, howMatched, fields) =
Delete.byFields tableName howMatched fields (Sql.existingConnection conn)
/// <summary>Delete documents by matching a JSON contains query (<c>@&gt;</c>)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline DeleteByContains(conn, tableName, criteria: 'TContains) =
Delete.byContains tableName criteria (Sql.existingConnection conn)
/// <summary>Delete documents by matching a JSON Path match query (@?)</summary>
/// <param name="conn">The <c>NpgsqlConnection</c> on which to run the query</param>
/// <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>
[<Extension>]
static member inline DeleteByJsonPath(conn, tableName, jsonPath) =
Delete.byJsonPath tableName jsonPath (Sql.existingConnection conn)