Version 4 rc1 (#6)
Changes in this version: - **BREAKING CHANGE**: All `*byField`/`*ByField` functions are now `*byFields`/`*ByFields`, and take a `FieldMatch` case before the list of fields. The `Compat` namespace in both libraries will assist in this transition. In support of this change, the `Field` parameter name is optional; the library will generate parameter names for it if they are not specified. - **BREAKING CHANGE**: The `Query` namespaces have had some significant work, particularly from the full-query perspective. Most have been broken up into the base query and modifiers `by*` that will combine the base query with the `WHERE` clause needed to satisfy the criteria. - **FEATURE / BREAKING CHANGE**: PostgreSQL document fields will now be cast to numeric if the parameter value passed to the query is numeric. This drove the `Query` breaking changes, as the fields need to have their intended value for the library to generate the appropriate SQL. Additionally, if code assumes the library can be given something like `8` and transform it to `"8"`, this is no longer the case. - **FEATURE**: All `Find` queries (except `byId`/`ById`) now have a version with the `Ordered` suffix. These take a list of fields by which the query should be ordered. A new `Field` method called `Named` can assist with creating these fields. Prefixing the field name with `n:` will cast the field to numeric in PostgreSQL (and will be ignored by SQLite); adding " DESC" to the field name will sort it descending (Z-A, high to low) instead of ascending (A-Z, low to high). - **BREAKING CHANGE** (PostgreSQL only): `fieldNameParam`/`Parameters.FieldName` are now plural. The function still only generates one parameter, but the name is now the same between PostgreSQL and SQLite. The goal of this library is to abstract the differences away as much as practical, and this furthers that end. There are functions with these names in the `Compat` namespace. - **FEATURE**: In the F# v3 library, lists of parameters were expected to be F#'s `List` type, and the C# version took either `List<T>` or `IEnumerable<T>`. In this version, these all expect `seq`/`IEnumerable<T>`. F#'s `List` satisfies the `seq` constraints, so this should not be a breaking change. - **FEATURE**: `Field`s now may have qualifiers; this allows tables to be aliased when joining multiple tables (as all have the same `data` column). F# users can use `with` to specify this at creation, and both F# and C# can use the `WithQualifier` method to create a field with the qualifier specified. Parameter names for fields may be specified in a similar way, substituting `ParameterName` for `Qualifier`. Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
@@ -50,8 +50,8 @@ module Extensions =
|
||||
WithProps.Count.all tableName (Sql.existingConnection conn)
|
||||
|
||||
/// Count matching documents using a JSON field comparison query (->> =)
|
||||
member conn.countByField tableName field =
|
||||
WithProps.Count.byField tableName field (Sql.existingConnection conn)
|
||||
member conn.countByFields tableName howMatched fields =
|
||||
WithProps.Count.byFields tableName howMatched fields (Sql.existingConnection conn)
|
||||
|
||||
/// Count matching documents using a JSON containment query (@>)
|
||||
member conn.countByContains tableName criteria =
|
||||
@@ -66,8 +66,8 @@ module Extensions =
|
||||
WithProps.Exists.byId tableName docId (Sql.existingConnection conn)
|
||||
|
||||
/// Determine if documents exist using a JSON field comparison query (->> =)
|
||||
member conn.existsByField tableName field =
|
||||
WithProps.Exists.byField tableName field (Sql.existingConnection conn)
|
||||
member conn.existsByFields tableName howMatched fields =
|
||||
WithProps.Exists.byFields tableName howMatched fields (Sql.existingConnection conn)
|
||||
|
||||
/// Determine if documents exist using a JSON containment query (@>)
|
||||
member conn.existsByContains tableName criteria =
|
||||
@@ -81,34 +81,68 @@ module Extensions =
|
||||
member conn.findAll<'TDoc> tableName =
|
||||
WithProps.Find.all<'TDoc> tableName (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve all documents in the given table ordered by the given fields in the document
|
||||
member conn.findAllOrdered<'TDoc> tableName orderFields =
|
||||
WithProps.Find.allOrdered<'TDoc> tableName orderFields (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve a document by its ID; returns None if not found
|
||||
member conn.findById<'TKey, 'TDoc> tableName docId =
|
||||
WithProps.Find.byId<'TKey, 'TDoc> tableName docId (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison query (->> =)
|
||||
member conn.findByField<'TDoc> tableName field =
|
||||
WithProps.Find.byField<'TDoc> tableName field (Sql.existingConnection conn)
|
||||
member conn.findByFields<'TDoc> tableName howMatched fields =
|
||||
WithProps.Find.byFields<'TDoc> tableName howMatched fields (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison query (->> =) ordered by the given fields in the
|
||||
/// document
|
||||
member conn.findByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields =
|
||||
WithProps.Find.byFieldsOrdered<'TDoc>
|
||||
tableName howMatched queryFields orderFields (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>)
|
||||
member conn.findByContains<'TDoc> tableName (criteria: obj) =
|
||||
WithProps.Find.byContains<'TDoc> tableName criteria (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>) ordered by the given fields in the document
|
||||
member conn.findByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields =
|
||||
WithProps.Find.byContainsOrdered<'TDoc> tableName criteria orderFields (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON Path match query (@?)
|
||||
member conn.findByJsonPath<'TDoc> tableName jsonPath =
|
||||
WithProps.Find.byJsonPath<'TDoc> tableName jsonPath (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON Path match query (@?) ordered by the given fields in the document
|
||||
member conn.findByJsonPathOrdered<'TDoc> tableName jsonPath orderFields =
|
||||
WithProps.Find.byJsonPathOrdered<'TDoc> tableName jsonPath orderFields (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison query (->> =); returns None if not found
|
||||
member conn.findFirstByField<'TDoc> tableName field =
|
||||
WithProps.Find.firstByField<'TDoc> tableName field (Sql.existingConnection conn)
|
||||
member conn.findFirstByFields<'TDoc> tableName howMatched fields =
|
||||
WithProps.Find.firstByFields<'TDoc> tableName howMatched fields (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison query (->> =) ordered by the given fields in
|
||||
/// the document; returns None if not found
|
||||
member conn.findFirstByFieldsOrdered<'TDoc> tableName howMatched queryFields orderFields =
|
||||
WithProps.Find.firstByFieldsOrdered<'TDoc>
|
||||
tableName howMatched queryFields orderFields (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>); returns None if not found
|
||||
member conn.findFirstByContains<'TDoc> tableName (criteria: obj) =
|
||||
WithProps.Find.firstByContains<'TDoc> tableName criteria (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>) ordered by the given fields in the
|
||||
/// document; returns None if not found
|
||||
member conn.findFirstByContainsOrdered<'TDoc> tableName (criteria: obj) orderFields =
|
||||
WithProps.Find.firstByContainsOrdered<'TDoc> tableName criteria orderFields (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON Path match query (@?); returns None if not found
|
||||
member conn.findFirstByJsonPath<'TDoc> tableName jsonPath =
|
||||
WithProps.Find.firstByJsonPath<'TDoc> tableName jsonPath (Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON Path match query (@?) ordered by the given fields in the
|
||||
/// document; returns None if not found
|
||||
member conn.findFirstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields =
|
||||
WithProps.Find.firstByJsonPathOrdered<'TDoc> tableName jsonPath orderFields (Sql.existingConnection conn)
|
||||
|
||||
/// Update an entire document by its ID
|
||||
member conn.updateById tableName (docId: 'TKey) (document: 'TDoc) =
|
||||
WithProps.Update.byId tableName docId document (Sql.existingConnection conn)
|
||||
@@ -122,8 +156,8 @@ module Extensions =
|
||||
WithProps.Patch.byId tableName docId patch (Sql.existingConnection conn)
|
||||
|
||||
/// Patch documents using a JSON field comparison query in the WHERE clause (->> =)
|
||||
member conn.patchByField tableName field (patch: 'TPatch) =
|
||||
WithProps.Patch.byField tableName field patch (Sql.existingConnection conn)
|
||||
member conn.patchByFields tableName howMatched fields (patch: 'TPatch) =
|
||||
WithProps.Patch.byFields tableName howMatched fields patch (Sql.existingConnection conn)
|
||||
|
||||
/// Patch documents using a JSON containment query in the WHERE clause (@>)
|
||||
member conn.patchByContains tableName (criteria: 'TCriteria) (patch: 'TPatch) =
|
||||
@@ -137,9 +171,9 @@ module Extensions =
|
||||
member conn.removeFieldsById tableName (docId: 'TKey) fieldNames =
|
||||
WithProps.RemoveFields.byId tableName docId fieldNames (Sql.existingConnection conn)
|
||||
|
||||
/// Remove fields from documents via a comparison on a JSON field in the document
|
||||
member conn.removeFieldsByField tableName field fieldNames =
|
||||
WithProps.RemoveFields.byField tableName field fieldNames (Sql.existingConnection conn)
|
||||
/// Remove fields from documents via a comparison on JSON fields in the document
|
||||
member conn.removeFieldsByFields tableName howMatched fields fieldNames =
|
||||
WithProps.RemoveFields.byFields tableName howMatched fields fieldNames (Sql.existingConnection conn)
|
||||
|
||||
/// Remove fields from documents via a JSON containment query (@>)
|
||||
member conn.removeFieldsByContains tableName (criteria: 'TContains) fieldNames =
|
||||
@@ -153,9 +187,8 @@ module Extensions =
|
||||
member conn.deleteById tableName (docId: 'TKey) =
|
||||
WithProps.Delete.byId tableName docId (Sql.existingConnection conn)
|
||||
|
||||
/// Delete documents by matching a JSON field comparison query (->> =)
|
||||
member conn.deleteByField tableName field =
|
||||
WithProps.Delete.byField tableName field (Sql.existingConnection conn)
|
||||
member conn.deleteByFields tableName howMatched fields =
|
||||
WithProps.Delete.byFields tableName howMatched fields (Sql.existingConnection conn)
|
||||
|
||||
/// Delete documents by matching a JSON containment query (@>)
|
||||
member conn.deleteByContains tableName (criteria: 'TContains) =
|
||||
@@ -225,8 +258,8 @@ type NpgsqlConnectionCSharpExtensions =
|
||||
|
||||
/// Count matching documents using a JSON field comparison query (->> =)
|
||||
[<Extension>]
|
||||
static member inline CountByField(conn, tableName, field) =
|
||||
WithProps.Count.byField tableName field (Sql.existingConnection conn)
|
||||
static member inline CountByFields(conn, tableName, howMatched, fields) =
|
||||
WithProps.Count.byFields tableName howMatched fields (Sql.existingConnection conn)
|
||||
|
||||
/// Count matching documents using a JSON containment query (@>)
|
||||
[<Extension>]
|
||||
@@ -245,8 +278,8 @@ type NpgsqlConnectionCSharpExtensions =
|
||||
|
||||
/// Determine if documents exist using a JSON field comparison query (->> =)
|
||||
[<Extension>]
|
||||
static member inline ExistsByField(conn, tableName, field) =
|
||||
WithProps.Exists.byField tableName field (Sql.existingConnection conn)
|
||||
static member inline ExistsByFields(conn, tableName, howMatched, fields) =
|
||||
WithProps.Exists.byFields tableName howMatched fields (Sql.existingConnection conn)
|
||||
|
||||
/// Determine if documents exist using a JSON containment query (@>)
|
||||
[<Extension>]
|
||||
@@ -263,6 +296,11 @@ type NpgsqlConnectionCSharpExtensions =
|
||||
static member inline FindAll<'TDoc>(conn, tableName) =
|
||||
WithProps.Find.All<'TDoc>(tableName, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve all documents in the given table ordered by the given fields in the document
|
||||
[<Extension>]
|
||||
static member inline FindAllOrdered<'TDoc>(conn, tableName, orderFields) =
|
||||
WithProps.Find.AllOrdered<'TDoc>(tableName, orderFields, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve a document by its ID; returns None if not found
|
||||
[<Extension>]
|
||||
static member inline FindById<'TKey, 'TDoc when 'TDoc: null>(conn, tableName, docId: 'TKey) =
|
||||
@@ -270,34 +308,71 @@ type NpgsqlConnectionCSharpExtensions =
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison query (->> =)
|
||||
[<Extension>]
|
||||
static member inline FindByField<'TDoc>(conn, tableName, field) =
|
||||
WithProps.Find.ByField<'TDoc>(tableName, field, Sql.existingConnection conn)
|
||||
static member inline FindByFields<'TDoc>(conn, tableName, howMatched, fields) =
|
||||
WithProps.Find.ByFields<'TDoc>(tableName, howMatched, fields, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON field comparison query (->> =) ordered by the given fields in the document
|
||||
[<Extension>]
|
||||
static member inline FindByFieldsOrdered<'TDoc>(conn, tableName, howMatched, queryFields, orderFields) =
|
||||
WithProps.Find.ByFieldsOrdered<'TDoc>(
|
||||
tableName, howMatched, queryFields, orderFields, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>)
|
||||
[<Extension>]
|
||||
static member inline FindByContains<'TDoc>(conn, tableName, criteria: obj) =
|
||||
WithProps.Find.ByContains<'TDoc>(tableName, criteria, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON containment query (@>) ordered by the given fields in the document
|
||||
[<Extension>]
|
||||
static member inline FindByContainsOrdered<'TDoc>(conn, tableName, criteria: obj, orderFields) =
|
||||
WithProps.Find.ByContainsOrdered<'TDoc>(tableName, criteria, orderFields, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve documents matching a JSON Path match query (@?)
|
||||
[<Extension>]
|
||||
static member inline FindByJsonPath<'TDoc>(conn, tableName, jsonPath) =
|
||||
WithProps.Find.ByJsonPath<'TDoc>(tableName, jsonPath, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison query (->> =); returns None if not found
|
||||
/// Retrieve documents matching a JSON Path match query (@?) ordered by the given fields in the document
|
||||
[<Extension>]
|
||||
static member inline FindFirstByField<'TDoc when 'TDoc: null>(conn, tableName, field) =
|
||||
WithProps.Find.FirstByField<'TDoc>(tableName, field, Sql.existingConnection conn)
|
||||
static member inline FindByJsonPathOrdered<'TDoc>(conn, tableName, jsonPath, orderFields) =
|
||||
WithProps.Find.ByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison query (->> =); returns null if not found
|
||||
[<Extension>]
|
||||
static member inline FindFirstByFields<'TDoc when 'TDoc: null>(conn, tableName, howMatched, fields) =
|
||||
WithProps.Find.FirstByFields<'TDoc>(tableName, howMatched, fields, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON field comparison query (->> =) ordered by the given fields in the
|
||||
/// document; returns null if not found
|
||||
[<Extension>]
|
||||
static member inline FindFirstByFieldsOrdered<'TDoc when 'TDoc: null>(
|
||||
conn, tableName, howMatched, queryFields, orderFields) =
|
||||
WithProps.Find.FirstByFieldsOrdered<'TDoc>(
|
||||
tableName, howMatched, queryFields, orderFields, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>); returns None if not found
|
||||
[<Extension>]
|
||||
static member inline FindFirstByContains<'TDoc when 'TDoc: null>(conn, tableName, criteria: obj) =
|
||||
WithProps.Find.FirstByContains<'TDoc>(tableName, criteria, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON containment query (@>) ordered by the given fields in the document;
|
||||
/// returns None if not found
|
||||
[<Extension>]
|
||||
static member inline FindFirstByContainsOrdered<'TDoc when 'TDoc: null>(
|
||||
conn, tableName, criteria: obj, orderFields) =
|
||||
WithProps.Find.FirstByContainsOrdered<'TDoc>(tableName, criteria, orderFields, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON Path match query (@?); returns None if not found
|
||||
[<Extension>]
|
||||
static member inline FindFirstByJsonPath<'TDoc when 'TDoc: null>(conn, tableName, jsonPath) =
|
||||
WithProps.Find.FirstByJsonPath<'TDoc>(tableName, jsonPath, Sql.existingConnection conn)
|
||||
|
||||
/// Retrieve the first document matching a JSON Path match query (@?) ordered by the given fields in the document;
|
||||
/// returns None if not found
|
||||
[<Extension>]
|
||||
static member inline FindFirstByJsonPathOrdered<'TDoc when 'TDoc: null>(conn, tableName, jsonPath, orderFields) =
|
||||
WithProps.Find.FirstByJsonPathOrdered<'TDoc>(tableName, jsonPath, orderFields, Sql.existingConnection conn)
|
||||
|
||||
/// Update an entire document by its ID
|
||||
[<Extension>]
|
||||
static member inline UpdateById(conn, tableName, docId: 'TKey, document: 'TDoc) =
|
||||
@@ -315,8 +390,8 @@ type NpgsqlConnectionCSharpExtensions =
|
||||
|
||||
/// Patch documents using a JSON field comparison query in the WHERE clause (->> =)
|
||||
[<Extension>]
|
||||
static member inline PatchByField(conn, tableName, field, patch: 'TPatch) =
|
||||
WithProps.Patch.byField tableName field patch (Sql.existingConnection conn)
|
||||
static member inline PatchByFields(conn, tableName, howMatched, fields, patch: 'TPatch) =
|
||||
WithProps.Patch.byFields tableName howMatched fields patch (Sql.existingConnection conn)
|
||||
|
||||
/// Patch documents using a JSON containment query in the WHERE clause (@>)
|
||||
[<Extension>]
|
||||
@@ -331,32 +406,32 @@ type NpgsqlConnectionCSharpExtensions =
|
||||
/// Remove fields from a document by the document's ID
|
||||
[<Extension>]
|
||||
static member inline RemoveFieldsById(conn, tableName, docId: 'TKey, fieldNames) =
|
||||
WithProps.RemoveFields.ById(tableName, docId, fieldNames, Sql.existingConnection conn)
|
||||
|
||||
/// Remove fields from documents via a comparison on a JSON field in the document
|
||||
WithProps.RemoveFields.byId tableName docId fieldNames (Sql.existingConnection conn)
|
||||
|
||||
/// Remove fields from documents via a comparison on JSON fields in the document
|
||||
[<Extension>]
|
||||
static member inline RemoveFieldsByField(conn, tableName, field, fieldNames) =
|
||||
WithProps.RemoveFields.ByField(tableName, field, fieldNames, Sql.existingConnection conn)
|
||||
|
||||
static member inline RemoveFieldsByFields(conn, tableName, howMatched, fields, fieldNames) =
|
||||
WithProps.RemoveFields.byFields tableName howMatched fields fieldNames (Sql.existingConnection conn)
|
||||
|
||||
/// Remove fields from documents via a JSON containment query (@>)
|
||||
[<Extension>]
|
||||
static member inline RemoveFieldsByContains(conn, tableName, criteria: 'TContains, fieldNames) =
|
||||
WithProps.RemoveFields.ByContains(tableName, criteria, fieldNames, Sql.existingConnection conn)
|
||||
|
||||
WithProps.RemoveFields.byContains tableName criteria fieldNames (Sql.existingConnection conn)
|
||||
|
||||
/// Remove fields from documents via a JSON Path match query (@?)
|
||||
[<Extension>]
|
||||
static member inline RemoveFieldsByJsonPath(conn, tableName, jsonPath, fieldNames) =
|
||||
WithProps.RemoveFields.ByJsonPath(tableName, jsonPath, fieldNames, Sql.existingConnection conn)
|
||||
WithProps.RemoveFields.byJsonPath tableName jsonPath fieldNames (Sql.existingConnection conn)
|
||||
|
||||
/// Delete a document by its ID
|
||||
[<Extension>]
|
||||
static member inline DeleteById(conn, tableName, docId: 'TKey) =
|
||||
WithProps.Delete.byId tableName docId (Sql.existingConnection conn)
|
||||
|
||||
|
||||
/// Delete documents by matching a JSON field comparison query (->> =)
|
||||
[<Extension>]
|
||||
static member inline DeleteByField(conn, tableName, field) =
|
||||
WithProps.Delete.byField tableName field (Sql.existingConnection conn)
|
||||
static member inline DeleteByFields(conn, tableName, howMatched, fields) =
|
||||
WithProps.Delete.byFields tableName howMatched fields (Sql.existingConnection conn)
|
||||
|
||||
/// Delete documents by matching a JSON containment query (@>)
|
||||
[<Extension>]
|
||||
|
||||
Reference in New Issue
Block a user