diff --git a/src/Sqlite/Functions.fs b/src/Sqlite/Functions.fs
index 24c3316..2b0ec65 100644
--- a/src/Sqlite/Functions.fs
+++ b/src/Sqlite/Functions.fs
@@ -25,11 +25,49 @@ module Custom =
use conn = Configuration.dbConn ()
WithConn.Custom.List<'TDoc>(query, parameters, mapFunc, conn)
+ /// Execute a query that returns a JSON array of results
+ /// The query to retrieve the results
+ /// Parameters to use for the query
+ /// The mapping function to extract the document
+ /// A JSON array of results for the given query
+ []
+ let jsonArray query parameters mapFunc =
+ use conn = Configuration.dbConn ()
+ WithConn.Custom.jsonArray query parameters mapFunc conn
+
+ /// Execute a query that returns a JSON array of results
+ /// The query to retrieve the results
+ /// Parameters to use for the query
+ /// The mapping function to extract the document
+ /// A JSON array of results for the given query
+ let JsonArray(query, parameters, mapFunc) =
+ use conn = Configuration.dbConn ()
+ WithConn.Custom.JsonArray(query, parameters, mapFunc, conn)
+
+ /// Execute a query, writing its results to the given StreamWriter
+ /// The query to retrieve the results
+ /// Parameters to use for the query
+ /// The StreamWriter to which the results should be written
+ /// The mapping function to extract the document
+ []
+ let writeJsonArray query parameters writer mapFunc =
+ use conn = Configuration.dbConn ()
+ WithConn.Custom.writeJsonArray query parameters writer mapFunc conn
+
+ /// Execute a query, writing its results to the given StreamWriter
+ /// The query to retrieve the results
+ /// Parameters to use for the query
+ /// The StreamWriter to which the results should be written
+ /// The mapping function to extract the document
+ let WriteJsonArray(query, parameters, writer, mapFunc) =
+ use conn = Configuration.dbConn ()
+ WithConn.Custom.WriteJsonArray(query, parameters, writer, mapFunc, conn)
+
/// 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
+ /// Some with the first matching result, or None if not found
[]
let single<'TDoc> query parameters (mapFunc: SqliteDataReader -> 'TDoc) =
use conn = Configuration.dbConn ()
@@ -39,12 +77,31 @@ module Custom =
/// 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
+ /// The first matching result, or null if not found
let Single<'TDoc when 'TDoc: null and 'TDoc: not struct>(
query, parameters, mapFunc: System.Func) =
use conn = Configuration.dbConn ()
WithConn.Custom.Single<'TDoc>(query, parameters, mapFunc, conn)
+ /// Execute a query that returns one or no JSON documents
+ /// The query to retrieve the results
+ /// Parameters to use for the query
+ /// The mapping function to extract the document
+ /// The JSON document with the first matching result, or an empty document if not found
+ []
+ let jsonSingle query parameters mapFunc =
+ use conn = Configuration.dbConn ()
+ WithConn.Custom.jsonSingle query parameters mapFunc conn
+
+ /// Execute a query that returns one or no JSON documents
+ /// The query to retrieve the results
+ /// Parameters to use for the query
+ /// The mapping function to extract the document
+ /// The JSON document with the first matching result, or an empty document if not found
+ let JsonSingle(query, parameters, mapFunc) =
+ use conn = Configuration.dbConn ()
+ WithConn.Custom.JsonSingle(query, parameters, mapFunc, conn)
+
/// Execute a query that returns no results
/// The query to retrieve the results
/// Parameters to use for the query
@@ -127,7 +184,7 @@ module Count =
use conn = Configuration.dbConn ()
WithConn.Count.all tableName conn
- /// Count matching documents using JSON field comparisons (->> =, etc.)
+ /// 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
@@ -151,7 +208,7 @@ module Exists =
use conn = Configuration.dbConn ()
WithConn.Exists.byId tableName docId conn
- /// Determine if a document exists using JSON field comparisons (->> =, etc.)
+ /// 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
@@ -201,7 +258,7 @@ module Find =
/// 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
+ /// Some with the document if found, None otherwise
[]
let byId<'TKey, 'TDoc> tableName docId =
use conn = Configuration.dbConn ()
@@ -210,12 +267,12 @@ module Find =
/// 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
+ /// The document if found, null otherwise
let ById<'TKey, 'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, docId) =
use conn = Configuration.dbConn ()
WithConn.Find.ById<'TKey, 'TDoc>(tableName, docId, conn)
- /// Retrieve documents matching JSON field comparisons (->> =, etc.)
+ /// 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
@@ -225,7 +282,7 @@ module Find =
use conn = Configuration.dbConn ()
WithConn.Find.byFields<'TDoc> tableName howMatched fields conn
- /// Retrieve documents matching JSON field comparisons (->> =, etc.)
+ /// 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
@@ -235,8 +292,8 @@ module Find =
WithConn.Find.ByFields<'TDoc>(tableName, howMatched, fields, conn)
///
- /// Retrieve documents matching JSON field comparisons (->> =, etc.) ordered by the given fields in
- /// the document
+ /// 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
@@ -249,8 +306,8 @@ module Find =
WithConn.Find.byFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields conn
///
- /// Retrieve documents matching JSON field comparisons (->> =, etc.) ordered by the given fields in
- /// the document
+ /// 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
@@ -261,27 +318,27 @@ module Find =
use conn = Configuration.dbConn ()
WithConn.Find.ByFieldsOrdered<'TDoc>(tableName, howMatched, queryFields, orderFields, conn)
- /// Retrieve the first document matching JSON field comparisons (->> =, etc.)
+ /// 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
+ /// Some with the first document, or None if not found
[]
let firstByFields<'TDoc> tableName howMatched fields =
use conn = Configuration.dbConn ()
WithConn.Find.firstByFields<'TDoc> tableName howMatched fields conn
- /// Retrieve the first document matching JSON field comparisons (->> =, etc.)
+ /// 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
+ /// The first document, or null if not found
let FirstByFields<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, howMatched, fields) =
use conn = Configuration.dbConn ()
WithConn.Find.FirstByFields<'TDoc>(tableName, howMatched, fields, conn)
///
- /// Retrieve the first document matching JSON field comparisons (->> =, etc.) ordered by the given
+ /// 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)
@@ -289,7 +346,7 @@ module Find =
/// 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
+ /// Some with the first document ordered by the given fields, or None if not found
///
[]
let firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields =
@@ -297,20 +354,181 @@ module Find =
WithConn.Find.firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields conn
///
- /// Retrieve the first document matching JSON field comparisons (->> =, etc.) ordered by the given
+ /// 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
+ /// 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) =
use conn = Configuration.dbConn ()
WithConn.Find.FirstByFieldsOrdered<'TDoc>(tableName, howMatched, queryFields, orderFields, conn)
+/// Commands to retrieve documents as raw JSON
+[]
+module Json =
+
+ /// Retrieve all JSON documents in the given table
+ /// The table from which documents should be retrieved (may include schema)
+ /// All JSON documents from the given table
+ []
+ let all tableName =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.all tableName conn
+
+ /// Retrieve all JSON 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 JSON documents from the given table, ordered by the given fields
+ []
+ let allOrdered tableName orderFields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.allOrdered tableName orderFields conn
+
+ /// Retrieve a JSON document by its ID
+ /// The table from which a document should be retrieved (may include schema)
+ /// The ID of the document to retrieve
+ /// The JSON document if found, an empty JSON document otherwise
+ []
+ let byId<'TKey> tableName (docId: 'TKey) =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.byId tableName docId conn
+
+ /// Retrieve JSON 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 JSON documents matching the given fields
+ []
+ let byFields tableName howMatched fields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.byFields tableName howMatched fields conn
+
+ ///
+ /// Retrieve JSON 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 JSON documents matching the given fields, ordered by the other given fields
+ []
+ let byFieldsOrdered tableName howMatched queryFields orderFields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.byFieldsOrdered tableName howMatched queryFields orderFields conn
+
+ /// Retrieve the first JSON 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 JSON document if found, an empty JSON document otherwise
+ []
+ let firstByFields tableName howMatched fields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.firstByFields tableName howMatched fields conn
+
+ ///
+ /// Retrieve the first JSON 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 JSON document (in order) if found, an empty JSON document otherwise
+ []
+ let firstByFieldsOrdered tableName howMatched queryFields orderFields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.firstByFieldsOrdered tableName howMatched queryFields orderFields conn
+
+ /// Write all JSON documents in the given table to the given StreamWriter
+ /// The table from which documents should be retrieved (may include schema)
+ /// The StreamWriter to which the results should be written
+ []
+ let writeAll tableName writer =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.writeAll tableName writer conn
+
+ ///
+ /// Write all JSON all documents in the given table to the given StreamWriter, ordered by the given fields in
+ /// the document
+ ///
+ /// The table from which documents should be retrieved (may include schema)
+ /// The StreamWriter to which the results should be written
+ /// Fields by which the results should be ordered
+ []
+ let writeAllOrdered tableName writer orderFields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.writeAllOrdered tableName writer orderFields conn
+
+ /// Write a JSON document to the given StreamWriter by its ID
+ /// The table from which a document should be retrieved (may include schema)
+ /// The StreamWriter to which the results should be written
+ /// The ID of the document to retrieve
+ []
+ let writeById<'TKey> tableName writer (docId: 'TKey) =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.writeById tableName writer docId conn
+
+ ///
+ /// Write JSON documents to the given StreamWriter matching JSON field comparisons (->> =, etc.)
+ ///
+ /// The table from which documents should be retrieved (may include schema)
+ /// The StreamWriter to which the results should be written
+ /// Whether to match any or all of the field conditions
+ /// The field conditions to match
+ []
+ let writeByFields tableName writer howMatched fields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.writeByFields tableName writer howMatched fields conn
+
+ ///
+ /// Write JSON documents to the given StreamWriter matching JSON field comparisons (->> =, etc.)
+ /// ordered by the given fields in the document
+ ///
+ /// The table from which documents should be retrieved (may include schema)
+ /// The StreamWriter to which the results should be written
+ /// Whether to match any or all of the field conditions
+ /// The field conditions to match
+ /// Fields by which the results should be ordered
+ []
+ let writeByFieldsOrdered tableName writer howMatched queryFields orderFields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.writeByFieldsOrdered tableName writer howMatched queryFields orderFields conn
+
+ ///
+ /// Write the first JSON document to the given StreamWriter matching JSON field comparisons
+ /// (->> =, etc.)
+ ///
+ /// The table from which a document should be retrieved (may include schema)
+ /// The StreamWriter to which the results should be written
+ /// Whether to match any or all of the field conditions
+ /// The field conditions to match
+ []
+ let writeFirstByFields tableName writer howMatched fields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.writeFirstByFields tableName writer howMatched fields conn
+
+ ///
+ /// Write the first JSON document to the given StreamWriter 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)
+ /// The StreamWriter to which the results should be written
+ /// Whether to match any or all of the field conditions
+ /// The field conditions to match
+ /// Fields by which the results should be ordered
+ []
+ let writeFirstByFieldsOrdered tableName writer howMatched queryFields orderFields =
+ use conn = Configuration.dbConn ()
+ WithConn.Json.writeFirstByFieldsOrdered tableName writer howMatched queryFields orderFields conn
+
+
/// Commands to update documents
[]
module Update =
@@ -360,7 +578,7 @@ module Patch =
WithConn.Patch.byId tableName docId patch conn
///
- /// Patch documents using a JSON field comparison query in the WHERE clause (->> =, etc.)
+ /// 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
@@ -408,7 +626,7 @@ module Delete =
use conn = Configuration.dbConn ()
WithConn.Delete.byId tableName docId conn
- /// Delete documents by matching a JSON field comparison query (->> =, etc.)
+ /// 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
diff --git a/src/Sqlite/WithConn.fs b/src/Sqlite/WithConn.fs
index 0a163b0..1006a3f 100644
--- a/src/Sqlite/WithConn.fs
+++ b/src/Sqlite/WithConn.fs
@@ -630,7 +630,6 @@ module Json =
/// Whether to match any or all of the field conditions
/// The field conditions to match
/// The SqliteConnection to use to execute the query
- /// The first JSON document if found, an empty JSON document otherwise
[]
let writeFirstByFields tableName (writer: StreamWriter) howMatched fields conn = backgroundTask {
let! json =
@@ -649,7 +648,6 @@ module Json =
/// The field conditions to match
/// Fields by which the results should be ordered
/// The SqliteConnection to use to execute the query
- /// The first JSON document (in order) if found, an empty JSON document otherwise
[]
let writeFirstByFieldsOrdered tableName (writer: StreamWriter) howMatched queryFields orderFields conn =
backgroundTask {