namespace BitBadger.Documents.Postgres
/// Commands to execute custom SQL queries
[]
module Custom =
/// 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
[]
let list<'TDoc> query parameters (mapFunc: RowReader -> 'TDoc) =
WithProps.Custom.list<'TDoc> query parameters mapFunc (fromDataSource ())
/// 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
let List<'TDoc>(query, parameters, mapFunc: System.Func) =
WithProps.Custom.List<'TDoc>(query, parameters, mapFunc, fromDataSource ())
/// 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
[]
let single<'TDoc> query parameters (mapFunc: RowReader -> 'TDoc) =
WithProps.Custom.single<'TDoc> query parameters mapFunc (fromDataSource ())
/// 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
/// The first matching result, or null if not found
let Single<'TDoc when 'TDoc: null and 'TDoc: not struct>(
query, parameters, mapFunc: System.Func) =
WithProps.Custom.Single<'TDoc>(query, parameters, mapFunc, fromDataSource ())
/// Execute a query that returns no results
/// The query to retrieve the results
/// Parameters to use for the query
[]
let nonQuery query parameters =
WithProps.Custom.nonQuery query parameters (fromDataSource ())
/// 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
[]
let scalar<'T when 'T: struct> query parameters (mapFunc: RowReader -> 'T) =
WithProps.Custom.scalar query parameters mapFunc (fromDataSource ())
/// 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
let Scalar<'T when 'T: struct>(query, parameters, mapFunc: System.Func) =
WithProps.Custom.Scalar<'T>(query, parameters, mapFunc, fromDataSource ())
/// Table and index definition commands
[]
module Definition =
/// Create a document table
/// The table whose existence should be ensured (may include schema)
[]
let ensureTable name =
WithProps.Definition.ensureTable name (fromDataSource ())
/// Create an index on documents in the specified table
/// The table to be indexed (may include schema)
/// The type of document index to create
[]
let ensureDocumentIndex name idxType =
WithProps.Definition.ensureDocumentIndex name idxType (fromDataSource ())
/// 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
[]
let ensureFieldIndex tableName indexName fields =
WithProps.Definition.ensureFieldIndex tableName indexName fields (fromDataSource ())
/// Document writing functions
[]
module Document =
/// Insert a new document
/// The table into which the document should be inserted (may include schema)
/// The document to be inserted
[]
let insert<'TDoc> tableName (document: 'TDoc) =
WithProps.Document.insert<'TDoc> tableName document (fromDataSource ())
/// 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
[]
let save<'TDoc> tableName (document: 'TDoc) =
WithProps.Document.save<'TDoc> tableName document (fromDataSource ())
/// Queries to count documents
[]
module Count =
/// 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
[]
let all tableName =
WithProps.Count.all tableName (fromDataSource ())
/// 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
[]
let byFields tableName howMatched fields =
WithProps.Count.byFields tableName howMatched fields (fromDataSource ())
/// 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
[]
let byContains tableName criteria =
WithProps.Count.byContains tableName criteria (fromDataSource ())
/// 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
[]
let byJsonPath tableName jsonPath =
WithProps.Count.byJsonPath tableName jsonPath (fromDataSource ())
/// Queries to determine if documents exist
[]
module Exists =
/// 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
[]
let byId tableName docId =
WithProps.Exists.byId tableName docId (fromDataSource ())
/// 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
[]
let byFields tableName howMatched fields =
WithProps.Exists.byFields tableName howMatched fields (fromDataSource ())
/// 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
[]
let byContains tableName criteria =
WithProps.Exists.byContains tableName criteria (fromDataSource ())
/// 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
[]
let byJsonPath tableName jsonPath =
WithProps.Exists.byJsonPath tableName jsonPath (fromDataSource ())
/// Commands to retrieve documents
[]
module Find =
/// Retrieve all documents in the given table
/// The table from which documents should be retrieved (may include schema)
/// All documents from the given table
[]
let all<'TDoc> tableName =
WithProps.Find.all<'TDoc> tableName (fromDataSource ())
/// Retrieve all documents in the given table
/// The table from which documents should be retrieved (may include schema)
/// All documents from the given table
let All<'TDoc> tableName =
WithProps.Find.All<'TDoc>(tableName, fromDataSource ())
/// 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
[]
let allOrdered<'TDoc> tableName orderFields =
WithProps.Find.allOrdered<'TDoc> tableName orderFields (fromDataSource ())
/// 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
let AllOrdered<'TDoc> tableName orderFields =
WithProps.Find.AllOrdered<'TDoc>(tableName, orderFields, fromDataSource ())
/// 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
[]
let byId<'TKey, 'TDoc> tableName docId =
WithProps.Find.byId<'TKey, 'TDoc> tableName docId (fromDataSource ())
/// 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
/// The document if found, null otherwise
let ById<'TKey, 'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, docId: 'TKey) =
WithProps.Find.ById<'TKey, 'TDoc>(tableName, docId, fromDataSource ())
/// 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
[]
let byFields<'TDoc> tableName howMatched fields =
WithProps.Find.byFields<'TDoc> tableName howMatched fields (fromDataSource ())
/// 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
let ByFields<'TDoc>(tableName, howMatched, fields) =
WithProps.Find.ByFields<'TDoc>(tableName, howMatched, fields, fromDataSource ())
///
/// 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
[]
let byFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields =
WithProps.Find.byFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields (fromDataSource ())
///
/// 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
let ByFieldsOrdered<'TDoc>(tableName, howMatched, queryFields, orderFields) =
WithProps.Find.ByFieldsOrdered<'TDoc>(tableName, howMatched, queryFields, orderFields, fromDataSource ())
/// 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
[]
let byContains<'TDoc> tableName (criteria: obj) =
WithProps.Find.byContains<'TDoc> tableName criteria (fromDataSource ())
/// 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
let ByContains<'TDoc>(tableName, criteria: obj) =
WithProps.Find.ByContains<'TDoc>(tableName, criteria, fromDataSource ())
///
/// 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
[]
let byContainsOrdered<'TDoc> tableName (criteria: obj) orderFields =
WithProps.Find.byContainsOrdered<'TDoc> tableName criteria orderFields (fromDataSource ())
///
/// 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
let ByContainsOrdered<'TDoc>(tableName, criteria: obj, orderFields) =
WithProps.Find.ByContainsOrdered<'TDoc>(tableName, criteria, orderFields, fromDataSource ())
/// 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
[]
let byJsonPath<'TDoc> tableName jsonPath =
WithProps.Find.byJsonPath<'TDoc> tableName jsonPath (fromDataSource ())
/// 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
let ByJsonPath<'TDoc>(tableName, jsonPath) =
WithProps.Find.ByJsonPath<'TDoc>(tableName, jsonPath, fromDataSource ())
///
/// 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
[]
let byJsonPathOrdered<'TDoc> tableName jsonPath orderFields =
WithProps.Find.byJsonPathOrdered<'TDoc> tableName jsonPath orderFields (fromDataSource ())
///
/// 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
let ByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields) =
WithProps.Find.ByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, fromDataSource ())
/// 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
[]
let firstByFields<'TDoc> tableName howMatched fields =
WithProps.Find.firstByFields<'TDoc> tableName howMatched fields (fromDataSource ())
/// 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
/// The first document, or null if not found
let FirstByFields<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, howMatched, fields) =
WithProps.Find.FirstByFields<'TDoc>(tableName, howMatched, fields, fromDataSource ())
///
/// 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
///
[]
let firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields =
WithProps.Find.firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields (fromDataSource ())
///
/// 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
/// The first document ordered by the given fields, or null if not found
let FirstByFieldsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
tableName, howMatched, queryFields, orderFields) =
WithProps.Find.FirstByFieldsOrdered<'TDoc>(tableName, howMatched, queryFields, orderFields, fromDataSource ())
/// 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
[]
let firstByContains<'TDoc> tableName (criteria: obj) =
WithProps.Find.firstByContains<'TDoc> tableName criteria (fromDataSource ())
/// 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
/// The first document, or null if not found
let FirstByContains<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, criteria: obj) =
WithProps.Find.FirstByContains<'TDoc>(tableName, criteria, fromDataSource ())
///
/// 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
///
[]
let firstByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields =
WithProps.Find.firstByContainsOrdered<'TDoc> tableName criteria orderFields (fromDataSource ())
///
/// 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
/// The first document ordered by the given fields, or null if not found
let FirstByContainsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, criteria: obj, orderFields) =
WithProps.Find.FirstByContainsOrdered<'TDoc>(tableName, criteria, orderFields, fromDataSource ())
/// 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
[]
let firstByJsonPath<'TDoc> tableName jsonPath =
WithProps.Find.firstByJsonPath<'TDoc> tableName jsonPath (fromDataSource ())
/// 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
/// The first document, or null if not found
let FirstByJsonPath<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, jsonPath) =
WithProps.Find.FirstByJsonPath<'TDoc>(tableName, jsonPath, fromDataSource ())
///
/// 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
///
[]
let firstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields =
WithProps.Find.firstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields (fromDataSource ())
///
/// 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
/// The first document ordered by the given fields, or null if not found
let FirstByJsonPathOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, jsonPath, orderFields) =
WithProps.Find.FirstByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, fromDataSource ())
/// Commands to update documents
[]
module Update =
/// 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
[]
let byId tableName (docId: 'TKey) (document: 'TDoc) =
WithProps.Update.byId tableName docId document (fromDataSource ())
///
/// 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
[]
let byFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) =
WithProps.Update.byFunc tableName idFunc document (fromDataSource ())
///
/// 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
let ByFunc(tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc) =
WithProps.Update.ByFunc(tableName, idFunc, document, fromDataSource ())
/// Commands to patch (partially update) documents
[]
module Patch =
/// 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
[]
let byId tableName (docId: 'TKey) (patch: 'TPatch) =
WithProps.Patch.byId tableName docId patch (fromDataSource ())
///
/// 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
[]
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 (@>)
/// 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
[]
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 (@?)
/// 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
[]
let byJsonPath tableName jsonPath (patch: 'TPatch) =
WithProps.Patch.byJsonPath tableName jsonPath patch (fromDataSource ())
/// Commands to remove fields from documents
[]
module RemoveFields =
/// 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
[]
let byId tableName (docId: 'TKey) fieldNames =
WithProps.RemoveFields.byId tableName docId fieldNames (fromDataSource ())
/// 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
[]
let byFields tableName howMatched fields fieldNames =
WithProps.RemoveFields.byFields tableName howMatched fields fieldNames (fromDataSource ())
/// 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
[]
let byContains tableName (criteria: 'TContains) fieldNames =
WithProps.RemoveFields.byContains tableName criteria fieldNames (fromDataSource ())
/// 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
[]
let byJsonPath tableName jsonPath fieldNames =
WithProps.RemoveFields.byJsonPath tableName jsonPath fieldNames (fromDataSource ())
/// Commands to delete documents
[]
module Delete =
/// 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
[]
let byId tableName (docId: 'TKey) =
WithProps.Delete.byId tableName docId (fromDataSource ())
/// 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
[]
let byFields tableName howMatched fields =
WithProps.Delete.byFields tableName howMatched fields (fromDataSource ())
/// 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
[]
let byContains tableName (criteria: 'TContains) =
WithProps.Delete.byContains tableName criteria (fromDataSource ())
/// 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
[]
let byJsonPath tableName jsonPath =
WithProps.Delete.byJsonPath tableName jsonPath (fromDataSource ())