From 5f3f84d607ac7d362cc29c31add093ddecfe8562 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Fri, 27 Dec 2024 08:43:31 -0500 Subject: [PATCH] WIP on docs; add F# PG ext docs --- src/Postgres/Extensions.fs | 562 ++++++++++++++++++++++++------------- src/Postgres/Functions.fs | 4 +- src/Postgres/WithProps.fs | 4 +- 3 files changed, 373 insertions(+), 197 deletions(-) diff --git a/src/Postgres/Extensions.fs b/src/Postgres/Extensions.fs index 17c7810..1622cef 100644 --- a/src/Postgres/Extensions.fs +++ b/src/Postgres/Extensions.fs @@ -2,446 +2,622 @@ namespace BitBadger.Documents.Postgres open Npgsql open Npgsql.FSharp +open WithProps /// F# Extensions for the NpgsqlConnection type [] module Extensions = - + type NpgsqlConnection with - /// Execute a query that returns a list of results + /// Execute a query that returns a list of results + /// The query to retrieve the results + /// Parameters to use for the query + /// The mapping function between the document and the domain item + /// A list of results for the given query member conn.customList<'TDoc> query parameters (mapFunc: RowReader -> 'TDoc) = - WithProps.Custom.list<'TDoc> query parameters mapFunc (Sql.existingConnection conn) + Custom.list<'TDoc> query parameters mapFunc (Sql.existingConnection conn) - /// Execute a query that returns one or no results; returns None if not found + /// Execute a query that returns one or no results + /// The query to retrieve the results + /// Parameters to use for the query + /// The mapping function between the document and the domain item + /// Some with the first matching result, or None if not found member conn.customSingle<'TDoc> query parameters (mapFunc: RowReader -> 'TDoc) = - WithProps.Custom.single<'TDoc> query parameters mapFunc (Sql.existingConnection conn) + Custom.single<'TDoc> query parameters mapFunc (Sql.existingConnection conn) - /// Execute a query that returns no results + /// Execute a query that returns no results + /// The query to retrieve the results + /// Parameters to use for the query member conn.customNonQuery query parameters = - WithProps.Custom.nonQuery query parameters (Sql.existingConnection conn) + Custom.nonQuery query parameters (Sql.existingConnection conn) - /// Execute a query that returns a scalar value + /// Execute a query that returns a scalar value + /// The query to retrieve the value + /// Parameters to use for the query + /// The mapping function to obtain the value + /// The scalar value for the query member conn.customScalar<'T when 'T: struct> query parameters (mapFunc: RowReader -> 'T) = - WithProps.Custom.scalar query parameters mapFunc (Sql.existingConnection conn) - - /// Create a document table + Custom.scalar query parameters mapFunc (Sql.existingConnection conn) + + /// Create a document table + /// The table whose existence should be ensured (may include schema) member conn.ensureTable name = - WithProps.Definition.ensureTable name (Sql.existingConnection conn) + Definition.ensureTable name (Sql.existingConnection conn) - /// Create an index on documents in the specified table + /// Create an index on documents in the specified table + /// The table to be indexed (may include schema) + /// The type of document index to create member conn.ensureDocumentIndex name idxType = - WithProps.Definition.ensureDocumentIndex name idxType (Sql.existingConnection conn) - - /// Create an index on field(s) within documents in the specified table + Definition.ensureDocumentIndex name idxType (Sql.existingConnection conn) + + /// Create an index on field(s) within documents in the specified table + /// The table to be indexed (may include schema) + /// The name of the index to create + /// One or more fields to be indexed member conn.ensureFieldIndex tableName indexName fields = - WithProps.Definition.ensureFieldIndex tableName indexName fields (Sql.existingConnection conn) + Definition.ensureFieldIndex tableName indexName fields (Sql.existingConnection conn) - /// Insert a new document + /// Insert a new document + /// The table into which the document should be inserted (may include schema) + /// The document to be inserted member conn.insert<'TDoc> tableName (document: 'TDoc) = - WithProps.Document.insert<'TDoc> tableName document (Sql.existingConnection conn) + insert<'TDoc> tableName document (Sql.existingConnection conn) + /// /// Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert") + /// + /// The table into which the document should be saved (may include schema) + /// The document to be saved member conn.save<'TDoc> tableName (document: 'TDoc) = - WithProps.Document.save<'TDoc> tableName document (Sql.existingConnection conn) + save<'TDoc> tableName document (Sql.existingConnection conn) - /// Count all documents in a table + /// Count all documents in a table + /// The table in which documents should be counted (may include schema) + /// The count of the documents in the table member conn.countAll tableName = - WithProps.Count.all tableName (Sql.existingConnection conn) - - /// Count matching documents using a JSON field comparison query (->> =) + Count.all tableName (Sql.existingConnection conn) + + /// Count matching documents using JSON field comparisons (->> =, etc.) + /// The table in which documents should be counted (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match + /// The count of matching documents in the table member conn.countByFields tableName howMatched fields = - WithProps.Count.byFields tableName howMatched fields (Sql.existingConnection conn) - - /// Count matching documents using a JSON containment query (@>) + Count.byFields tableName howMatched fields (Sql.existingConnection conn) + + /// Count matching documents using a JSON containment query (@>) + /// The table in which documents should be counted (may include schema) + /// The document to match with the containment query + /// The count of the documents in the table member conn.countByContains tableName criteria = - WithProps.Count.byContains tableName criteria (Sql.existingConnection conn) + Count.byContains tableName criteria (Sql.existingConnection conn) - /// Count matching documents using a JSON Path match query (@?) + /// Count matching documents using a JSON Path match query (@?) + /// The table in which documents should be counted (may include schema) + /// The JSON Path expression to be matched + /// The count of the documents in the table member conn.countByJsonPath tableName jsonPath = - WithProps.Count.byJsonPath tableName jsonPath (Sql.existingConnection conn) + Count.byJsonPath tableName jsonPath (Sql.existingConnection conn) - /// Determine if a document exists for the given ID + /// Determine if a document exists for the given ID + /// The table in which existence should be checked (may include schema) + /// The ID of the document whose existence should be checked + /// True if a document exists, false if not member conn.existsById tableName docId = - WithProps.Exists.byId tableName docId (Sql.existingConnection conn) - - /// Determine if documents exist using a JSON field comparison query (->> =) + Exists.byId tableName docId (Sql.existingConnection conn) + + /// Determine if a document exists using JSON field comparisons (->> =, etc.) + /// The table in which existence should be checked (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match + /// True if any matching documents exist, false if not member conn.existsByFields tableName howMatched fields = - WithProps.Exists.byFields tableName howMatched fields (Sql.existingConnection conn) - - /// Determine if documents exist using a JSON containment query (@>) + Exists.byFields tableName howMatched fields (Sql.existingConnection conn) + + /// Determine if a document exists using a JSON containment query (@>) + /// The table in which existence should be checked (may include schema) + /// The document to match with the containment query + /// True if any matching documents exist, false if not member conn.existsByContains tableName criteria = - WithProps.Exists.byContains tableName criteria (Sql.existingConnection conn) + Exists.byContains tableName criteria (Sql.existingConnection conn) - /// Determine if documents exist using a JSON Path match query (@?) + /// Determine if a document exists using a JSON Path match query (@?) + /// The table in which existence should be checked (may include schema) + /// The JSON Path expression to be matched + /// True if any matching documents exist, false if not member conn.existsByJsonPath tableName jsonPath = - WithProps.Exists.byJsonPath tableName jsonPath (Sql.existingConnection conn) - - /// Retrieve all documents in the given table + Exists.byJsonPath tableName jsonPath (Sql.existingConnection conn) + + /// Retrieve all documents in the given table + /// The table from which documents should be retrieved (may include schema) + /// All documents from the given table member conn.findAll<'TDoc> tableName = - WithProps.Find.all<'TDoc> tableName (Sql.existingConnection conn) + Find.all<'TDoc> tableName (Sql.existingConnection conn) - /// Retrieve all documents in the given table ordered by the given fields in the document + /// Retrieve all documents in the given table ordered by the given fields in the document + /// The table from which documents should be retrieved (may include schema) + /// Fields by which the results should be ordered + /// All documents from the given table, ordered by the given fields member conn.findAllOrdered<'TDoc> tableName orderFields = - WithProps.Find.allOrdered<'TDoc> tableName orderFields (Sql.existingConnection conn) + Find.allOrdered<'TDoc> tableName orderFields (Sql.existingConnection conn) - /// Retrieve a document by its ID; returns None if not found + /// Retrieve a document by its ID + /// The table from which a document should be retrieved (may include schema) + /// The ID of the document to retrieve + /// Some with the document if found, None otherwise member conn.findById<'TKey, 'TDoc> tableName docId = - WithProps.Find.byId<'TKey, 'TDoc> tableName docId (Sql.existingConnection conn) + Find.byId<'TKey, 'TDoc> tableName docId (Sql.existingConnection conn) - /// Retrieve documents matching a JSON field comparison query (->> =) + /// Retrieve documents matching JSON field comparisons (->> =, etc.) + /// The table from which documents should be retrieved (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match + /// All documents matching the given fields member conn.findByFields<'TDoc> tableName howMatched fields = - WithProps.Find.byFields<'TDoc> tableName howMatched fields (Sql.existingConnection conn) - - /// Retrieve documents matching a JSON field comparison query (->> =) ordered by the given fields in the - /// document + Find.byFields<'TDoc> tableName howMatched fields (Sql.existingConnection conn) + + /// + /// Retrieve documents matching JSON field comparisons (->> =, etc.) ordered by the given fields + /// in the document + /// + /// The table from which documents should be retrieved (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match + /// Fields by which the results should be ordered + /// All documents matching the given fields, ordered by the other given fields member conn.findByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields = - WithProps.Find.byFieldsOrdered<'TDoc> + Find.byFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields (Sql.existingConnection conn) - - /// Retrieve documents matching a JSON containment query (@>) + + /// Retrieve documents matching a JSON containment query (@>) + /// The table from which documents should be retrieved (may include schema) + /// The document to match with the containment query + /// All documents matching the given containment query member conn.findByContains<'TDoc> tableName (criteria: obj) = - WithProps.Find.byContains<'TDoc> tableName criteria (Sql.existingConnection conn) + Find.byContains<'TDoc> tableName criteria (Sql.existingConnection conn) - /// Retrieve documents matching a JSON containment query (@>) ordered by the given fields in the document + /// + /// Retrieve documents matching a JSON containment query (@>) ordered by the given fields in the + /// document + /// + /// The table from which documents should be retrieved (may include schema) + /// The document to match with the containment query + /// Fields by which the results should be ordered + /// All documents matching the given containment query, ordered by the given fields member conn.findByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields = - WithProps.Find.byContainsOrdered<'TDoc> tableName criteria orderFields (Sql.existingConnection conn) + Find.byContainsOrdered<'TDoc> tableName criteria orderFields (Sql.existingConnection conn) - /// Retrieve documents matching a JSON Path match query (@?) + /// Retrieve documents matching a JSON Path match query (@?) + /// The table from which documents should be retrieved (may include schema) + /// The JSON Path expression to match + /// All documents matching the given JSON Path expression member conn.findByJsonPath<'TDoc> tableName jsonPath = - WithProps.Find.byJsonPath<'TDoc> tableName jsonPath (Sql.existingConnection conn) - - /// Retrieve documents matching a JSON Path match query (@?) ordered by the given fields in the document + Find.byJsonPath<'TDoc> tableName jsonPath (Sql.existingConnection conn) + + /// + /// Retrieve documents matching a JSON Path match query (@?) ordered by the given fields in the + /// document + /// + /// The table from which documents should be retrieved (may include schema) + /// The JSON Path expression to match + /// Fields by which the results should be ordered + /// All documents matching the given JSON Path expression, ordered by the given fields member conn.findByJsonPathOrdered<'TDoc> tableName jsonPath orderFields = - WithProps.Find.byJsonPathOrdered<'TDoc> tableName jsonPath orderFields (Sql.existingConnection conn) - - /// Retrieve the first document matching a JSON field comparison query (->> =); returns None if not found + Find.byJsonPathOrdered<'TDoc> tableName jsonPath orderFields (Sql.existingConnection conn) + + /// Retrieve the first document matching JSON field comparisons (->> =, etc.) + /// The table from which a document should be retrieved (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match + /// Some with the first document, or None if not found member conn.findFirstByFields<'TDoc> tableName howMatched fields = - WithProps.Find.firstByFields<'TDoc> tableName howMatched fields (Sql.existingConnection conn) - - /// Retrieve the first document matching a JSON field comparison query (->> =) ordered by the given fields in - /// the document; returns None if not found + Find.firstByFields<'TDoc> tableName howMatched fields (Sql.existingConnection conn) + + /// + /// Retrieve the first document matching JSON field comparisons (->> =, etc.) ordered by the + /// given fields in the document + /// + /// The table from which a document should be retrieved (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match + /// Fields by which the results should be ordered + /// + /// Some with the first document ordered by the given fields, or None if not found + /// member conn.findFirstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields = - WithProps.Find.firstByFieldsOrdered<'TDoc> + Find.firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields (Sql.existingConnection conn) - - /// Retrieve the first document matching a JSON containment query (@>); returns None if not found + + /// Retrieve the first document matching a JSON containment query (@>) + /// The table from which a document should be retrieved (may include schema) + /// The document to match with the containment query + /// Some with the first document, or None if not found member conn.findFirstByContains<'TDoc> tableName (criteria: obj) = - WithProps.Find.firstByContains<'TDoc> tableName criteria (Sql.existingConnection conn) + Find.firstByContains<'TDoc> tableName criteria (Sql.existingConnection conn) - /// Retrieve the first document matching a JSON containment query (@>) ordered by the given fields in the - /// document; returns None if not found + /// + /// Retrieve the first document matching a JSON containment query (@>) ordered by the given fields + /// in the document + /// + /// The table from which a document should be retrieved (may include schema) + /// The document to match with the containment query + /// Fields by which the results should be ordered + /// + /// Some with the first document ordered by the given fields, or None if not found + /// member conn.findFirstByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields = - WithProps.Find.firstByContainsOrdered<'TDoc> tableName criteria orderFields (Sql.existingConnection conn) + Find.firstByContainsOrdered<'TDoc> tableName criteria orderFields (Sql.existingConnection conn) - /// Retrieve the first document matching a JSON Path match query (@?); returns None if not found + /// Retrieve the first document matching a JSON Path match query (@?) + /// The table from which a document should be retrieved (may include schema) + /// The JSON Path expression to match + /// Some with the first document, or None if not found member conn.findFirstByJsonPath<'TDoc> tableName jsonPath = - WithProps.Find.firstByJsonPath<'TDoc> tableName jsonPath (Sql.existingConnection conn) - - /// Retrieve the first document matching a JSON Path match query (@?) ordered by the given fields in the - /// document; returns None if not found + Find.firstByJsonPath<'TDoc> tableName jsonPath (Sql.existingConnection conn) + + /// + /// Retrieve the first document matching a JSON Path match query (@?) ordered by the given fields in + /// the document + /// + /// The table from which a document should be retrieved (may include schema) + /// The JSON Path expression to match + /// Fields by which the results should be ordered + /// + /// Some with the first document ordered by the given fields, or None if not found + /// member conn.findFirstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields = - WithProps.Find.firstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields (Sql.existingConnection conn) - - /// Update an entire document by its ID + Find.firstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields (Sql.existingConnection conn) + + /// Update (replace) an entire document by its ID + /// The table in which a document should be updated (may include schema) + /// The ID of the document to be updated (replaced) + /// The new document member conn.updateById tableName (docId: 'TKey) (document: 'TDoc) = - WithProps.Update.byId tableName docId document (Sql.existingConnection conn) + Update.byId tableName docId document (Sql.existingConnection conn) - /// Update an entire document by its ID, using the provided function to obtain the ID from the document + /// + /// Update (replace) an entire document by its ID, using the provided function to obtain the ID from the + /// document + /// + /// The table in which a document should be updated (may include schema) + /// The function to obtain the ID of the document + /// The new document member conn.updateByFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) = - WithProps.Update.byFunc tableName idFunc document (Sql.existingConnection conn) + Update.byFunc tableName idFunc document (Sql.existingConnection conn) - /// Patch a document by its ID + /// Patch a document by its ID + /// The table in which a document should be patched (may include schema) + /// The ID of the document to patch + /// The partial document to patch the existing document member conn.patchById tableName (docId: 'TKey) (patch: 'TPatch) = - WithProps.Patch.byId tableName docId patch (Sql.existingConnection conn) - - /// Patch documents using a JSON field comparison query in the WHERE clause (->> =) + Patch.byId tableName docId patch (Sql.existingConnection conn) + + /// + /// Patch documents using a JSON field comparison query in the WHERE clause (->> =, + /// etc.) + /// + /// The table in which documents should be patched (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match + /// The partial document to patch the existing document member conn.patchByFields tableName howMatched fields (patch: 'TPatch) = - WithProps.Patch.byFields tableName howMatched fields patch (Sql.existingConnection conn) - - /// Patch documents using a JSON containment query in the WHERE clause (@>) + Patch.byFields tableName howMatched fields patch (Sql.existingConnection conn) + + /// + /// Patch documents using a JSON containment query in the WHERE clause (@>) + /// + /// The table in which documents should be patched (may include schema) + /// The document to match the containment query + /// The partial document to patch the existing document member conn.patchByContains tableName (criteria: 'TCriteria) (patch: 'TPatch) = - WithProps.Patch.byContains tableName criteria patch (Sql.existingConnection conn) - - /// Patch documents using a JSON Path match query in the WHERE clause (@?) + Patch.byContains tableName criteria patch (Sql.existingConnection conn) + + /// Patch documents using a JSON Path match query in the WHERE clause (@?) + /// The table in which documents should be patched (may include schema) + /// The JSON Path expression to match + /// The partial document to patch the existing document member conn.patchByJsonPath tableName jsonPath (patch: 'TPatch) = - WithProps.Patch.byJsonPath tableName jsonPath patch (Sql.existingConnection conn) - - /// Remove fields from a document by the document's ID + Patch.byJsonPath tableName jsonPath patch (Sql.existingConnection conn) + + /// Remove fields from a document by the document's ID + /// The table in which a document should be modified (may include schema) + /// The ID of the document to modify + /// One or more field names to remove from the document member conn.removeFieldsById tableName (docId: 'TKey) fieldNames = - WithProps.RemoveFields.byId tableName docId fieldNames (Sql.existingConnection conn) - - /// Remove fields from documents via a comparison on JSON fields in the document + RemoveFields.byId tableName docId fieldNames (Sql.existingConnection conn) + + /// Remove fields from documents via a comparison on JSON fields in the document + /// The table in which documents should be modified (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match + /// One or more field names to remove from the matching documents member conn.removeFieldsByFields tableName howMatched fields fieldNames = - WithProps.RemoveFields.byFields tableName howMatched fields fieldNames (Sql.existingConnection conn) - - /// Remove fields from documents via a JSON containment query (@>) + RemoveFields.byFields tableName howMatched fields fieldNames (Sql.existingConnection conn) + + /// Remove fields from documents via a JSON containment query (@>) + /// The table in which documents should be modified (may include schema) + /// The document to match the containment query + /// One or more field names to remove from the matching documents member conn.removeFieldsByContains tableName (criteria: 'TContains) fieldNames = - WithProps.RemoveFields.byContains tableName criteria fieldNames (Sql.existingConnection conn) - - /// Remove fields from documents via a JSON Path match query (@?) + RemoveFields.byContains tableName criteria fieldNames (Sql.existingConnection conn) + + /// Remove fields from documents via a JSON Path match query (@?) + /// The table in which documents should be modified (may include schema) + /// The JSON Path expression to match + /// One or more field names to remove from the matching documents member conn.removeFieldsByJsonPath tableName jsonPath fieldNames = - WithProps.RemoveFields.byJsonPath tableName jsonPath fieldNames (Sql.existingConnection conn) - - /// Delete a document by its ID + RemoveFields.byJsonPath tableName jsonPath fieldNames (Sql.existingConnection conn) + + /// Delete a document by its ID + /// The table in which a document should be deleted (may include schema) + /// The ID of the document to delete member conn.deleteById tableName (docId: 'TKey) = - WithProps.Delete.byId tableName docId (Sql.existingConnection conn) + Delete.byId tableName docId (Sql.existingConnection conn) + /// Delete documents by matching a JSON field comparison query (->> =, etc.) + /// The table in which documents should be deleted (may include schema) + /// Whether to match any or all of the field conditions + /// The field conditions to match member conn.deleteByFields tableName howMatched fields = - WithProps.Delete.byFields tableName howMatched fields (Sql.existingConnection conn) - - /// Delete documents by matching a JSON containment query (@>) - member conn.deleteByContains tableName (criteria: 'TContains) = - WithProps.Delete.byContains tableName criteria (Sql.existingConnection conn) + Delete.byFields tableName howMatched fields (Sql.existingConnection conn) - /// Delete documents by matching a JSON Path match query (@?) - member conn.deleteByJsonPath tableName path = - WithProps.Delete.byJsonPath tableName path (Sql.existingConnection conn) + /// Delete documents by matching a JSON contains query (@>) + /// The table in which documents should be deleted (may include schema) + /// The document to match the containment query + member conn.deleteByContains tableName (criteria: 'TContains) = + Delete.byContains tableName criteria (Sql.existingConnection conn) + + /// Delete documents by matching a JSON Path match query (@?) + /// The table in which documents should be deleted (may include schema) + /// The JSON Path expression to match + member conn.deleteByJsonPath tableName jsonPath = + Delete.byJsonPath tableName jsonPath (Sql.existingConnection conn) open System.Runtime.CompilerServices /// C# extensions on the NpgsqlConnection type type NpgsqlConnectionCSharpExtensions = - + /// Execute a query that returns a list of results [] static member inline CustomList<'TDoc>(conn, query, parameters, mapFunc: System.Func) = - WithProps.Custom.List<'TDoc>(query, parameters, mapFunc, Sql.existingConnection conn) + Custom.List<'TDoc>(query, parameters, mapFunc, Sql.existingConnection conn) /// Execute a query that returns one or no results; returns None if not found [] static member inline CustomSingle<'TDoc when 'TDoc: null and 'TDoc: not struct>( conn, query, parameters, mapFunc: System.Func) = - WithProps.Custom.Single<'TDoc>(query, parameters, mapFunc, Sql.existingConnection conn) + Custom.Single<'TDoc>(query, parameters, mapFunc, Sql.existingConnection conn) /// Execute a query that returns no results [] static member inline CustomNonQuery(conn, query, parameters) = - WithProps.Custom.nonQuery query parameters (Sql.existingConnection conn) + Custom.nonQuery query parameters (Sql.existingConnection conn) /// Execute a query that returns a scalar value [] static member inline CustomScalar<'T when 'T: struct>( conn, query, parameters, mapFunc: System.Func) = - WithProps.Custom.Scalar(query, parameters, mapFunc, Sql.existingConnection conn) - + Custom.Scalar(query, parameters, mapFunc, Sql.existingConnection conn) + /// Create a document table [] static member inline EnsureTable(conn, name) = - WithProps.Definition.ensureTable name (Sql.existingConnection conn) + Definition.ensureTable name (Sql.existingConnection conn) /// Create an index on documents in the specified table [] static member inline EnsureDocumentIndex(conn, name, idxType) = - WithProps.Definition.ensureDocumentIndex name idxType (Sql.existingConnection conn) - + Definition.ensureDocumentIndex name idxType (Sql.existingConnection conn) + /// Create an index on field(s) within documents in the specified table [] static member inline EnsureFieldIndex(conn, tableName, indexName, fields) = - WithProps.Definition.ensureFieldIndex tableName indexName fields (Sql.existingConnection conn) + Definition.ensureFieldIndex tableName indexName fields (Sql.existingConnection conn) /// Insert a new document [] static member inline Insert<'TDoc>(conn, tableName, document: 'TDoc) = - WithProps.Document.insert<'TDoc> tableName document (Sql.existingConnection conn) + insert<'TDoc> tableName document (Sql.existingConnection conn) /// Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert") [] static member inline Save<'TDoc>(conn, tableName, document: 'TDoc) = - WithProps.Document.save<'TDoc> tableName document (Sql.existingConnection conn) + save<'TDoc> tableName document (Sql.existingConnection conn) /// Count all documents in a table [] static member inline CountAll(conn, tableName) = - WithProps.Count.all tableName (Sql.existingConnection conn) - + Count.all tableName (Sql.existingConnection conn) + /// Count matching documents using a JSON field comparison query (->> =) [] static member inline CountByFields(conn, tableName, howMatched, fields) = - WithProps.Count.byFields tableName howMatched fields (Sql.existingConnection conn) - + Count.byFields tableName howMatched fields (Sql.existingConnection conn) + /// Count matching documents using a JSON containment query (@>) [] static member inline CountByContains(conn, tableName, criteria: 'TCriteria) = - WithProps.Count.byContains tableName criteria (Sql.existingConnection conn) + Count.byContains tableName criteria (Sql.existingConnection conn) /// Count matching documents using a JSON Path match query (@?) [] static member inline CountByJsonPath(conn, tableName, jsonPath) = - WithProps.Count.byJsonPath tableName jsonPath (Sql.existingConnection conn) + Count.byJsonPath tableName jsonPath (Sql.existingConnection conn) /// Determine if a document exists for the given ID [] static member inline ExistsById(conn, tableName, docId) = - WithProps.Exists.byId tableName docId (Sql.existingConnection conn) - + Exists.byId tableName docId (Sql.existingConnection conn) + /// Determine if documents exist using a JSON field comparison query (->> =) [] static member inline ExistsByFields(conn, tableName, howMatched, fields) = - WithProps.Exists.byFields tableName howMatched fields (Sql.existingConnection conn) - + Exists.byFields tableName howMatched fields (Sql.existingConnection conn) + /// Determine if documents exist using a JSON containment query (@>) [] static member inline ExistsByContains(conn, tableName, criteria: 'TCriteria) = - WithProps.Exists.byContains tableName criteria (Sql.existingConnection conn) + Exists.byContains tableName criteria (Sql.existingConnection conn) /// Determine if documents exist using a JSON Path match query (@?) [] static member inline ExistsByJsonPath(conn, tableName, jsonPath) = - WithProps.Exists.byJsonPath tableName jsonPath (Sql.existingConnection conn) - + Exists.byJsonPath tableName jsonPath (Sql.existingConnection conn) + /// Retrieve all documents in the given table [] static member inline FindAll<'TDoc>(conn, tableName) = - WithProps.Find.All<'TDoc>(tableName, Sql.existingConnection conn) + Find.All<'TDoc>(tableName, Sql.existingConnection conn) /// Retrieve all documents in the given table ordered by the given fields in the document [] static member inline FindAllOrdered<'TDoc>(conn, tableName, orderFields) = - WithProps.Find.AllOrdered<'TDoc>(tableName, orderFields, Sql.existingConnection conn) + Find.AllOrdered<'TDoc>(tableName, orderFields, Sql.existingConnection conn) /// Retrieve a document by its ID; returns None if not found [] static member inline FindById<'TKey, 'TDoc when 'TDoc: null and 'TDoc: not struct>(conn, tableName, docId: 'TKey) = - WithProps.Find.ById<'TKey, 'TDoc>(tableName, docId, Sql.existingConnection conn) + Find.ById<'TKey, 'TDoc>(tableName, docId, Sql.existingConnection conn) /// Retrieve documents matching a JSON field comparison query (->> =) [] static member inline FindByFields<'TDoc>(conn, tableName, howMatched, fields) = - WithProps.Find.ByFields<'TDoc>(tableName, howMatched, fields, Sql.existingConnection conn) - + Find.ByFields<'TDoc>(tableName, howMatched, fields, Sql.existingConnection conn) + /// Retrieve documents matching a JSON field comparison query (->> =) ordered by the given fields in the document [] static member inline FindByFieldsOrdered<'TDoc>(conn, tableName, howMatched, queryFields, orderFields) = - WithProps.Find.ByFieldsOrdered<'TDoc>( + Find.ByFieldsOrdered<'TDoc>( tableName, howMatched, queryFields, orderFields, Sql.existingConnection conn) - + /// Retrieve documents matching a JSON containment query (@>) [] static member inline FindByContains<'TDoc>(conn, tableName, criteria: obj) = - WithProps.Find.ByContains<'TDoc>(tableName, criteria, Sql.existingConnection conn) + Find.ByContains<'TDoc>(tableName, criteria, Sql.existingConnection conn) /// Retrieve documents matching a JSON containment query (@>) ordered by the given fields in the document [] static member inline FindByContainsOrdered<'TDoc>(conn, tableName, criteria: obj, orderFields) = - WithProps.Find.ByContainsOrdered<'TDoc>(tableName, criteria, orderFields, Sql.existingConnection conn) + Find.ByContainsOrdered<'TDoc>(tableName, criteria, orderFields, Sql.existingConnection conn) /// Retrieve documents matching a JSON Path match query (@?) [] static member inline FindByJsonPath<'TDoc>(conn, tableName, jsonPath) = - WithProps.Find.ByJsonPath<'TDoc>(tableName, jsonPath, Sql.existingConnection conn) - + Find.ByJsonPath<'TDoc>(tableName, jsonPath, Sql.existingConnection conn) + /// Retrieve documents matching a JSON Path match query (@?) ordered by the given fields in the document [] static member inline FindByJsonPathOrdered<'TDoc>(conn, tableName, jsonPath, orderFields) = - WithProps.Find.ByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, Sql.existingConnection conn) - + Find.ByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, Sql.existingConnection conn) + /// Retrieve the first document matching a JSON field comparison query (->> =); returns null if not found [] static member inline FindFirstByFields<'TDoc when 'TDoc: null and 'TDoc: not struct>( conn, tableName, howMatched, fields) = - WithProps.Find.FirstByFields<'TDoc>(tableName, howMatched, fields, Sql.existingConnection conn) - + Find.FirstByFields<'TDoc>(tableName, howMatched, fields, Sql.existingConnection conn) + /// Retrieve the first document matching a JSON field comparison query (->> =) ordered by the given fields in the /// document; returns null if not found [] static member inline FindFirstByFieldsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>( conn, tableName, howMatched, queryFields, orderFields) = - WithProps.Find.FirstByFieldsOrdered<'TDoc>( + Find.FirstByFieldsOrdered<'TDoc>( tableName, howMatched, queryFields, orderFields, Sql.existingConnection conn) - + /// Retrieve the first document matching a JSON containment query (@>); returns None if not found [] static member inline FindFirstByContains<'TDoc when 'TDoc: null and 'TDoc: not struct>( conn, tableName, criteria: obj) = - WithProps.Find.FirstByContains<'TDoc>(tableName, criteria, Sql.existingConnection conn) + Find.FirstByContains<'TDoc>(tableName, criteria, Sql.existingConnection conn) /// Retrieve the first document matching a JSON containment query (@>) ordered by the given fields in the document; /// returns None if not found [] static member inline FindFirstByContainsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>( conn, tableName, criteria: obj, orderFields) = - WithProps.Find.FirstByContainsOrdered<'TDoc>(tableName, criteria, orderFields, Sql.existingConnection conn) + Find.FirstByContainsOrdered<'TDoc>(tableName, criteria, orderFields, Sql.existingConnection conn) /// Retrieve the first document matching a JSON Path match query (@?); returns None if not found [] static member inline FindFirstByJsonPath<'TDoc when 'TDoc: null and 'TDoc: not struct>(conn, tableName, jsonPath) = - WithProps.Find.FirstByJsonPath<'TDoc>(tableName, jsonPath, Sql.existingConnection conn) - + Find.FirstByJsonPath<'TDoc>(tableName, jsonPath, Sql.existingConnection conn) + /// Retrieve the first document matching a JSON Path match query (@?) ordered by the given fields in the document; /// returns None if not found [] static member inline FindFirstByJsonPathOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>( conn, tableName, jsonPath, orderFields) = - WithProps.Find.FirstByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, Sql.existingConnection conn) - + Find.FirstByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, Sql.existingConnection conn) + /// Update an entire document by its ID [] static member inline UpdateById(conn, tableName, docId: 'TKey, document: 'TDoc) = - WithProps.Update.byId tableName docId document (Sql.existingConnection conn) + Update.byId tableName docId document (Sql.existingConnection conn) /// Update an entire document by its ID, using the provided function to obtain the ID from the document [] static member inline UpdateByFunc(conn, tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc) = - WithProps.Update.ByFunc(tableName, idFunc, document, Sql.existingConnection conn) + Update.ByFunc(tableName, idFunc, document, Sql.existingConnection conn) /// Patch a document by its ID [] static member inline PatchById(conn, tableName, docId: 'TKey, patch: 'TPatch) = - WithProps.Patch.byId tableName docId patch (Sql.existingConnection conn) - + Patch.byId tableName docId patch (Sql.existingConnection conn) + /// Patch documents using a JSON field comparison query in the WHERE clause (->> =) [] static member inline PatchByFields(conn, tableName, howMatched, fields, patch: 'TPatch) = - WithProps.Patch.byFields tableName howMatched fields patch (Sql.existingConnection conn) - + Patch.byFields tableName howMatched fields patch (Sql.existingConnection conn) + /// Patch documents using a JSON containment query in the WHERE clause (@>) [] static member inline PatchByContains(conn, tableName, criteria: 'TCriteria, patch: 'TPatch) = - WithProps.Patch.byContains tableName criteria patch (Sql.existingConnection conn) - + Patch.byContains tableName criteria patch (Sql.existingConnection conn) + /// Patch documents using a JSON Path match query in the WHERE clause (@?) [] static member inline PatchByJsonPath(conn, tableName, jsonPath, patch: 'TPatch) = - WithProps.Patch.byJsonPath tableName jsonPath patch (Sql.existingConnection conn) - + Patch.byJsonPath tableName jsonPath patch (Sql.existingConnection conn) + /// Remove fields from a document by the document's ID [] static member inline RemoveFieldsById(conn, tableName, docId: 'TKey, fieldNames) = - WithProps.RemoveFields.byId tableName docId fieldNames (Sql.existingConnection conn) - + RemoveFields.byId tableName docId fieldNames (Sql.existingConnection conn) + /// Remove fields from documents via a comparison on JSON fields in the document [] static member inline RemoveFieldsByFields(conn, tableName, howMatched, fields, fieldNames) = - WithProps.RemoveFields.byFields tableName howMatched fields fieldNames (Sql.existingConnection conn) - + RemoveFields.byFields tableName howMatched fields fieldNames (Sql.existingConnection conn) + /// Remove fields from documents via a JSON containment query (@>) [] static member inline RemoveFieldsByContains(conn, tableName, criteria: 'TContains, fieldNames) = - WithProps.RemoveFields.byContains tableName criteria fieldNames (Sql.existingConnection conn) - + RemoveFields.byContains tableName criteria fieldNames (Sql.existingConnection conn) + /// Remove fields from documents via a JSON Path match query (@?) [] static member inline RemoveFieldsByJsonPath(conn, tableName, jsonPath, fieldNames) = - WithProps.RemoveFields.byJsonPath tableName jsonPath fieldNames (Sql.existingConnection conn) - + RemoveFields.byJsonPath tableName jsonPath fieldNames (Sql.existingConnection conn) + /// Delete a document by its ID [] static member inline DeleteById(conn, tableName, docId: 'TKey) = - WithProps.Delete.byId tableName docId (Sql.existingConnection conn) - + Delete.byId tableName docId (Sql.existingConnection conn) + /// Delete documents by matching a JSON field comparison query (->> =) [] static member inline DeleteByFields(conn, tableName, howMatched, fields) = - WithProps.Delete.byFields tableName howMatched fields (Sql.existingConnection conn) - + Delete.byFields tableName howMatched fields (Sql.existingConnection conn) + /// Delete documents by matching a JSON containment query (@>) [] static member inline DeleteByContains(conn, tableName, criteria: 'TContains) = - WithProps.Delete.byContains tableName criteria (Sql.existingConnection conn) + Delete.byContains tableName criteria (Sql.existingConnection conn) /// Delete documents by matching a JSON Path match query (@?) [] static member inline DeleteByJsonPath(conn, tableName, path) = - WithProps.Delete.byJsonPath tableName path (Sql.existingConnection conn) + Delete.byJsonPath tableName path (Sql.existingConnection conn) diff --git a/src/Postgres/Functions.fs b/src/Postgres/Functions.fs index ef699a8..fb189e9 100644 --- a/src/Postgres/Functions.fs +++ b/src/Postgres/Functions.fs @@ -528,7 +528,7 @@ module Patch = let byFields tableName howMatched fields (patch: 'TPatch) = WithProps.Patch.byFields tableName howMatched fields patch (fromDataSource ()) - /// Patch documents using a JSON containment query in the WHERE clause (@>) + /// Patch documents using a JSON containment query in the WHERE clause (@>) /// The table in which documents should be patched (may include schema) /// The document to match the containment query /// The partial document to patch the existing document @@ -536,7 +536,7 @@ module Patch = let byContains tableName (criteria: 'TCriteria) (patch: 'TPatch) = WithProps.Patch.byContains tableName criteria patch (fromDataSource ()) - /// Patch documents using a JSON Path match query in the WHERE clause (@?) + /// Patch documents using a JSON Path match query in the WHERE clause (@?) /// The table in which documents should be patched (may include schema) /// The JSON Path expression to match /// The partial document to patch the existing document diff --git a/src/Postgres/WithProps.fs b/src/Postgres/WithProps.fs index 4e03a26..6b0d05c 100644 --- a/src/Postgres/WithProps.fs +++ b/src/Postgres/WithProps.fs @@ -726,7 +726,7 @@ module Patch = (addFieldParams fields [ jsonParam "@data" patch ]) sqlProps - /// Patch documents using a JSON containment query in the WHERE clause (@>) + /// Patch documents using a JSON containment query in the WHERE clause (@>) /// The table in which documents should be patched (may include schema) /// The document to match the containment query /// The partial document to patch the existing document @@ -738,7 +738,7 @@ module Patch = [ jsonParam "@data" patch; jsonParam "@criteria" criteria ] sqlProps - /// Patch documents using a JSON Path match query in the WHERE clause (@?) + /// Patch documents using a JSON Path match query in the WHERE clause (@?) /// The table in which documents should be patched (may include schema) /// The JSON Path expression to match /// The partial document to patch the existing document