Final tweaks for v4 (#9)
- Add .NET 9, PostgreSQL 17 support - Drop .NET 6, PostgreSQL 12 support - Finalize READMEs Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FSharp.SystemTextJson" Version="1.3.13" />
|
||||
<PackageReference Update="FSharp.Core" Version="8.0.300" />
|
||||
<PackageReference Update="FSharp.Core" Version="9.0.100" />
|
||||
<PackageReference Include="System.Text.Encodings.Web" Version="9.0.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -4,26 +4,37 @@ open System.Security.Cryptography
|
||||
|
||||
/// The types of comparisons available for JSON fields
|
||||
type Comparison =
|
||||
|
||||
/// Equals (=)
|
||||
| Equal of Value: obj
|
||||
|
||||
/// Greater Than (>)
|
||||
| Greater of Value: obj
|
||||
|
||||
/// Greater Than or Equal To (>=)
|
||||
| GreaterOrEqual of Value: obj
|
||||
|
||||
/// Less Than (<)
|
||||
| Less of Value: obj
|
||||
|
||||
/// Less Than or Equal To (<=)
|
||||
| LessOrEqual of Value: obj
|
||||
|
||||
/// Not Equal to (<>)
|
||||
| NotEqual of Value: obj
|
||||
|
||||
/// Between (BETWEEN)
|
||||
| Between of Min: obj * Max: obj
|
||||
|
||||
/// In (IN)
|
||||
| In of Values: obj seq
|
||||
|
||||
/// In Array (PostgreSQL: |?, SQLite: EXISTS / json_each / IN)
|
||||
| InArray of Table: string * Values: obj seq
|
||||
|
||||
/// Exists (IS NOT NULL)
|
||||
| Exists
|
||||
|
||||
/// Does Not Exist (IS NULL)
|
||||
| NotExists
|
||||
|
||||
@@ -53,26 +64,29 @@ type Dialect =
|
||||
/// The format in which an element of a JSON field should be extracted
|
||||
[<Struct>]
|
||||
type FieldFormat =
|
||||
|
||||
/// Use ->> or #>>; extracts a text (PostgreSQL) or SQL (SQLite) value
|
||||
| AsSql
|
||||
|
||||
/// Use -> or #>; extracts a JSONB (PostgreSQL) or JSON (SQLite) value
|
||||
| AsJson
|
||||
|
||||
|
||||
/// Criteria for a field WHERE clause
|
||||
type Field =
|
||||
{ /// The name of the field
|
||||
Name: string
|
||||
type Field = {
|
||||
|
||||
/// The comparison for the field
|
||||
Comparison: Comparison
|
||||
/// The name of the field
|
||||
Name: string
|
||||
|
||||
/// The name of the parameter for this field
|
||||
ParameterName: string option
|
||||
/// The comparison for the field
|
||||
Comparison: Comparison
|
||||
|
||||
/// The table qualifier for this field
|
||||
Qualifier: string option }
|
||||
with
|
||||
/// The name of the parameter for this field
|
||||
ParameterName: string option
|
||||
|
||||
/// The table qualifier for this field
|
||||
Qualifier: string option
|
||||
} with
|
||||
|
||||
/// Create a comparison against a field
|
||||
static member Where name (comparison: Comparison) =
|
||||
@@ -190,8 +204,10 @@ with
|
||||
/// How fields should be matched
|
||||
[<Struct>]
|
||||
type FieldMatch =
|
||||
|
||||
/// Any field matches (OR)
|
||||
| Any
|
||||
|
||||
/// All fields match (AND)
|
||||
| All
|
||||
|
||||
@@ -202,6 +218,7 @@ type FieldMatch =
|
||||
|
||||
/// Derive parameter names (each instance wraps a counter to uniquely name anonymous fields)
|
||||
type ParameterName() =
|
||||
|
||||
/// The counter for the next field value
|
||||
let mutable currentIdx = -1
|
||||
|
||||
@@ -213,35 +230,30 @@ type ParameterName() =
|
||||
currentIdx <- currentIdx + 1
|
||||
$"@field{currentIdx}"
|
||||
|
||||
#if NET6_0
|
||||
open System.Text
|
||||
#endif
|
||||
|
||||
/// Automatically-generated document ID strategies
|
||||
[<Struct>]
|
||||
type AutoId =
|
||||
|
||||
/// No automatic IDs will be generated
|
||||
| Disabled
|
||||
|
||||
/// Generate a MAX-plus-1 numeric value for documents
|
||||
| Number
|
||||
|
||||
/// Generate a GUID for each document (as a lowercase, no-dashes, 32-character string)
|
||||
| Guid
|
||||
|
||||
/// Generate a random string of hexadecimal characters for each document
|
||||
| RandomString
|
||||
with
|
||||
/// Generate a GUID string
|
||||
static member GenerateGuid () =
|
||||
static member GenerateGuid() =
|
||||
System.Guid.NewGuid().ToString "N"
|
||||
|
||||
/// Generate a string of random hexadecimal characters
|
||||
static member GenerateRandomString (length: int) =
|
||||
#if NET8_0_OR_GREATER
|
||||
static member GenerateRandomString(length: int) =
|
||||
RandomNumberGenerator.GetHexString(length, lowercase = true)
|
||||
#else
|
||||
RandomNumberGenerator.GetBytes((length / 2) + 1)
|
||||
|> Array.fold (fun (str: StringBuilder) byt -> str.Append(byt.ToString "x2")) (StringBuilder length)
|
||||
|> function it -> it.Length <- length; it.ToString()
|
||||
#endif
|
||||
|
||||
/// Does the given document need an automatic ID generated?
|
||||
static member NeedsAutoId<'T> strategy (document: 'T) idProp =
|
||||
|
||||
@@ -7,6 +7,7 @@ This package provides common definitions and functionality for `BitBadger.Docume
|
||||
## Features
|
||||
|
||||
- Select, insert, update, save (upsert), delete, count, and check existence of documents, and create tables and indexes for these documents
|
||||
- Automatically generate IDs for documents (numeric IDs, GUIDs, or random strings)
|
||||
- Addresses documents via ID and via comparison on any field (for PostgreSQL, also via equality on any property by using JSON containment, or via condition on any property using JSON Path queries)
|
||||
- Accesses documents as your domain models (<abbr title="Plain Old CLR Objects">POCO</abbr>s)
|
||||
- Uses `Task`-based async for all data access functions
|
||||
|
||||
Reference in New Issue
Block a user