First cut of BT operator (#3)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Expecto.CSharp;
|
||||
using Expecto;
|
||||
using Microsoft.FSharp.Collections;
|
||||
|
||||
namespace BitBadger.Documents.Tests.CSharp;
|
||||
|
||||
@@ -96,6 +97,10 @@ public static class CommonCSharpTests
|
||||
{
|
||||
Expect.equal(Op.NE.ToString(), "<>", "The not equal to operator was not correct");
|
||||
}),
|
||||
TestCase("BT succeeds", () =>
|
||||
{
|
||||
Expect.equal(Op.BT.ToString(), "BETWEEN", "The \"between\" operator was not correct");
|
||||
}),
|
||||
TestCase("EX succeeds", () =>
|
||||
{
|
||||
Expect.equal(Op.EX.ToString(), "IS NOT NULL", "The \"exists\" operator was not correct");
|
||||
@@ -149,6 +154,13 @@ public static class CommonCSharpTests
|
||||
Expect.equal(field.Op, Op.NE, "Operator incorrect");
|
||||
Expect.equal(field.Value, "here", "Value incorrect");
|
||||
}),
|
||||
TestCase("BT succeeds", () =>
|
||||
{
|
||||
var field = Field.BT("Age", 18, 49);
|
||||
Expect.equal(field.Name, "Age", "Field name incorrect");
|
||||
Expect.equal(field.Op, Op.BT, "Operator incorrect");
|
||||
Expect.equal(((FSharpList<object>)field.Value).ToArray(), new object[] { 18, 49 }, "Value incorrect");
|
||||
}),
|
||||
TestCase("EX succeeds", () =>
|
||||
{
|
||||
var field = Field.EX("Groovy");
|
||||
@@ -169,23 +181,6 @@ public static class CommonCSharpTests
|
||||
Expect.equal(Query.SelectFromTable("test.table"), "SELECT data FROM test.table",
|
||||
"SELECT statement not correct");
|
||||
}),
|
||||
TestCase("WhereById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.WhereById("@id"), "data ->> 'Id' = @id", "WHERE clause not correct");
|
||||
}),
|
||||
TestList("WhereByField", new[]
|
||||
{
|
||||
TestCase("succeeds when a logical operator is passed", () =>
|
||||
{
|
||||
Expect.equal(Query.WhereByField(Field.GT("theField", 0), "@test"), "data ->> 'theField' > @test",
|
||||
"WHERE clause not correct");
|
||||
}),
|
||||
TestCase("succeeds when an existence operator is passed", () =>
|
||||
{
|
||||
Expect.equal(Query.WhereByField(Field.NEX("thatField"), ""), "data ->> 'thatField' IS NULL",
|
||||
"WHERE clause not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Definition", new[]
|
||||
{
|
||||
TestCase("EnsureTableFor succeeds", () =>
|
||||
@@ -226,69 +221,8 @@ public static class CommonCSharpTests
|
||||
TestCase("Save succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Save("tbl"),
|
||||
$"INSERT INTO tbl VALUES (@data) ON CONFLICT ((data ->> 'Id')) DO UPDATE SET data = EXCLUDED.data",
|
||||
"INSERT INTO tbl VALUES (@data) ON CONFLICT ((data->>'Id')) DO UPDATE SET data = EXCLUDED.data",
|
||||
"INSERT ON CONFLICT UPDATE statement not correct");
|
||||
}),
|
||||
TestCase("Update succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Update("tbl"), "UPDATE tbl SET data = @data WHERE data ->> 'Id' = @id",
|
||||
"UPDATE full statement not correct");
|
||||
}),
|
||||
TestList("Count", new[]
|
||||
{
|
||||
TestCase("All succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Count.All("tbl"), "SELECT COUNT(*) AS it FROM tbl", "Count query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Count.ByField("tbl", Field.EQ("thatField", 0)),
|
||||
"SELECT COUNT(*) AS it FROM tbl WHERE data ->> 'thatField' = @field",
|
||||
"JSON field text comparison count query not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Exists", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Exists.ById("tbl"),
|
||||
"SELECT EXISTS (SELECT 1 FROM tbl WHERE data ->> 'Id' = @id) AS it",
|
||||
"ID existence query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Exists.ByField("tbl", Field.LT("Test", 0)),
|
||||
"SELECT EXISTS (SELECT 1 FROM tbl WHERE data ->> 'Test' < @field) AS it",
|
||||
"JSON field text comparison exists query not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Find", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Find.ById("tbl"), "SELECT data FROM tbl WHERE data ->> 'Id' = @id",
|
||||
"SELECT by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Find.ByField("tbl", Field.GE("Golf", 0)),
|
||||
"SELECT data FROM tbl WHERE data ->> 'Golf' >= @field",
|
||||
"SELECT by JSON comparison query not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Delete", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Delete.ById("tbl"), "DELETE FROM tbl WHERE data ->> 'Id' = @id",
|
||||
"DELETE by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Query.Delete.ByField("tbl", Field.NEX("gone")),
|
||||
"DELETE FROM tbl WHERE data ->> 'gone' IS NULL",
|
||||
"DELETE by JSON comparison query not correct");
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
@@ -47,42 +47,48 @@ public static class PostgresCSharpTests
|
||||
{
|
||||
var it = Parameters.AddField("@it", Field.EX("It"), Enumerable.Empty<Tuple<string, SqlValue>>());
|
||||
Expect.isEmpty(it, "There should not have been any parameters added");
|
||||
}),
|
||||
TestCase("succeeds when two parameters are added", () =>
|
||||
{
|
||||
var it = Parameters.AddField("@field", Field.BT("that", "eh", "zed"),
|
||||
Enumerable.Empty<Tuple<string, SqlValue>>()).ToList();
|
||||
Expect.hasLength(it, 2, "There should have been 2 parameters added");
|
||||
Expect.equal(it[0].Item1, "@fieldmin", "Minimum field name not correct");
|
||||
Expect.isTrue(it[0].Item2.IsParameter, "Minimum field parameter value incorrect");
|
||||
Expect.equal(it[1].Item1, "@fieldmax", "Maximum field name not correct");
|
||||
Expect.isTrue(it[1].Item2.IsParameter, "Maximum field parameter value incorrect");
|
||||
})
|
||||
}),
|
||||
TestList("RemoveFields", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.RemoveFields.ById("tbl"),
|
||||
"UPDATE tbl SET data = data - @name WHERE data ->> 'Id' = @id",
|
||||
"Remove field by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.RemoveFields.ByField("tbl", Field.LT("Fly", 0)),
|
||||
"UPDATE tbl SET data = data - @name WHERE data ->> 'Fly' < @field",
|
||||
"Remove field by field query not correct");
|
||||
}),
|
||||
TestCase("ByContains succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.RemoveFields.ByContains("tbl"),
|
||||
"UPDATE tbl SET data = data - @name WHERE data @> @criteria",
|
||||
"Remove field by contains query not correct");
|
||||
}),
|
||||
TestCase("ByJsonPath succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.RemoveFields.ByJsonPath("tbl"),
|
||||
"UPDATE tbl SET data = data - @name WHERE data @? @path::jsonpath",
|
||||
"Remove field by JSON path query not correct");
|
||||
})
|
||||
}),
|
||||
TestCase("None succeeds", () =>
|
||||
{
|
||||
Expect.isEmpty(Parameters.None, "The no-params sequence should be empty");
|
||||
})
|
||||
}),
|
||||
TestList("Query", new[]
|
||||
{
|
||||
TestList("WhereByField", new[]
|
||||
{
|
||||
TestCase("succeeds when a logical operator is passed", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.WhereByField(Field.GT("theField", 0), "@test"),
|
||||
"data->>'theField' > @test", "WHERE clause not correct");
|
||||
}),
|
||||
TestCase("succeeds when an existence operator is passed", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.WhereByField(Field.NEX("thatField"), ""), "data->>'thatField' IS NULL",
|
||||
"WHERE clause not correct");
|
||||
}),
|
||||
TestCase("succeeds when a between operator is passed with numeric values", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.WhereByField(Field.BT("aField", 50, 99), "@range"),
|
||||
"(data->>'aField')::numeric BETWEEN @rangemin AND @rangemax", "WHERE clause not correct");
|
||||
}),
|
||||
TestCase("succeeds when a between operator is passed with non-numeric values", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.WhereByField(Field.BT("field0", "a", "b"), "@alpha"),
|
||||
"data->>'field0' BETWEEN @alphamin AND @alphamax", "WHERE clause not correct");
|
||||
})
|
||||
}),
|
||||
TestCase("WhereById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.WhereById("@id"), "data->>'Id' = @id", "WHERE clause not correct");
|
||||
}),
|
||||
TestList("Definition", new[]
|
||||
{
|
||||
TestCase("EnsureTable succeeds", () =>
|
||||
@@ -107,6 +113,11 @@ public static class PostgresCSharpTests
|
||||
"CREATE INDEX statement not constructed correctly");
|
||||
})
|
||||
}),
|
||||
TestCase("Update succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Update("tbl"), "UPDATE tbl SET data = @data WHERE data->>'Id' = @id",
|
||||
"UPDATE full statement not correct");
|
||||
}),
|
||||
TestCase("WhereDataContains succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.WhereDataContains("@test"), "data @> @test",
|
||||
@@ -119,6 +130,17 @@ public static class PostgresCSharpTests
|
||||
}),
|
||||
TestList("Count", new[]
|
||||
{
|
||||
TestCase("All succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Count.All(PostgresDb.TableName),
|
||||
$"SELECT COUNT(*) AS it FROM {PostgresDb.TableName}", "Count query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Count.ByField(PostgresDb.TableName, Field.EQ("thatField", 0)),
|
||||
$"SELECT COUNT(*) AS it FROM {PostgresDb.TableName} WHERE data->>'thatField' = @field",
|
||||
"JSON field text comparison count query not correct");
|
||||
}),
|
||||
TestCase("ByContains succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Count.ByContains(PostgresDb.TableName),
|
||||
@@ -134,6 +156,18 @@ public static class PostgresCSharpTests
|
||||
}),
|
||||
TestList("Exists", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Exists.ById(PostgresDb.TableName),
|
||||
$"SELECT EXISTS (SELECT 1 FROM {PostgresDb.TableName} WHERE data->>'Id' = @id) AS it",
|
||||
"ID existence query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Exists.ByField(PostgresDb.TableName, Field.LT("Test", 0)),
|
||||
$"SELECT EXISTS (SELECT 1 FROM {PostgresDb.TableName} WHERE data->>'Test' < @field) AS it",
|
||||
"JSON field text comparison exists query not correct");
|
||||
}),
|
||||
TestCase("ByContains succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Exists.ByContains(PostgresDb.TableName),
|
||||
@@ -149,6 +183,18 @@ public static class PostgresCSharpTests
|
||||
}),
|
||||
TestList("Find", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Find.ById(PostgresDb.TableName),
|
||||
$"SELECT data FROM {PostgresDb.TableName} WHERE data->>'Id' = @id",
|
||||
"SELECT by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Find.ByField(PostgresDb.TableName, Field.GE("Golf", 0)),
|
||||
$"SELECT data FROM {PostgresDb.TableName} WHERE data->>'Golf' >= @field",
|
||||
"SELECT by JSON comparison query not correct");
|
||||
}),
|
||||
TestCase("byContains succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Find.ByContains(PostgresDb.TableName),
|
||||
@@ -167,13 +213,13 @@ public static class PostgresCSharpTests
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Patch.ById(PostgresDb.TableName),
|
||||
$"UPDATE {PostgresDb.TableName} SET data = data || @data WHERE data ->> 'Id' = @id",
|
||||
$"UPDATE {PostgresDb.TableName} SET data = data || @data WHERE data->>'Id' = @id",
|
||||
"UPDATE partial by ID statement not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Patch.ByField(PostgresDb.TableName, Field.LT("Snail", 0)),
|
||||
$"UPDATE {PostgresDb.TableName} SET data = data || @data WHERE data ->> 'Snail' < @field",
|
||||
$"UPDATE {PostgresDb.TableName} SET data = data || @data WHERE data->>'Snail' < @field",
|
||||
"UPDATE partial by ID statement not correct");
|
||||
}),
|
||||
TestCase("ByContains succeeds", () =>
|
||||
@@ -189,8 +235,47 @@ public static class PostgresCSharpTests
|
||||
"UPDATE partial by JSON Path statement not correct");
|
||||
})
|
||||
}),
|
||||
TestList("RemoveFields", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.RemoveFields.ById(PostgresDb.TableName),
|
||||
$"UPDATE {PostgresDb.TableName} SET data = data - @name WHERE data->>'Id' = @id",
|
||||
"Remove field by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.RemoveFields.ByField(PostgresDb.TableName, Field.LT("Fly", 0)),
|
||||
$"UPDATE {PostgresDb.TableName} SET data = data - @name WHERE data->>'Fly' < @field",
|
||||
"Remove field by field query not correct");
|
||||
}),
|
||||
TestCase("ByContains succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.RemoveFields.ByContains(PostgresDb.TableName),
|
||||
$"UPDATE {PostgresDb.TableName} SET data = data - @name WHERE data @> @criteria",
|
||||
"Remove field by contains query not correct");
|
||||
}),
|
||||
TestCase("ByJsonPath succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.RemoveFields.ByJsonPath(PostgresDb.TableName),
|
||||
$"UPDATE {PostgresDb.TableName} SET data = data - @name WHERE data @? @path::jsonpath",
|
||||
"Remove field by JSON path query not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Delete", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Delete.ById(PostgresDb.TableName),
|
||||
$"DELETE FROM {PostgresDb.TableName} WHERE data->>'Id' = @id",
|
||||
"DELETE by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Delete.ByField(PostgresDb.TableName, Field.NEX("gone")),
|
||||
$"DELETE FROM {PostgresDb.TableName} WHERE data->>'gone' IS NULL",
|
||||
"DELETE by JSON comparison query not correct");
|
||||
}),
|
||||
TestCase("byContains succeeds", () =>
|
||||
{
|
||||
Expect.equal(Postgres.Query.Delete.ByContains(PostgresDb.TableName),
|
||||
@@ -469,8 +554,8 @@ public static class PostgresCSharpTests
|
||||
await using var db = PostgresDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var theCount = await Count.ByField(PostgresDb.TableName, Field.EQ("Value", "purple"));
|
||||
Expect.equal(theCount, 2, "There should have been 2 matching documents");
|
||||
var theCount = await Count.ByField(PostgresDb.TableName, Field.BT("NumValue", 10, 20));
|
||||
Expect.equal(theCount, 3, "There should have been 3 matching documents");
|
||||
}),
|
||||
TestCase("ByContains succeeds", async () =>
|
||||
{
|
||||
|
||||
@@ -21,23 +21,93 @@ public static class SqliteCSharpTests
|
||||
{
|
||||
TestList("Query", new[]
|
||||
{
|
||||
TestList("WhereByField", new[]
|
||||
{
|
||||
TestCase("succeeds when a logical operator is passed", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.WhereByField(Field.GT("theField", 0), "@test"),
|
||||
"data->>'theField' > @test", "WHERE clause not correct");
|
||||
}),
|
||||
TestCase("succeeds when an existence operator is passed", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.WhereByField(Field.NEX("thatField"), ""), "data->>'thatField' IS NULL",
|
||||
"WHERE clause not correct");
|
||||
}),
|
||||
TestCase("succeeds when the between operator is passed", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.WhereByField(Field.BT("aField", 50, 99), "@range"),
|
||||
"data->>'aField' BETWEEN @rangemin AND @rangemax", "WHERE clause not correct");
|
||||
})
|
||||
}),
|
||||
TestCase("WhereById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.WhereById("@id"), "data->>'Id' = @id", "WHERE clause not correct");
|
||||
}),
|
||||
TestCase("Definition.EnsureTable succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Definition.EnsureTable("tbl"),
|
||||
"CREATE TABLE IF NOT EXISTS tbl (data TEXT NOT NULL)", "CREATE TABLE statement not correct");
|
||||
}),
|
||||
TestCase("Update succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Update("tbl"), "UPDATE tbl SET data = @data WHERE data->>'Id' = @id",
|
||||
"UPDATE full statement not correct");
|
||||
}),
|
||||
TestList("Count", new[]
|
||||
{
|
||||
TestCase("All succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Count.All("tbl"), "SELECT COUNT(*) AS it FROM tbl",
|
||||
"Count query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Count.ByField("tbl", Field.EQ("thatField", 0)),
|
||||
"SELECT COUNT(*) AS it FROM tbl WHERE data->>'thatField' = @field",
|
||||
"JSON field text comparison count query not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Exists", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Exists.ById("tbl"),
|
||||
"SELECT EXISTS (SELECT 1 FROM tbl WHERE data->>'Id' = @id) AS it",
|
||||
"ID existence query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Exists.ByField("tbl", Field.LT("Test", 0)),
|
||||
"SELECT EXISTS (SELECT 1 FROM tbl WHERE data->>'Test' < @field) AS it",
|
||||
"JSON field text comparison exists query not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Find", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Find.ById("tbl"), "SELECT data FROM tbl WHERE data->>'Id' = @id",
|
||||
"SELECT by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Find.ByField("tbl", Field.GE("Golf", 0)),
|
||||
"SELECT data FROM tbl WHERE data->>'Golf' >= @field",
|
||||
"SELECT by JSON comparison query not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Patch", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Patch.ById("tbl"),
|
||||
"UPDATE tbl SET data = json_patch(data, json(@data)) WHERE data ->> 'Id' = @id",
|
||||
"UPDATE tbl SET data = json_patch(data, json(@data)) WHERE data->>'Id' = @id",
|
||||
"UPDATE partial by ID statement not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Patch.ByField("tbl", Field.NE("Part", 0)),
|
||||
"UPDATE tbl SET data = json_patch(data, json(@data)) WHERE data ->> 'Part' <> @field",
|
||||
"UPDATE tbl SET data = json_patch(data, json(@data)) WHERE data->>'Part' <> @field",
|
||||
"UPDATE partial by JSON comparison query not correct");
|
||||
})
|
||||
}),
|
||||
@@ -46,16 +116,29 @@ public static class SqliteCSharpTests
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.RemoveFields.ById("tbl", new[] { new SqliteParameter("@name", "one") }),
|
||||
"UPDATE tbl SET data = json_remove(data, @name) WHERE data ->> 'Id' = @id",
|
||||
"UPDATE tbl SET data = json_remove(data, @name) WHERE data->>'Id' = @id",
|
||||
"Remove field by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.RemoveFields.ByField("tbl", Field.LT("Fly", 0),
|
||||
new[] { new SqliteParameter("@name0", "one"), new SqliteParameter("@name1", "two") }),
|
||||
"UPDATE tbl SET data = json_remove(data, @name0, @name1) WHERE data ->> 'Fly' < @field",
|
||||
"UPDATE tbl SET data = json_remove(data, @name0, @name1) WHERE data->>'Fly' < @field",
|
||||
"Remove field by field query not correct");
|
||||
})
|
||||
}),
|
||||
TestList("Delete", new[]
|
||||
{
|
||||
TestCase("ById succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Delete.ById("tbl"), "DELETE FROM tbl WHERE data->>'Id' = @id",
|
||||
"DELETE by ID query not correct");
|
||||
}),
|
||||
TestCase("ByField succeeds", () =>
|
||||
{
|
||||
Expect.equal(Sqlite.Query.Delete.ByField("tbl", Field.NEX("gone")),
|
||||
"DELETE FROM tbl WHERE data->>'gone' IS NULL", "DELETE by JSON comparison query not correct");
|
||||
})
|
||||
})
|
||||
}),
|
||||
TestList("Parameters", new[]
|
||||
@@ -321,8 +404,8 @@ public static class SqliteCSharpTests
|
||||
await using var db = await SqliteDb.BuildDb();
|
||||
await LoadDocs();
|
||||
|
||||
var theCount = await Count.ByField(SqliteDb.TableName, Field.EQ("Value", "purple"));
|
||||
Expect.equal(theCount, 2L, "There should have been 2 matching documents");
|
||||
var theCount = await Count.ByField(SqliteDb.TableName, Field.BT("NumValue", 10, 20));
|
||||
Expect.equal(theCount, 3L, "There should have been 3 matching documents");
|
||||
})
|
||||
}),
|
||||
TestList("Exists", new[]
|
||||
|
||||
Reference in New Issue
Block a user