v3 RC1 #1
@ -72,21 +72,21 @@ module Extensions =
|
||||
member conn.findFirstByField<'TDoc> tableName fieldName op (value: obj) =
|
||||
WithConn.Find.firstByField<'TDoc> tableName fieldName op value conn
|
||||
|
||||
/// Update an entire document
|
||||
member conn.updateFull tableName (docId: 'TKey) (document: 'TDoc) =
|
||||
WithConn.Update.full tableName docId document conn
|
||||
/// Update an entire document by its ID
|
||||
member conn.updateById tableName (docId: 'TKey) (document: 'TDoc) =
|
||||
WithConn.Update.byId tableName docId document conn
|
||||
|
||||
/// Update an entire document
|
||||
member conn.updateFullFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) =
|
||||
WithConn.Update.fullFunc tableName idFunc document conn
|
||||
/// Update an entire document by its ID, using the provided function to obtain the ID from the document
|
||||
member conn.updateByFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) =
|
||||
WithConn.Update.byFunc tableName idFunc document conn
|
||||
|
||||
/// Update a partial document
|
||||
member conn.updatePartialById tableName (docId: 'TKey) (partial: 'TPatch) =
|
||||
WithConn.Update.partialById tableName docId partial conn
|
||||
/// Patch a document by its ID
|
||||
member conn.patchById tableName (docId: 'TKey) (patch: 'TPatch) =
|
||||
WithConn.Patch.byId tableName docId patch conn
|
||||
|
||||
/// Update partial documents using a comparison on a JSON field
|
||||
member conn.updatePartialByField tableName fieldName op (value: obj) (partial: 'TPatch) =
|
||||
WithConn.Update.partialByField tableName fieldName op value partial conn
|
||||
/// Patch documents using a comparison on a JSON field
|
||||
member conn.patchByField tableName fieldName op (value: obj) (patch: 'TPatch) =
|
||||
WithConn.Patch.byField tableName fieldName op value patch conn
|
||||
|
||||
/// Delete a document by its ID
|
||||
member conn.deleteById tableName (docId: 'TKey) =
|
||||
@ -184,25 +184,25 @@ type SqliteConnectionCSharpExtensions =
|
||||
static member inline FindFirstByField<'TDoc when 'TDoc: null>(conn, tableName, fieldName, op, value: obj) =
|
||||
WithConn.Find.FirstByField<'TDoc>(tableName, fieldName, op, value, conn)
|
||||
|
||||
/// Update an entire document
|
||||
/// Update an entire document by its ID
|
||||
[<Extension>]
|
||||
static member inline UpdateFull<'TKey, 'TDoc>(conn, tableName, docId: 'TKey, document: 'TDoc) =
|
||||
WithConn.Update.full tableName docId document conn
|
||||
static member inline UpdateById<'TKey, 'TDoc>(conn, tableName, docId: 'TKey, document: 'TDoc) =
|
||||
WithConn.Update.byId tableName docId document conn
|
||||
|
||||
/// Update an entire document
|
||||
/// Update an entire document by its ID, using the provided function to obtain the ID from the document
|
||||
[<Extension>]
|
||||
static member inline UpdateFullFunc<'TKey, 'TDoc>(conn, tableName, idFunc: System.Func<'TDoc, 'TKey>, doc: 'TDoc) =
|
||||
WithConn.Update.FullFunc(tableName, idFunc, doc, conn)
|
||||
static member inline UpdateByFunc<'TKey, 'TDoc>(conn, tableName, idFunc: System.Func<'TDoc, 'TKey>, doc: 'TDoc) =
|
||||
WithConn.Update.ByFunc(tableName, idFunc, doc, conn)
|
||||
|
||||
/// Update a partial document
|
||||
/// Patch a document by its ID
|
||||
[<Extension>]
|
||||
static member inline UpdatePartialById<'TKey, 'TPatch>(conn, tableName, docId: 'TKey, partial: 'TPatch) =
|
||||
WithConn.Update.partialById tableName docId partial conn
|
||||
static member inline PatchById<'TKey, 'TPatch>(conn, tableName, docId: 'TKey, patch: 'TPatch) =
|
||||
WithConn.Patch.byId tableName docId patch conn
|
||||
|
||||
/// Update partial documents using a comparison on a JSON field
|
||||
/// Patch documents using a comparison on a JSON field
|
||||
[<Extension>]
|
||||
static member inline UpdatePartialByField<'TPatch>(conn, tableName, fieldName, op, value: obj, partial: 'TPatch) =
|
||||
WithConn.Update.partialByField tableName fieldName op value partial conn
|
||||
static member inline PatchByField<'TPatch>(conn, tableName, fieldName, op, value: obj, patch: 'TPatch) =
|
||||
WithConn.Patch.byField tableName fieldName op value patch conn
|
||||
|
||||
/// Delete a document by its ID
|
||||
[<Extension>]
|
||||
|
@ -39,17 +39,17 @@ module Query =
|
||||
let ensureTable name =
|
||||
Query.Definition.ensureTableFor name "TEXT"
|
||||
|
||||
/// Document update queries
|
||||
module Update =
|
||||
/// Document patching (partial update) queries
|
||||
module Patch =
|
||||
|
||||
/// Query to update a partial document by its ID
|
||||
[<CompiledName "PartialById">]
|
||||
let partialById tableName =
|
||||
/// Query to patch (partially update) a document by its ID
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName =
|
||||
$"""UPDATE %s{tableName} SET data = json_patch(data, json(@data)) WHERE {Query.whereById "@id"}"""
|
||||
|
||||
/// Query to update a partial document via a comparison on a JSON field
|
||||
[<CompiledName "PartialByField">]
|
||||
let partialByField tableName fieldName op =
|
||||
/// Query to patch (partially update) a document via a comparison on a JSON field
|
||||
[<CompiledName "ByField">]
|
||||
let byField tableName fieldName op =
|
||||
sprintf
|
||||
"UPDATE %s SET data = json_patch(data, json(@data)) WHERE %s"
|
||||
tableName (Query.whereByField fieldName op "@field")
|
||||
@ -295,32 +295,34 @@ module WithConn =
|
||||
[<RequireQualifiedAccess>]
|
||||
module Update =
|
||||
|
||||
/// Update an entire document
|
||||
[<CompiledName "Full">]
|
||||
let full tableName (docId: 'TKey) (document: 'TDoc) conn =
|
||||
/// Update an entire document by its ID
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) (document: 'TDoc) conn =
|
||||
Custom.nonQuery (Query.update tableName) [ idParam docId; jsonParam "@data" document ] conn
|
||||
|
||||
/// Update an entire document
|
||||
[<CompiledName "FSharpFullFunc">]
|
||||
let fullFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) conn =
|
||||
full tableName (idFunc document) document conn
|
||||
/// Update an entire document by its ID, using the provided function to obtain the ID from the document
|
||||
[<CompiledName "FSharpByFunc">]
|
||||
let byFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) conn =
|
||||
byId tableName (idFunc document) document conn
|
||||
|
||||
/// Update an entire document
|
||||
let FullFunc(tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc, conn) =
|
||||
fullFunc tableName idFunc.Invoke document conn
|
||||
/// Update an entire document by its ID, using the provided function to obtain the ID from the document
|
||||
let ByFunc(tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc, conn) =
|
||||
byFunc tableName idFunc.Invoke document conn
|
||||
|
||||
/// Commands to patch (partially update) documents
|
||||
[<RequireQualifiedAccess>]
|
||||
module Patch =
|
||||
|
||||
/// Update a partial document
|
||||
[<CompiledName "PartialById">]
|
||||
let partialById tableName (docId: 'TKey) (partial: 'TPatch) conn =
|
||||
Custom.nonQuery (Query.Update.partialById tableName) [ idParam docId; jsonParam "@data" partial ] conn
|
||||
/// Patch a document by its ID
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) (patch: 'TPatch) conn =
|
||||
Custom.nonQuery (Query.Patch.byId tableName) [ idParam docId; jsonParam "@data" patch ] conn
|
||||
|
||||
/// Update partial documents using a comparison on a JSON field
|
||||
[<CompiledName "PartialByField">]
|
||||
let partialByField tableName fieldName op (value: obj) (partial: 'TPatch) (conn: SqliteConnection) =
|
||||
/// Patch documents using a comparison on a JSON field
|
||||
[<CompiledName "ByField">]
|
||||
let byField tableName fieldName op (value: obj) (patch: 'TPatch) (conn: SqliteConnection) =
|
||||
Custom.nonQuery
|
||||
(Query.Update.partialByField tableName fieldName op)
|
||||
[ fieldParam value; jsonParam "@data" partial ]
|
||||
conn
|
||||
(Query.Patch.byField tableName fieldName op) [ fieldParam value; jsonParam "@data" patch ] conn
|
||||
|
||||
/// Commands to delete documents
|
||||
[<RequireQualifiedAccess>]
|
||||
@ -490,34 +492,38 @@ module Find =
|
||||
[<RequireQualifiedAccess>]
|
||||
module Update =
|
||||
|
||||
/// Update an entire document
|
||||
[<CompiledName "Full">]
|
||||
let full tableName (docId: 'TKey) (document: 'TDoc) =
|
||||
/// Update an entire document by its ID
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) (document: 'TDoc) =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Update.full tableName docId document conn
|
||||
WithConn.Update.byId tableName docId document conn
|
||||
|
||||
/// Update an entire document
|
||||
[<CompiledName "FSharpFullFunc">]
|
||||
let fullFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) =
|
||||
/// Update an entire document by its ID, using the provided function to obtain the ID from the document
|
||||
[<CompiledName "FSharpByFunc">]
|
||||
let byFunc tableName (idFunc: 'TDoc -> 'TKey) (document: 'TDoc) =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Update.fullFunc tableName idFunc document conn
|
||||
WithConn.Update.byFunc tableName idFunc document conn
|
||||
|
||||
/// Update an entire document
|
||||
let FullFunc(tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc) =
|
||||
/// Update an entire document by its ID, using the provided function to obtain the ID from the document
|
||||
let ByFunc(tableName, idFunc: System.Func<'TDoc, 'TKey>, document: 'TDoc) =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Update.FullFunc(tableName, idFunc, document, conn)
|
||||
WithConn.Update.ByFunc(tableName, idFunc, document, conn)
|
||||
|
||||
/// Commands to patch (partially update) documents
|
||||
[<RequireQualifiedAccess>]
|
||||
module Patch =
|
||||
|
||||
/// Update a partial document
|
||||
[<CompiledName "PartialById">]
|
||||
let partialById tableName (docId: 'TKey) (partial: 'TPatch) =
|
||||
/// Patch a document by its ID
|
||||
[<CompiledName "ById">]
|
||||
let byId tableName (docId: 'TKey) (patch: 'TPatch) =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Update.partialById tableName docId partial conn
|
||||
WithConn.Patch.byId tableName docId patch conn
|
||||
|
||||
/// Update partial documents using a comparison on a JSON field in the WHERE clause
|
||||
[<CompiledName "PartialByField">]
|
||||
let partialByField tableName fieldName op (value: obj) (partial: 'TPatch) =
|
||||
/// Patch documents using a comparison on a JSON field in the WHERE clause
|
||||
[<CompiledName "ByField">]
|
||||
let byField tableName fieldName op (value: obj) (patch: 'TPatch) =
|
||||
use conn = Configuration.dbConn ()
|
||||
WithConn.Update.partialByField tableName fieldName op value partial conn
|
||||
WithConn.Patch.byField tableName fieldName op value patch conn
|
||||
|
||||
/// Commands to delete documents
|
||||
[<RequireQualifiedAccess>]
|
||||
|
@ -348,7 +348,7 @@ public static class SqliteCSharpExtensionTests
|
||||
Expect.isNull(doc, "There should not have been a document returned");
|
||||
})
|
||||
}),
|
||||
TestList("UpdateFull", new[]
|
||||
TestList("UpdateById", new[]
|
||||
{
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
@ -357,7 +357,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await LoadDocs();
|
||||
|
||||
var testDoc = new JsonDocument { Id = "one", Sub = new() { Foo = "blue", Bar = "red" } };
|
||||
await conn.UpdateFull(SqliteDb.TableName, "one", testDoc);
|
||||
await conn.UpdateById(SqliteDb.TableName, "one", testDoc);
|
||||
var after = await conn.FindById<string, JsonDocument>(SqliteDb.TableName, "one");
|
||||
Expect.isNotNull(after, "There should have been a document returned post-update");
|
||||
Expect.equal(after.Id, "one", "The updated document is not correct");
|
||||
@ -373,11 +373,11 @@ public static class SqliteCSharpExtensionTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.UpdateFull(SqliteDb.TableName, "test",
|
||||
await conn.UpdateById(SqliteDb.TableName, "test",
|
||||
new JsonDocument { Id = "x", Sub = new() { Foo = "blue", Bar = "red" } });
|
||||
})
|
||||
}),
|
||||
TestList("UpdateFullFunc", new[]
|
||||
TestList("UpdateByFunc", new[]
|
||||
{
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
@ -385,7 +385,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
await conn.UpdateFullFunc(SqliteDb.TableName, doc => doc.Id,
|
||||
await conn.UpdateByFunc(SqliteDb.TableName, doc => doc.Id,
|
||||
new JsonDocument { Id = "one", Value = "le un", NumValue = 1 });
|
||||
var after = await conn.FindById<string, JsonDocument>(SqliteDb.TableName, "one");
|
||||
Expect.isNotNull(after, "There should have been a document returned post-update");
|
||||
@ -402,11 +402,11 @@ public static class SqliteCSharpExtensionTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.UpdateFullFunc(SqliteDb.TableName, doc => doc.Id,
|
||||
await conn.UpdateByFunc(SqliteDb.TableName, doc => doc.Id,
|
||||
new JsonDocument { Id = "one", Value = "le un", NumValue = 1 });
|
||||
})
|
||||
}),
|
||||
TestList("UpdatePartialById", new[]
|
||||
TestList("PatchById", new[]
|
||||
{
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
@ -414,7 +414,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
await conn.UpdatePartialById(SqliteDb.TableName, "one", new { NumValue = 44 });
|
||||
await conn.PatchById(SqliteDb.TableName, "one", new { NumValue = 44 });
|
||||
var after = await conn.FindById<string, JsonDocument>(SqliteDb.TableName, "one");
|
||||
Expect.isNotNull(after, "There should have been a document returned post-update");
|
||||
Expect.equal(after.Id, "one", "The updated document is not correct");
|
||||
@ -428,10 +428,10 @@ public static class SqliteCSharpExtensionTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.UpdatePartialById(SqliteDb.TableName, "test", new { Foo = "green" });
|
||||
await conn.PatchById(SqliteDb.TableName, "test", new { Foo = "green" });
|
||||
})
|
||||
}),
|
||||
TestList("UpdatePartialByField", new[]
|
||||
TestList("PatchByField", new[]
|
||||
{
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
@ -439,7 +439,7 @@ public static class SqliteCSharpExtensionTests
|
||||
await using var conn = Sqlite.Configuration.DbConn();
|
||||
await LoadDocs();
|
||||
|
||||
await conn.UpdatePartialByField(SqliteDb.TableName, "Value", Op.EQ, "purple", new { NumValue = 77 });
|
||||
await conn.PatchByField(SqliteDb.TableName, "Value", Op.EQ, "purple", new { NumValue = 77 });
|
||||
var after = await conn.CountByField(SqliteDb.TableName, "NumValue", Op.EQ, 77);
|
||||
Expect.equal(after, 2L, "There should have been 2 documents returned");
|
||||
}),
|
||||
@ -451,7 +451,7 @@ public static class SqliteCSharpExtensionTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await conn.UpdatePartialByField(SqliteDb.TableName, "Value", Op.EQ, "burgundy", new { Foo = "green" });
|
||||
await conn.PatchByField(SqliteDb.TableName, "Value", Op.EQ, "burgundy", new { Foo = "green" });
|
||||
})
|
||||
}),
|
||||
TestList("DeleteById", new[]
|
||||
|
@ -25,17 +25,17 @@ public static class SqliteCSharpTests
|
||||
Expect.equal(Sqlite.Query.Definition.EnsureTable("tbl"),
|
||||
"CREATE TABLE IF NOT EXISTS tbl (data TEXT NOT NULL)", "CREATE TABLE statement not correct");
|
||||
}),
|
||||
TestList("Update", new[]
|
||||
TestList("Patch", new[]
|
||||
{
|
||||
TestCase("PartialById succeeds", () =>
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Update.PartialById("tbl"),
|
||||
Expect.equal(Sqlite.Query.Patch.ById("tbl"),
|
||||
"UPDATE tbl SET data = json_patch(data, json(@data)) WHERE data ->> 'Id' = @id",
|
||||
"UPDATE partial by ID statement not correct");
|
||||
}),
|
||||
TestCase("PartialByField succeeds", () =>
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Update.PartialByField("tbl", "Part", Op.NE),
|
||||
Expect.equal(Sqlite.Query.Patch.ByField("tbl", "Part", Op.NE),
|
||||
"UPDATE tbl SET data = json_patch(data, json(@data)) WHERE data ->> 'Part' <> @field",
|
||||
"UPDATE partial by JSON comparison query not correct");
|
||||
})
|
||||
@ -420,7 +420,7 @@ public static class SqliteCSharpTests
|
||||
}),
|
||||
TestList("Update", new[]
|
||||
{
|
||||
TestList("Full", new[]
|
||||
TestList("ById", new[]
|
||||
{
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
@ -428,7 +428,7 @@ public static class SqliteCSharpTests
|
||||
await LoadDocs();
|
||||
|
||||
var testDoc = new JsonDocument { Id = "one", Sub = new() { Foo = "blue", Bar = "red" } };
|
||||
await Update.Full(SqliteDb.TableName, "one", testDoc);
|
||||
await Update.ById(SqliteDb.TableName, "one", testDoc);
|
||||
var after = await Find.ById<string, JsonDocument>(SqliteDb.TableName, "one");
|
||||
Expect.isNotNull(after, "There should have been a document returned post-update");
|
||||
Expect.equal(after!.Id, "one", "The updated document is not correct");
|
||||
@ -444,18 +444,18 @@ public static class SqliteCSharpTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await Update.Full(SqliteDb.TableName, "test",
|
||||
await Update.ById(SqliteDb.TableName, "test",
|
||||
new JsonDocument { Id = "x", Sub = new() { Foo = "blue", Bar = "red" } });
|
||||
})
|
||||
}),
|
||||
TestList("FullFunc", new[]
|
||||
TestList("ByFunc", new[]
|
||||
{
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Update.FullFunc(SqliteDb.TableName, doc => doc.Id,
|
||||
await Update.ByFunc(SqliteDb.TableName, doc => doc.Id,
|
||||
new JsonDocument { Id = "one", Value = "le un", NumValue = 1 });
|
||||
var after = await Find.ById<string, JsonDocument>(SqliteDb.TableName, "one");
|
||||
Expect.isNotNull(after, "There should have been a document returned post-update");
|
||||
@ -472,18 +472,21 @@ public static class SqliteCSharpTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await Update.FullFunc(SqliteDb.TableName, doc => doc.Id,
|
||||
await Update.ByFunc(SqliteDb.TableName, doc => doc.Id,
|
||||
new JsonDocument { Id = "one", Value = "le un", NumValue = 1 });
|
||||
})
|
||||
}),
|
||||
TestList("PartialById", new[]
|
||||
}),
|
||||
TestList("Patch", new[]
|
||||
{
|
||||
TestList("ById", new[]
|
||||
{
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Update.PartialById(SqliteDb.TableName, "one", new { NumValue = 44 });
|
||||
await Patch.ById(SqliteDb.TableName, "one", new { NumValue = 44 });
|
||||
var after = await Find.ById<string, JsonDocument>(SqliteDb.TableName, "one");
|
||||
Expect.isNotNull(after, "There should have been a document returned post-update");
|
||||
Expect.equal(after!.Id, "one", "The updated document is not correct");
|
||||
@ -497,18 +500,17 @@ public static class SqliteCSharpTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await Update.PartialById(SqliteDb.TableName, "test", new { Foo = "green" });
|
||||
await Patch.ById(SqliteDb.TableName, "test", new { Foo = "green" });
|
||||
})
|
||||
}),
|
||||
TestList("PartialByField", new[]
|
||||
TestList("ByField", new[]
|
||||
{
|
||||
TestCase("succeeds when a document is updated", async () =>
|
||||
{
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
await Update.PartialByField(SqliteDb.TableName, "Value", Op.EQ, "purple",
|
||||
new { NumValue = 77 });
|
||||
await Patch.ByField(SqliteDb.TableName, "Value", Op.EQ, "purple", new { NumValue = 77 });
|
||||
var after = await Count.ByField(SqliteDb.TableName, "NumValue", Op.EQ, 77);
|
||||
Expect.equal(after, 2L, "There should have been 2 documents returned");
|
||||
}),
|
||||
@ -520,8 +522,7 @@ public static class SqliteCSharpTests
|
||||
Expect.isEmpty(before, "There should have been no documents returned");
|
||||
|
||||
// This not raising an exception is the test
|
||||
await Update.PartialByField(SqliteDb.TableName, "Value", Op.EQ, "burgundy",
|
||||
new { Foo = "green" });
|
||||
await Patch.ByField(SqliteDb.TableName, "Value", Op.EQ, "burgundy", new { Foo = "green" });
|
||||
})
|
||||
})
|
||||
}),
|
||||
|
@ -231,14 +231,14 @@ let integrationTests =
|
||||
Expect.isFalse (Option.isSome doc) "There should not have been a document returned"
|
||||
}
|
||||
]
|
||||
testList "updateFull" [
|
||||
testList "updateById" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
use conn = Configuration.dbConn ()
|
||||
do! loadDocs ()
|
||||
|
||||
let testDoc = { emptyDoc with Id = "one"; Sub = Some { Foo = "blue"; Bar = "red" } }
|
||||
do! conn.updateFull SqliteDb.TableName "one" testDoc
|
||||
do! conn.updateById SqliteDb.TableName "one" testDoc
|
||||
let! after = conn.findById<string, JsonDocument> SqliteDb.TableName "one"
|
||||
if Option.isNone after then
|
||||
Expect.isTrue false "There should have been a document returned post-update"
|
||||
@ -252,22 +252,20 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! conn.updateFull
|
||||
do! conn.updateById
|
||||
SqliteDb.TableName
|
||||
"test"
|
||||
{ emptyDoc with Id = "x"; Sub = Some { Foo = "blue"; Bar = "red" } }
|
||||
}
|
||||
]
|
||||
testList "updateFullFunc" [
|
||||
testList "updateByFunc" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
use conn = Configuration.dbConn ()
|
||||
do! loadDocs ()
|
||||
|
||||
do! conn.updateFullFunc
|
||||
SqliteDb.TableName
|
||||
(_.Id)
|
||||
{ Id = "one"; Value = "le un"; NumValue = 1; Sub = None }
|
||||
do! conn.updateByFunc
|
||||
SqliteDb.TableName (_.Id) { Id = "one"; Value = "le un"; NumValue = 1; Sub = None }
|
||||
let! after = conn.findById<string, JsonDocument> SqliteDb.TableName "one"
|
||||
if Option.isNone after then
|
||||
Expect.isTrue false "There should have been a document returned post-update"
|
||||
@ -284,19 +282,17 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! conn.updateFullFunc
|
||||
SqliteDb.TableName
|
||||
(_.Id)
|
||||
{ Id = "one"; Value = "le un"; NumValue = 1; Sub = None }
|
||||
do! conn.updateByFunc
|
||||
SqliteDb.TableName (_.Id) { Id = "one"; Value = "le un"; NumValue = 1; Sub = None }
|
||||
}
|
||||
]
|
||||
testList "updatePartialById" [
|
||||
testList "patchById" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
use conn = Configuration.dbConn ()
|
||||
do! loadDocs ()
|
||||
|
||||
do! conn.updatePartialById SqliteDb.TableName "one" {| NumValue = 44 |}
|
||||
do! conn.patchById SqliteDb.TableName "one" {| NumValue = 44 |}
|
||||
let! after = conn.findById<string, JsonDocument> SqliteDb.TableName "one"
|
||||
if Option.isNone after then
|
||||
Expect.isTrue false "There should have been a document returned post-update"
|
||||
@ -310,16 +306,16 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! conn.updatePartialById SqliteDb.TableName "test" {| Foo = "green" |}
|
||||
do! conn.patchById SqliteDb.TableName "test" {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
testList "updatePartialByField" [
|
||||
testList "patchByField" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
use conn = Configuration.dbConn ()
|
||||
do! loadDocs ()
|
||||
|
||||
do! conn.updatePartialByField SqliteDb.TableName "Value" EQ "purple" {| NumValue = 77 |}
|
||||
do! conn.patchByField SqliteDb.TableName "Value" EQ "purple" {| NumValue = 77 |}
|
||||
let! after = conn.countByField SqliteDb.TableName "NumValue" EQ 77
|
||||
Expect.equal after 2L "There should have been 2 documents returned"
|
||||
}
|
||||
@ -331,7 +327,7 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! conn.updatePartialByField SqliteDb.TableName "Value" EQ "burgundy" {| Foo = "green" |}
|
||||
do! conn.patchByField SqliteDb.TableName "Value" EQ "burgundy" {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
testList "deleteById" [
|
||||
|
@ -17,16 +17,16 @@ let unitTests =
|
||||
"CREATE TABLE IF NOT EXISTS tbl (data TEXT NOT NULL)"
|
||||
"CREATE TABLE statement not correct"
|
||||
}
|
||||
testList "Update" [
|
||||
test "partialById succeeds" {
|
||||
testList "Patch" [
|
||||
test "byId succeeds" {
|
||||
Expect.equal
|
||||
(Query.Update.partialById "tbl")
|
||||
(Query.Patch.byId "tbl")
|
||||
"UPDATE tbl SET data = json_patch(data, json(@data)) WHERE data ->> 'Id' = @id"
|
||||
"UPDATE partial by ID statement not correct"
|
||||
}
|
||||
test "partialByField succeeds" {
|
||||
test "byField succeeds" {
|
||||
Expect.equal
|
||||
(Query.Update.partialByField "tbl" "Part" NE)
|
||||
(Query.Patch.byField "tbl" "Part" NE)
|
||||
"UPDATE tbl SET data = json_patch(data, json(@data)) WHERE data ->> 'Part' <> @field"
|
||||
"UPDATE partial by JSON comparison query not correct"
|
||||
}
|
||||
@ -385,13 +385,13 @@ let integrationTests =
|
||||
]
|
||||
]
|
||||
testList "Update" [
|
||||
testList "full" [
|
||||
testList "byId" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
let testDoc = { emptyDoc with Id = "one"; Sub = Some { Foo = "blue"; Bar = "red" } }
|
||||
do! Update.full SqliteDb.TableName "one" testDoc
|
||||
do! Update.byId SqliteDb.TableName "one" testDoc
|
||||
let! after = Find.byId<string, JsonDocument> SqliteDb.TableName "one"
|
||||
Expect.isSome after "There should have been a document returned post-update"
|
||||
Expect.equal after.Value testDoc "The updated document is not correct"
|
||||
@ -403,18 +403,19 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! Update.full
|
||||
do! Update.byId
|
||||
SqliteDb.TableName
|
||||
"test"
|
||||
{ emptyDoc with Id = "x"; Sub = Some { Foo = "blue"; Bar = "red" } }
|
||||
}
|
||||
]
|
||||
testList "fullFunc" [
|
||||
testList "byFunc" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Update.fullFunc SqliteDb.TableName (_.Id) { Id = "one"; Value = "le un"; NumValue = 1; Sub = None }
|
||||
do! Update.byFunc
|
||||
SqliteDb.TableName (_.Id) { Id = "one"; Value = "le un"; NumValue = 1; Sub = None }
|
||||
let! after = Find.byId<string, JsonDocument> SqliteDb.TableName "one"
|
||||
Expect.isSome after "There should have been a document returned post-update"
|
||||
Expect.equal
|
||||
@ -429,15 +430,18 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! Update.fullFunc SqliteDb.TableName (_.Id) { Id = "one"; Value = "le un"; NumValue = 1; Sub = None }
|
||||
do! Update.byFunc
|
||||
SqliteDb.TableName (_.Id) { Id = "one"; Value = "le un"; NumValue = 1; Sub = None }
|
||||
}
|
||||
]
|
||||
testList "partialById" [
|
||||
]
|
||||
testList "Patch" [
|
||||
testList "byId" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Update.partialById SqliteDb.TableName "one" {| NumValue = 44 |}
|
||||
do! Patch.byId SqliteDb.TableName "one" {| NumValue = 44 |}
|
||||
let! after = Find.byId<string, JsonDocument> SqliteDb.TableName "one"
|
||||
Expect.isSome after "There should have been a document returned post-update"
|
||||
Expect.equal after.Value.NumValue 44 "The updated document is not correct"
|
||||
@ -449,15 +453,15 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! Update.partialById SqliteDb.TableName "test" {| Foo = "green" |}
|
||||
do! Patch.byId SqliteDb.TableName "test" {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
testList "partialByField" [
|
||||
testList "byField" [
|
||||
testTask "succeeds when a document is updated" {
|
||||
use! db = SqliteDb.BuildDb()
|
||||
do! loadDocs ()
|
||||
|
||||
do! Update.partialByField SqliteDb.TableName "Value" EQ "purple" {| NumValue = 77 |}
|
||||
do! Patch.byField SqliteDb.TableName "Value" EQ "purple" {| NumValue = 77 |}
|
||||
let! after = Count.byField SqliteDb.TableName "NumValue" EQ 77
|
||||
Expect.equal after 2L "There should have been 2 documents returned"
|
||||
}
|
||||
@ -468,7 +472,7 @@ let integrationTests =
|
||||
Expect.isEmpty before "There should have been no documents returned"
|
||||
|
||||
// This not raising an exception is the test
|
||||
do! Update.partialByField SqliteDb.TableName "Value" EQ "burgundy" {| Foo = "green" |}
|
||||
do! Patch.byField SqliteDb.TableName "Value" EQ "burgundy" {| Foo = "green" |}
|
||||
}
|
||||
]
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user