v4.1 #11
@ -3,11 +3,10 @@
|
|||||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||||
<DebugType>embedded</DebugType>
|
<DebugType>embedded</DebugType>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<AssemblyVersion>4.0.1.0</AssemblyVersion>
|
<AssemblyVersion>4.1.0.0</AssemblyVersion>
|
||||||
<FileVersion>4.0.1.0</FileVersion>
|
<FileVersion>4.1.0.0</FileVersion>
|
||||||
<VersionPrefix>4.0.1</VersionPrefix>
|
<VersionPrefix>4.1.0</VersionPrefix>
|
||||||
<PackageReleaseNotes>From v4.0: Add XML documention (IDE support)
|
<PackageReleaseNotes>Add JSON retrieval and stream-writing functions</PackageReleaseNotes>
|
||||||
From v3.1: See 4.0 release for breaking changes and compatibility</PackageReleaseNotes>
|
|
||||||
<Authors>danieljsummers</Authors>
|
<Authors>danieljsummers</Authors>
|
||||||
<Company>Bit Badger Solutions</Company>
|
<Company>Bit Badger Solutions</Company>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/// <summary>Versions of queries that accept a <c>SqliteConnection</c> as the last parameter</summary>
|
/// <summary>Versions of queries that accept a <c>SqliteConnection</c> as the last parameter</summary>
|
||||||
module BitBadger.Documents.Sqlite.WithConn
|
module BitBadger.Documents.Sqlite.WithConn
|
||||||
|
|
||||||
|
open System.IO
|
||||||
open BitBadger.Documents
|
open BitBadger.Documents
|
||||||
open Microsoft.Data.Sqlite
|
open Microsoft.Data.Sqlite
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ module Custom =
|
|||||||
/// <param name="query">The query to retrieve the results</param>
|
/// <param name="query">The query to retrieve the results</param>
|
||||||
/// <param name="parameters">Parameters to use for the query</param>
|
/// <param name="parameters">Parameters to use for the query</param>
|
||||||
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>A list of results for the given query</returns>
|
/// <returns>A list of results for the given query</returns>
|
||||||
[<CompiledName "FSharpList">]
|
[<CompiledName "FSharpList">]
|
||||||
let list<'TDoc> query (parameters: SqliteParameter seq) (mapFunc: SqliteDataReader -> 'TDoc)
|
let list<'TDoc> query (parameters: SqliteParameter seq) (mapFunc: SqliteDataReader -> 'TDoc)
|
||||||
@ -26,7 +27,7 @@ module Custom =
|
|||||||
/// <param name="query">The query to retrieve the results</param>
|
/// <param name="query">The query to retrieve the results</param>
|
||||||
/// <param name="parameters">Parameters to use for the query</param>
|
/// <param name="parameters">Parameters to use for the query</param>
|
||||||
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>A list of results for the given query</returns>
|
/// <returns>A list of results for the given query</returns>
|
||||||
let List<'TDoc>(
|
let List<'TDoc>(
|
||||||
query, parameters: SqliteParameter seq, mapFunc: System.Func<SqliteDataReader, 'TDoc>,
|
query, parameters: SqliteParameter seq, mapFunc: System.Func<SqliteDataReader, 'TDoc>,
|
||||||
@ -37,12 +38,65 @@ module Custom =
|
|||||||
cmd.Parameters.AddRange parameters
|
cmd.Parameters.AddRange parameters
|
||||||
ToCustomList<'TDoc>(cmd, mapFunc)
|
ToCustomList<'TDoc>(cmd, mapFunc)
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>A JSON array of results for the given query</returns>
|
||||||
|
[<CompiledName "FSharpJsonArray">]
|
||||||
|
let jsonArray
|
||||||
|
query
|
||||||
|
(parameters: SqliteParameter seq)
|
||||||
|
(mapFunc: SqliteDataReader -> string)
|
||||||
|
(conn: SqliteConnection) =
|
||||||
|
use cmd = conn.CreateCommand()
|
||||||
|
cmd.CommandText <- query
|
||||||
|
cmd.Parameters.AddRange parameters
|
||||||
|
toJsonArray cmd mapFunc
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>A JSON array of results for the given query</returns>
|
||||||
|
let JsonArray(query, parameters, mapFunc: System.Func<SqliteDataReader, string>, conn) =
|
||||||
|
jsonArray query parameters mapFunc.Invoke conn
|
||||||
|
|
||||||
|
/// <summary>Execute a query, writing its results to the given <c>StreamWriter</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 StreamWriter to which the results should be written</param>
|
||||||
|
/// <param name="mapFunc">The mapping function to extract the document</param>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
[<CompiledName "FSharpWriteJsonArray">]
|
||||||
|
let writeJsonArray
|
||||||
|
query
|
||||||
|
(parameters: SqliteParameter seq)
|
||||||
|
writer
|
||||||
|
(mapFunc: SqliteDataReader -> string)
|
||||||
|
(conn: SqliteConnection) =
|
||||||
|
use cmd = conn.CreateCommand()
|
||||||
|
cmd.CommandText <- query
|
||||||
|
cmd.Parameters.AddRange parameters
|
||||||
|
writeJsonArray cmd writer mapFunc
|
||||||
|
|
||||||
|
/// <summary>Execute a query, writing its results to the given <c>StreamWriter</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 StreamWriter to which the results should be written</param>
|
||||||
|
/// <param name="mapFunc">The mapping function to extract the document</param>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
let WriteJsonArray(query, parameters, writer, mapFunc: System.Func<SqliteDataReader, string>, conn) =
|
||||||
|
writeJsonArray query parameters writer mapFunc.Invoke conn
|
||||||
|
|
||||||
/// <summary>Execute a query that returns one or no results</summary>
|
/// <summary>Execute a query that returns one or no results</summary>
|
||||||
/// <param name="query">The query to retrieve the results</param>
|
/// <param name="query">The query to retrieve the results</param>
|
||||||
/// <param name="parameters">Parameters to use for the query</param>
|
/// <param name="parameters">Parameters to use for the query</param>
|
||||||
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns><tt>Some</tt> with the first matching result, or <tt>None</tt> if not found</returns>
|
/// <returns><c>Some</c> with the first matching result, or <c>None</c> if not found</returns>
|
||||||
[<CompiledName "FSharpSingle">]
|
[<CompiledName "FSharpSingle">]
|
||||||
let single<'TDoc> query parameters (mapFunc: SqliteDataReader -> 'TDoc) conn = backgroundTask {
|
let single<'TDoc> query parameters (mapFunc: SqliteDataReader -> 'TDoc) conn = backgroundTask {
|
||||||
let! results = list query parameters mapFunc conn
|
let! results = list query parameters mapFunc conn
|
||||||
@ -53,8 +107,8 @@ module Custom =
|
|||||||
/// <param name="query">The query to retrieve the results</param>
|
/// <param name="query">The query to retrieve the results</param>
|
||||||
/// <param name="parameters">Parameters to use for the query</param>
|
/// <param name="parameters">Parameters to use for the query</param>
|
||||||
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
/// <param name="mapFunc">The mapping function between the document and the domain item</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>The first matching result, or <tt>null</tt> if not found</returns>
|
/// <returns>The first matching result, or <c>null</c> if not found</returns>
|
||||||
let Single<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
let Single<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||||
query, parameters, mapFunc: System.Func<SqliteDataReader, 'TDoc>, conn
|
query, parameters, mapFunc: System.Func<SqliteDataReader, 'TDoc>, conn
|
||||||
) = backgroundTask {
|
) = backgroundTask {
|
||||||
@ -62,10 +116,31 @@ module Custom =
|
|||||||
return Option.toObj result
|
return Option.toObj result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>The JSON document with the first matching result, or an empty document if not found</returns>
|
||||||
|
[<CompiledName "FSharpJsonSingle">]
|
||||||
|
let jsonSingle query parameters mapFunc conn = backgroundTask {
|
||||||
|
let! results = jsonArray $"%s{query} LIMIT 1" parameters mapFunc conn
|
||||||
|
return if results = "[]" then "{}" else results[1..results.Length - 2]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>The JSON document with the first matching result, or an empty document if not found</returns>
|
||||||
|
let JsonSingle(query, parameters, mapFunc: System.Func<SqliteDataReader, string>, conn) =
|
||||||
|
jsonSingle query parameters mapFunc.Invoke conn
|
||||||
|
|
||||||
/// <summary>Execute a query that returns no results</summary>
|
/// <summary>Execute a query that returns no results</summary>
|
||||||
/// <param name="query">The query to retrieve the results</param>
|
/// <param name="query">The query to retrieve the results</param>
|
||||||
/// <param name="parameters">Parameters to use for the query</param>
|
/// <param name="parameters">Parameters to use for the query</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "NonQuery">]
|
[<CompiledName "NonQuery">]
|
||||||
let nonQuery query (parameters: SqliteParameter seq) (conn: SqliteConnection) =
|
let nonQuery query (parameters: SqliteParameter seq) (conn: SqliteConnection) =
|
||||||
use cmd = conn.CreateCommand()
|
use cmd = conn.CreateCommand()
|
||||||
@ -77,7 +152,7 @@ module Custom =
|
|||||||
/// <param name="query">The query to retrieve the value</param>
|
/// <param name="query">The query to retrieve the value</param>
|
||||||
/// <param name="parameters">Parameters to use for the query</param>
|
/// <param name="parameters">Parameters to use for the query</param>
|
||||||
/// <param name="mapFunc">The mapping function to obtain the value</param>
|
/// <param name="mapFunc">The mapping function to obtain the value</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>The scalar value for the query</returns>
|
/// <returns>The scalar value for the query</returns>
|
||||||
[<CompiledName "FSharpScalar">]
|
[<CompiledName "FSharpScalar">]
|
||||||
let scalar<'T when 'T : struct> query (parameters: SqliteParameter seq) (mapFunc: SqliteDataReader -> 'T)
|
let scalar<'T when 'T : struct> query (parameters: SqliteParameter seq) (mapFunc: SqliteDataReader -> 'T)
|
||||||
@ -94,18 +169,19 @@ module Custom =
|
|||||||
/// <param name="query">The query to retrieve the value</param>
|
/// <param name="query">The query to retrieve the value</param>
|
||||||
/// <param name="parameters">Parameters to use for the query</param>
|
/// <param name="parameters">Parameters to use for the query</param>
|
||||||
/// <param name="mapFunc">The mapping function to obtain the value</param>
|
/// <param name="mapFunc">The mapping function to obtain the value</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>The scalar value for the query</returns>
|
/// <returns>The scalar value for the query</returns>
|
||||||
let Scalar<'T when 'T: struct>(query, parameters, mapFunc: System.Func<SqliteDataReader, 'T>, conn) =
|
let Scalar<'T when 'T: struct>(query, parameters, mapFunc: System.Func<SqliteDataReader, 'T>, conn) =
|
||||||
scalar<'T> query parameters mapFunc.Invoke conn
|
scalar<'T> query parameters mapFunc.Invoke conn
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Functions to create tables and indexes</summary>
|
/// <summary>Functions to create tables and indexes</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module Definition =
|
module Definition =
|
||||||
|
|
||||||
/// <summary>Create a document table</summary>
|
/// <summary>Create a document table</summary>
|
||||||
/// <param name="name">The table whose existence should be ensured (may include schema)</param>
|
/// <param name="name">The table whose existence should be ensured (may include schema)</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "EnsureTable">]
|
[<CompiledName "EnsureTable">]
|
||||||
let ensureTable name conn = backgroundTask {
|
let ensureTable name conn = backgroundTask {
|
||||||
do! Custom.nonQuery (Query.Definition.ensureTable name) [] conn
|
do! Custom.nonQuery (Query.Definition.ensureTable name) [] conn
|
||||||
@ -116,7 +192,7 @@ module Definition =
|
|||||||
/// <param name="tableName">The table to be indexed (may include schema)</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="indexName">The name of the index to create</param>
|
||||||
/// <param name="fields">One or more fields to be indexed</param>
|
/// <param name="fields">One or more fields to be indexed</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "EnsureFieldIndex">]
|
[<CompiledName "EnsureFieldIndex">]
|
||||||
let ensureFieldIndex tableName indexName fields conn =
|
let ensureFieldIndex tableName indexName fields conn =
|
||||||
Custom.nonQuery (Query.Definition.ensureIndexOn tableName indexName fields SQLite) [] conn
|
Custom.nonQuery (Query.Definition.ensureIndexOn tableName indexName fields SQLite) [] conn
|
||||||
@ -128,7 +204,7 @@ module Document =
|
|||||||
/// <summary>Insert a new document</summary>
|
/// <summary>Insert a new document</summary>
|
||||||
/// <param name="tableName">The table into which the document should be inserted (may include schema)</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>
|
/// <param name="document">The document to be inserted</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "Insert">]
|
[<CompiledName "Insert">]
|
||||||
let insert<'TDoc> tableName (document: 'TDoc) conn =
|
let insert<'TDoc> tableName (document: 'TDoc) conn =
|
||||||
let query =
|
let query =
|
||||||
@ -148,39 +224,39 @@ module Document =
|
|||||||
(Query.insert tableName).Replace("@data", dataParam)
|
(Query.insert tableName).Replace("@data", dataParam)
|
||||||
Custom.nonQuery query [ jsonParam "@data" document ] conn
|
Custom.nonQuery query [ jsonParam "@data" document ] conn
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert")</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="tableName">The table into which the document should be saved (may include schema)</param>
|
||||||
/// <param name="document">The document to be saved</param>
|
/// <param name="document">The document to be saved</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "Save">]
|
[<CompiledName "Save">]
|
||||||
let save<'TDoc> tableName (document: 'TDoc) conn =
|
let save<'TDoc> tableName (document: 'TDoc) conn =
|
||||||
Custom.nonQuery (Query.save tableName) [ jsonParam "@data" document ] conn
|
Custom.nonQuery (Query.save tableName) [ jsonParam "@data" document ] conn
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Commands to count documents</summary>
|
/// <summary>Commands to count documents</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module Count =
|
module Count =
|
||||||
|
|
||||||
/// <summary>Count all documents in a table</summary>
|
/// <summary>Count all documents in a table</summary>
|
||||||
/// <param name="tableName">The table in which documents should be counted (may include schema)</param>
|
/// <param name="tableName">The table in which documents should be counted (may include schema)</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>The count of the documents in the table</returns>
|
/// <returns>The count of the documents in the table</returns>
|
||||||
[<CompiledName "All">]
|
[<CompiledName "All">]
|
||||||
let all tableName conn =
|
let all tableName conn =
|
||||||
Custom.scalar (Query.count tableName) [] toCount conn
|
Custom.scalar (Query.count tableName) [] toCount conn
|
||||||
|
|
||||||
/// <summary>Count matching documents using JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
/// <summary>Count matching documents using JSON field comparisons (<c>->> =</c>, etc.)</summary>
|
||||||
/// <param name="tableName">The table in which documents should be counted (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="fields">The field conditions to match</param>
|
/// <param name="fields">The field conditions to match</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>The count of matching documents in the table</returns>
|
/// <returns>The count of matching documents in the table</returns>
|
||||||
[<CompiledName "ByFields">]
|
[<CompiledName "ByFields">]
|
||||||
let byFields tableName howMatched fields conn =
|
let byFields tableName howMatched fields conn =
|
||||||
Custom.scalar
|
Custom.scalar
|
||||||
(Query.byFields (Query.count tableName) howMatched fields) (addFieldParams fields []) toCount conn
|
(Query.byFields (Query.count tableName) howMatched fields) (addFieldParams fields []) toCount conn
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Commands to determine if documents exist</summary>
|
/// <summary>Commands to determine if documents exist</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module Exists =
|
module Exists =
|
||||||
@ -188,17 +264,17 @@ module Exists =
|
|||||||
/// <summary>Determine if a document exists for the given ID</summary>
|
/// <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="tableName">The table in which existence should be checked (may include schema)</param>
|
||||||
/// <param name="docId">The ID of the document whose existence should be checked</param>
|
/// <param name="docId">The ID of the document whose existence should be checked</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>True if a document exists, false if not</returns>
|
/// <returns>True if a document exists, false if not</returns>
|
||||||
[<CompiledName "ById">]
|
[<CompiledName "ById">]
|
||||||
let byId tableName (docId: 'TKey) conn =
|
let byId tableName (docId: 'TKey) conn =
|
||||||
Custom.scalar (Query.exists tableName (Query.whereById docId)) [ idParam docId ] toExists conn
|
Custom.scalar (Query.exists tableName (Query.whereById docId)) [ idParam docId ] toExists conn
|
||||||
|
|
||||||
/// <summary>Determine if a document exists using JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
/// <summary>Determine if a document exists using JSON field comparisons (<c>->> =</c>, etc.)</summary>
|
||||||
/// <param name="tableName">The table in which existence should be checked (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="fields">The field conditions to match</param>
|
/// <param name="fields">The field conditions to match</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>True if any matching documents exist, false if not</returns>
|
/// <returns>True if any matching documents exist, false if not</returns>
|
||||||
[<CompiledName "ByFields">]
|
[<CompiledName "ByFields">]
|
||||||
let byFields tableName howMatched fields conn =
|
let byFields tableName howMatched fields conn =
|
||||||
@ -208,13 +284,14 @@ module Exists =
|
|||||||
toExists
|
toExists
|
||||||
conn
|
conn
|
||||||
|
|
||||||
/// <summary>Commands to retrieve documents</summary>
|
|
||||||
|
/// <summary>Commands to retrieve documents as domain items</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module Find =
|
module Find =
|
||||||
|
|
||||||
/// <summary>Retrieve all documents in the given table</summary>
|
/// <summary>Retrieve all documents in the given table</summary>
|
||||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>All documents from the given table</returns>
|
/// <returns>All documents from the given table</returns>
|
||||||
[<CompiledName "FSharpAll">]
|
[<CompiledName "FSharpAll">]
|
||||||
let all<'TDoc> tableName conn =
|
let all<'TDoc> tableName conn =
|
||||||
@ -222,7 +299,7 @@ module Find =
|
|||||||
|
|
||||||
/// <summary>Retrieve all documents in the given table</summary>
|
/// <summary>Retrieve all documents in the given table</summary>
|
||||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>All documents from the given table</returns>
|
/// <returns>All documents from the given table</returns>
|
||||||
let All<'TDoc>(tableName, conn) =
|
let All<'TDoc>(tableName, conn) =
|
||||||
Custom.List(Query.find tableName, [], fromData<'TDoc>, conn)
|
Custom.List(Query.find tableName, [], fromData<'TDoc>, conn)
|
||||||
@ -230,7 +307,7 @@ module Find =
|
|||||||
/// <summary>Retrieve all documents in the given table ordered by the given fields in the document</summary>
|
/// <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="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>All documents from the given table, ordered by the given fields</returns>
|
/// <returns>All documents from the given table, ordered by the given fields</returns>
|
||||||
[<CompiledName "FSharpAllOrdered">]
|
[<CompiledName "FSharpAllOrdered">]
|
||||||
let allOrdered<'TDoc> tableName orderFields conn =
|
let allOrdered<'TDoc> tableName orderFields conn =
|
||||||
@ -239,7 +316,7 @@ module Find =
|
|||||||
/// <summary>Retrieve all documents in the given table ordered by the given fields in the document</summary>
|
/// <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="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>All documents from the given table, ordered by the given fields</returns>
|
/// <returns>All documents from the given table, ordered by the given fields</returns>
|
||||||
let AllOrdered<'TDoc>(tableName, orderFields, conn) =
|
let AllOrdered<'TDoc>(tableName, orderFields, conn) =
|
||||||
Custom.List(Query.find tableName + Query.orderBy orderFields SQLite, [], fromData<'TDoc>, conn)
|
Custom.List(Query.find tableName + Query.orderBy orderFields SQLite, [], fromData<'TDoc>, conn)
|
||||||
@ -247,8 +324,8 @@ module Find =
|
|||||||
/// <summary>Retrieve a document by its ID</summary>
|
/// <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="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||||
/// <param name="docId">The ID of the document to retrieve</param>
|
/// <param name="docId">The ID of the document to retrieve</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns><tt>Some</tt> with the document if found, <tt>None</tt> otherwise</returns>
|
/// <returns><c>Some</c> with the document if found, <c>None</c> otherwise</returns>
|
||||||
[<CompiledName "FSharpById">]
|
[<CompiledName "FSharpById">]
|
||||||
let byId<'TKey, 'TDoc> tableName (docId: 'TKey) conn =
|
let byId<'TKey, 'TDoc> tableName (docId: 'TKey) conn =
|
||||||
Custom.single<'TDoc> (Query.byId (Query.find tableName) docId) [ idParam docId ] fromData<'TDoc> conn
|
Custom.single<'TDoc> (Query.byId (Query.find tableName) docId) [ idParam docId ] fromData<'TDoc> conn
|
||||||
@ -256,16 +333,16 @@ module Find =
|
|||||||
/// <summary>Retrieve a document by its ID</summary>
|
/// <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="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||||
/// <param name="docId">The ID of the document to retrieve</param>
|
/// <param name="docId">The ID of the document to retrieve</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>The document if found, <tt>null</tt> otherwise</returns>
|
/// <returns>The document if found, <c>null</c> otherwise</returns>
|
||||||
let ById<'TKey, 'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, docId: 'TKey, conn) =
|
let ById<'TKey, 'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, docId: 'TKey, conn) =
|
||||||
Custom.Single<'TDoc>(Query.byId (Query.find tableName) docId, [ idParam docId ], fromData<'TDoc>, conn)
|
Custom.Single<'TDoc>(Query.byId (Query.find tableName) docId, [ idParam docId ], fromData<'TDoc>, conn)
|
||||||
|
|
||||||
/// <summary>Retrieve documents matching JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
/// <summary>Retrieve documents matching JSON field comparisons (<c>->> =</c>, etc.)</summary>
|
||||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="fields">The field conditions to match</param>
|
/// <param name="fields">The field conditions to match</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>All documents matching the given fields</returns>
|
/// <returns>All documents matching the given fields</returns>
|
||||||
[<CompiledName "FSharpByFields">]
|
[<CompiledName "FSharpByFields">]
|
||||||
let byFields<'TDoc> tableName howMatched fields conn =
|
let byFields<'TDoc> tableName howMatched fields conn =
|
||||||
@ -275,11 +352,11 @@ module Find =
|
|||||||
fromData<'TDoc>
|
fromData<'TDoc>
|
||||||
conn
|
conn
|
||||||
|
|
||||||
/// <summary>Retrieve documents matching JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
/// <summary>Retrieve documents matching JSON field comparisons (<c>->> =</c>, etc.)</summary>
|
||||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="fields">The field conditions to match</param>
|
/// <param name="fields">The field conditions to match</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>All documents matching the given fields</returns>
|
/// <returns>All documents matching the given fields</returns>
|
||||||
let ByFields<'TDoc>(tableName, howMatched, fields, conn) =
|
let ByFields<'TDoc>(tableName, howMatched, fields, conn) =
|
||||||
Custom.List<'TDoc>(
|
Custom.List<'TDoc>(
|
||||||
@ -289,14 +366,14 @@ module Find =
|
|||||||
conn)
|
conn)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve documents matching JSON field comparisons (<tt>->> =</tt>, etc.) ordered by the given fields
|
/// Retrieve documents matching JSON field comparisons (<c>->> =</c>, etc.) ordered by the given fields in the
|
||||||
/// in the document
|
/// document
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="queryFields">The field conditions to match</param>
|
/// <param name="queryFields">The field conditions to match</param>
|
||||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>All documents matching the given fields, ordered by the other given fields</returns>
|
/// <returns>All documents matching the given fields, ordered by the other given fields</returns>
|
||||||
[<CompiledName "FSharpByFieldsOrdered">]
|
[<CompiledName "FSharpByFieldsOrdered">]
|
||||||
let byFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields conn =
|
let byFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields conn =
|
||||||
@ -307,14 +384,14 @@ module Find =
|
|||||||
conn
|
conn
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve documents matching JSON field comparisons (<tt>->> =</tt>, etc.) ordered by the given fields
|
/// Retrieve documents matching JSON field comparisons (<c>->> =</c>, etc.) ordered by the given fields in the
|
||||||
/// in the document
|
/// document
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="queryFields">The field conditions to match</param>
|
/// <param name="queryFields">The field conditions to match</param>
|
||||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>All documents matching the given fields, ordered by the other given fields</returns>
|
/// <returns>All documents matching the given fields, ordered by the other given fields</returns>
|
||||||
let ByFieldsOrdered<'TDoc>(tableName, howMatched, queryFields, orderFields, conn) =
|
let ByFieldsOrdered<'TDoc>(tableName, howMatched, queryFields, orderFields, conn) =
|
||||||
Custom.List<'TDoc>(
|
Custom.List<'TDoc>(
|
||||||
@ -323,12 +400,12 @@ module Find =
|
|||||||
fromData<'TDoc>,
|
fromData<'TDoc>,
|
||||||
conn)
|
conn)
|
||||||
|
|
||||||
/// <summary>Retrieve the first document matching JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
/// <summary>Retrieve the first document matching JSON field comparisons (<c>->> =</c>, etc.)</summary>
|
||||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="fields">The field conditions to match</param>
|
/// <param name="fields">The field conditions to match</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns><tt>Some</tt> with the first document, or <tt>None</tt> if not found</returns>
|
/// <returns><c>Some</c> with the first document, or <c>None</c> if not found</returns>
|
||||||
[<CompiledName "FSharpFirstByFields">]
|
[<CompiledName "FSharpFirstByFields">]
|
||||||
let firstByFields<'TDoc> tableName howMatched fields conn =
|
let firstByFields<'TDoc> tableName howMatched fields conn =
|
||||||
Custom.single
|
Custom.single
|
||||||
@ -337,12 +414,12 @@ module Find =
|
|||||||
fromData<'TDoc>
|
fromData<'TDoc>
|
||||||
conn
|
conn
|
||||||
|
|
||||||
/// <summary>Retrieve the first document matching JSON field comparisons (<tt>->> =</tt>, etc.)</summary>
|
/// <summary>Retrieve the first document matching JSON field comparisons (<c>->> =</c>, etc.)</summary>
|
||||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="fields">The field conditions to match</param>
|
/// <param name="fields">The field conditions to match</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>The first document, or <tt>null</tt> if not found</returns>
|
/// <returns>The first document, or <c>null</c> if not found</returns>
|
||||||
let FirstByFields<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, howMatched, fields, conn) =
|
let FirstByFields<'TDoc when 'TDoc: null and 'TDoc: not struct>(tableName, howMatched, fields, conn) =
|
||||||
Custom.Single(
|
Custom.Single(
|
||||||
$"{Query.byFields (Query.find tableName) howMatched fields} LIMIT 1",
|
$"{Query.byFields (Query.find tableName) howMatched fields} LIMIT 1",
|
||||||
@ -351,16 +428,16 @@ module Find =
|
|||||||
conn)
|
conn)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve the first document matching JSON field comparisons (<tt>->> =</tt>, etc.) ordered by the
|
/// Retrieve the first document matching JSON field comparisons (<c>->> =</c>, etc.) ordered by the given
|
||||||
/// given fields in the document
|
/// fields in the document
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="queryFields">The field conditions to match</param>
|
/// <param name="queryFields">The field conditions to match</param>
|
||||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// <tt>Some</tt> with the first document ordered by the given fields, or <tt>None</tt> if not found
|
/// <c>Some</c> with the first document ordered by the given fields, or <c>None</c> if not found
|
||||||
/// </returns>
|
/// </returns>
|
||||||
[<CompiledName "FSharpFirstByFieldsOrdered">]
|
[<CompiledName "FSharpFirstByFieldsOrdered">]
|
||||||
let firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields conn =
|
let firstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields conn =
|
||||||
@ -371,15 +448,15 @@ module Find =
|
|||||||
conn
|
conn
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve the first document matching JSON field comparisons (<tt>->> =</tt>, etc.) ordered by the
|
/// Retrieve the first document matching JSON field comparisons (<c>->> =</c>, etc.) ordered by the given
|
||||||
/// given fields in the document
|
/// fields in the document
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="queryFields">The field conditions to match</param>
|
/// <param name="queryFields">The field conditions to match</param>
|
||||||
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
/// <returns>The first document ordered by the given fields, or <tt>null</tt> if not found</returns>
|
/// <returns>The first document ordered by the given fields, or <c>null</c> if not found</returns>
|
||||||
let FirstByFieldsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
let FirstByFieldsOrdered<'TDoc when 'TDoc: null and 'TDoc: not struct>(
|
||||||
tableName, howMatched, queryFields, orderFields, conn) =
|
tableName, howMatched, queryFields, orderFields, conn) =
|
||||||
Custom.Single(
|
Custom.Single(
|
||||||
@ -388,6 +465,204 @@ module Find =
|
|||||||
fromData<'TDoc>,
|
fromData<'TDoc>,
|
||||||
conn)
|
conn)
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>Commands to retrieve documents as raw JSON</summary>
|
||||||
|
[<RequireQualifiedAccess>]
|
||||||
|
module Json =
|
||||||
|
|
||||||
|
/// <summary>Retrieve all JSON documents in the given table</summary>
|
||||||
|
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>All JSON documents from the given table</returns>
|
||||||
|
[<CompiledName "All">]
|
||||||
|
let all tableName conn =
|
||||||
|
Custom.jsonArray (Query.find tableName) [] jsonFromData conn
|
||||||
|
|
||||||
|
/// <summary>Retrieve all JSON documents in the given table ordered by the given fields in the document</summary>
|
||||||
|
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||||
|
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>All JSON documents from the given table, ordered by the given fields</returns>
|
||||||
|
[<CompiledName "AllOrdered">]
|
||||||
|
let allOrdered tableName orderFields conn =
|
||||||
|
Custom.jsonArray (Query.find tableName + Query.orderBy orderFields SQLite) [] jsonFromData 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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>The JSON document if found, an empty JSON document otherwise</returns>
|
||||||
|
[<CompiledName "ById">]
|
||||||
|
let byId<'TKey> tableName (docId: 'TKey) conn =
|
||||||
|
Custom.jsonSingle (Query.byId (Query.find tableName) docId) [ idParam docId ] jsonFromData conn
|
||||||
|
|
||||||
|
/// <summary>Retrieve JSON documents matching JSON field comparisons (<c>->> =</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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>All JSON documents matching the given fields</returns>
|
||||||
|
[<CompiledName "ByFields">]
|
||||||
|
let byFields tableName howMatched fields conn =
|
||||||
|
Custom.jsonArray
|
||||||
|
(Query.byFields (Query.find tableName) howMatched fields) (addFieldParams fields []) jsonFromData conn
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve JSON documents matching JSON field comparisons (<c>->> =</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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>All JSON documents matching the given fields, ordered by the other given fields</returns>
|
||||||
|
[<CompiledName "ByFieldsOrdered">]
|
||||||
|
let byFieldsOrdered tableName howMatched queryFields orderFields conn =
|
||||||
|
Custom.jsonArray
|
||||||
|
(Query.byFields (Query.find tableName) howMatched queryFields + Query.orderBy orderFields SQLite)
|
||||||
|
(addFieldParams queryFields [])
|
||||||
|
jsonFromData
|
||||||
|
conn
|
||||||
|
|
||||||
|
/// <summary>Retrieve the first JSON document matching JSON field comparisons (<c>->> =</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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>The first JSON document if found, an empty JSON document otherwise</returns>
|
||||||
|
[<CompiledName "FirstByFields">]
|
||||||
|
let firstByFields tableName howMatched fields conn =
|
||||||
|
Custom.jsonSingle
|
||||||
|
(Query.byFields (Query.find tableName) howMatched fields) (addFieldParams fields []) jsonFromData conn
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve the first JSON document matching JSON field comparisons (<c>->> =</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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>The first JSON document (in order) if found, an empty JSON document otherwise</returns>
|
||||||
|
[<CompiledName "FirstByFieldsOrdered">]
|
||||||
|
let firstByFieldsOrdered tableName howMatched queryFields orderFields conn =
|
||||||
|
Custom.jsonSingle
|
||||||
|
(Query.byFields (Query.find tableName) howMatched queryFields + Query.orderBy orderFields SQLite)
|
||||||
|
(addFieldParams queryFields [])
|
||||||
|
jsonFromData
|
||||||
|
conn
|
||||||
|
|
||||||
|
/// <summary>Write all JSON documents in the given table to the given <c>StreamWriter</c></summary>
|
||||||
|
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||||
|
/// <param name="writer">The StreamWriter to which the results should be written</param>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
[<CompiledName "WriteAll">]
|
||||||
|
let writeAll tableName writer conn =
|
||||||
|
Custom.writeJsonArray (Query.find tableName) [] writer jsonFromData conn
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write all JSON all documents in the given table to the given <c>StreamWriter</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 StreamWriter to which the results should be written</param>
|
||||||
|
/// <param name="orderFields">Fields by which the results should be ordered</param>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
[<CompiledName "WriteAllOrdered">]
|
||||||
|
let writeAllOrdered tableName writer orderFields conn =
|
||||||
|
Custom.writeJsonArray (Query.find tableName + Query.orderBy orderFields SQLite) [] writer jsonFromData conn
|
||||||
|
|
||||||
|
/// <summary>Write a JSON document to the given <c>StreamWriter</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 StreamWriter to which the results should be written</param>
|
||||||
|
/// <param name="docId">The ID of the document to retrieve</param>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
[<CompiledName "WriteById">]
|
||||||
|
let writeById<'TKey> tableName (writer: StreamWriter) (docId: 'TKey) conn = backgroundTask {
|
||||||
|
let! json = Custom.jsonSingle (Query.byId (Query.find tableName) docId) [ idParam docId ] jsonFromData conn
|
||||||
|
do! writer.WriteAsync json
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write JSON documents to the given <c>StreamWriter</c> matching JSON field comparisons (<c>->> =</c>, etc.)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tableName">The table from which documents should be retrieved (may include schema)</param>
|
||||||
|
/// <param name="writer">The StreamWriter 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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
[<CompiledName "WriteByFields">]
|
||||||
|
let writeByFields tableName writer howMatched fields conn =
|
||||||
|
Custom.writeJsonArray
|
||||||
|
(Query.byFields (Query.find tableName) howMatched fields)
|
||||||
|
(addFieldParams fields [])
|
||||||
|
writer
|
||||||
|
jsonFromData
|
||||||
|
conn
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write JSON documents to the given <c>StreamWriter</c> matching JSON field comparisons (<c>->> =</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 StreamWriter 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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
[<CompiledName "WriteByFieldsOrdered">]
|
||||||
|
let writeByFieldsOrdered tableName writer howMatched queryFields orderFields conn =
|
||||||
|
Custom.writeJsonArray
|
||||||
|
(Query.byFields (Query.find tableName) howMatched queryFields + Query.orderBy orderFields SQLite)
|
||||||
|
(addFieldParams queryFields [])
|
||||||
|
writer
|
||||||
|
jsonFromData
|
||||||
|
conn
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write the first JSON document to the given <c>StreamWriter</c> matching JSON field comparisons
|
||||||
|
/// (<c>->> =</c>, etc.)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tableName">The table from which a document should be retrieved (may include schema)</param>
|
||||||
|
/// <param name="writer">The StreamWriter 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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>The first JSON document if found, an empty JSON document otherwise</returns>
|
||||||
|
[<CompiledName "WriteFirstByFields">]
|
||||||
|
let writeFirstByFields tableName (writer: StreamWriter) howMatched fields conn = backgroundTask {
|
||||||
|
let! json =
|
||||||
|
Custom.jsonSingle
|
||||||
|
(Query.byFields (Query.find tableName) howMatched fields) (addFieldParams fields []) jsonFromData conn
|
||||||
|
do! writer.WriteAsync json
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write the first JSON document to the given <c>StreamWriter</c> matching JSON field comparisons
|
||||||
|
/// (<c>->> =</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 StreamWriter 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>
|
||||||
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
|
/// <returns>The first JSON document (in order) if found, an empty JSON document otherwise</returns>
|
||||||
|
[<CompiledName "WriteFirstByFieldsOrdered">]
|
||||||
|
let writeFirstByFieldsOrdered tableName (writer: StreamWriter) howMatched queryFields orderFields conn =
|
||||||
|
backgroundTask {
|
||||||
|
let! json =
|
||||||
|
Custom.jsonSingle
|
||||||
|
(Query.byFields (Query.find tableName) howMatched queryFields + Query.orderBy orderFields SQLite)
|
||||||
|
(addFieldParams queryFields [])
|
||||||
|
jsonFromData
|
||||||
|
conn
|
||||||
|
do! writer.WriteAsync json
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Commands to update documents</summary>
|
/// <summary>Commands to update documents</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module Update =
|
module Update =
|
||||||
@ -396,7 +671,7 @@ module Update =
|
|||||||
/// <param name="tableName">The table in which a document should be updated (may include schema)</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="docId">The ID of the document to be updated (replaced)</param>
|
||||||
/// <param name="document">The new document</param>
|
/// <param name="document">The new document</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "ById">]
|
[<CompiledName "ById">]
|
||||||
let byId tableName (docId: 'TKey) (document: 'TDoc) conn =
|
let byId tableName (docId: 'TKey) (document: 'TDoc) conn =
|
||||||
Custom.nonQuery
|
Custom.nonQuery
|
||||||
@ -405,28 +680,27 @@ module Update =
|
|||||||
conn
|
conn
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update (replace) an entire document by its ID, using the provided function to obtain the ID from the
|
/// Update (replace) an entire document by its ID, using the provided function to obtain the ID from the document
|
||||||
/// document
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableName">The table in which a document should be updated (may include schema)</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="idFunc">The function to obtain the ID of the document</param>
|
||||||
/// <param name="document">The new document</param>
|
/// <param name="document">The new document</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "FSharpByFunc">]
|
[<CompiledName "FSharpByFunc">]
|
||||||
let byFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) conn =
|
let byFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) conn =
|
||||||
byId tableName (idFunc document) document conn
|
byId tableName (idFunc document) document conn
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update (replace) an entire document by its ID, using the provided function to obtain the ID from the
|
/// Update (replace) an entire document by its ID, using the provided function to obtain the ID from the document
|
||||||
/// document
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableName">The table in which a document should be updated (may include schema)</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="idFunc">The function to obtain the ID of the document</param>
|
||||||
/// <param name="document">The new document</param>
|
/// <param name="document">The new document</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
let ByFunc(tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc, conn) =
|
let ByFunc(tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc, conn) =
|
||||||
byFunc tableName idFunc.Invoke document conn
|
byFunc tableName idFunc.Invoke document conn
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Commands to patch (partially update) documents</summary>
|
/// <summary>Commands to patch (partially update) documents</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module Patch =
|
module Patch =
|
||||||
@ -435,21 +709,20 @@ module Patch =
|
|||||||
/// <param name="tableName">The table in which a document should be patched (may include schema)</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="docId">The ID of the document to patch</param>
|
||||||
/// <param name="patch">The partial document to patch the existing document</param>
|
/// <param name="patch">The partial document to patch the existing document</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "ById">]
|
[<CompiledName "ById">]
|
||||||
let byId tableName (docId: 'TKey) (patch: 'TPatch) conn =
|
let byId tableName (docId: 'TKey) (patch: 'TPatch) conn =
|
||||||
Custom.nonQuery
|
Custom.nonQuery
|
||||||
(Query.byId (Query.patch tableName) docId) [ idParam docId; jsonParam "@data" patch ] conn
|
(Query.byId (Query.patch tableName) docId) [ idParam docId; jsonParam "@data" patch ] conn
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Patch documents using a JSON field comparison query in the <tt>WHERE</tt> clause (<tt>->> =</tt>,
|
/// Patch documents using a JSON field comparison query in the <c>WHERE</c> clause (<c>->> =</c>, etc.)
|
||||||
/// etc.)
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableName">The table in which documents should be patched (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="fields">The field conditions to match</param>
|
/// <param name="fields">The field conditions to match</param>
|
||||||
/// <param name="patch">The partial document to patch the existing document</param>
|
/// <param name="patch">The partial document to patch the existing document</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "ByFields">]
|
[<CompiledName "ByFields">]
|
||||||
let byFields tableName howMatched fields (patch: 'TPatch) conn =
|
let byFields tableName howMatched fields (patch: 'TPatch) conn =
|
||||||
Custom.nonQuery
|
Custom.nonQuery
|
||||||
@ -457,6 +730,7 @@ module Patch =
|
|||||||
(addFieldParams fields [ jsonParam "@data" patch ])
|
(addFieldParams fields [ jsonParam "@data" patch ])
|
||||||
conn
|
conn
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Commands to remove fields from documents</summary>
|
/// <summary>Commands to remove fields from documents</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module RemoveFields =
|
module RemoveFields =
|
||||||
@ -465,7 +739,7 @@ module RemoveFields =
|
|||||||
/// <param name="tableName">The table in which a document should be modified (may include schema)</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="docId">The ID of the document to modify</param>
|
||||||
/// <param name="fieldNames">One or more field names to remove from the document</param>
|
/// <param name="fieldNames">One or more field names to remove from the document</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "ById">]
|
[<CompiledName "ById">]
|
||||||
let byId tableName (docId: 'TKey) fieldNames conn =
|
let byId tableName (docId: 'TKey) fieldNames conn =
|
||||||
let nameParams = fieldNameParams "@name" fieldNames
|
let nameParams = fieldNameParams "@name" fieldNames
|
||||||
@ -479,7 +753,7 @@ module RemoveFields =
|
|||||||
/// <param name="howMatched">Whether to match any or all of the field conditions</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="fields">The field conditions to match</param>
|
||||||
/// <param name="fieldNames">One or more field names to remove from the matching documents</param>
|
/// <param name="fieldNames">One or more field names to remove from the matching documents</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "ByFields">]
|
[<CompiledName "ByFields">]
|
||||||
let byFields tableName howMatched fields fieldNames conn =
|
let byFields tableName howMatched fields fieldNames conn =
|
||||||
let nameParams = fieldNameParams "@name" fieldNames
|
let nameParams = fieldNameParams "@name" fieldNames
|
||||||
@ -488,23 +762,24 @@ module RemoveFields =
|
|||||||
(addFieldParams fields nameParams)
|
(addFieldParams fields nameParams)
|
||||||
conn
|
conn
|
||||||
|
|
||||||
/// Commands to delete documents
|
|
||||||
|
/// <summary>Commands to delete documents</summary>
|
||||||
[<RequireQualifiedAccess>]
|
[<RequireQualifiedAccess>]
|
||||||
module Delete =
|
module Delete =
|
||||||
|
|
||||||
/// <summary>Delete a document by its ID</summary>
|
/// <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="tableName">The table in which a document should be deleted (may include schema)</param>
|
||||||
/// <param name="docId">The ID of the document to delete</param>
|
/// <param name="docId">The ID of the document to delete</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "ById">]
|
[<CompiledName "ById">]
|
||||||
let byId tableName (docId: 'TKey) conn =
|
let byId tableName (docId: 'TKey) conn =
|
||||||
Custom.nonQuery (Query.byId (Query.delete tableName) docId) [ idParam docId ] conn
|
Custom.nonQuery (Query.byId (Query.delete tableName) docId) [ idParam docId ] conn
|
||||||
|
|
||||||
/// <summary>Delete documents by matching a JSON field comparison query (<tt>->> =</tt>, etc.)</summary>
|
/// <summary>Delete documents by matching a JSON field comparison query (<c>->> =</c>, etc.)</summary>
|
||||||
/// <param name="tableName">The table in which documents should be deleted (may include schema)</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="howMatched">Whether to match any or all of the field conditions</param>
|
||||||
/// <param name="fields">The field conditions to match</param>
|
/// <param name="fields">The field conditions to match</param>
|
||||||
/// <param name="conn">The <tt>SqliteConnection</tt> to use to execute the query</param>
|
/// <param name="conn">The <c>SqliteConnection</c> to use to execute the query</param>
|
||||||
[<CompiledName "ByFields">]
|
[<CompiledName "ByFields">]
|
||||||
let byFields tableName howMatched fields conn =
|
let byFields tableName howMatched fields conn =
|
||||||
Custom.nonQuery (Query.byFields (Query.delete tableName) howMatched fields) (addFieldParams fields []) conn
|
Custom.nonQuery (Query.byFields (Query.delete tableName) howMatched fields) (addFieldParams fields []) conn
|
||||||
|
Loading…
x
Reference in New Issue
Block a user