Skip to content

Commit

Permalink
all tests pass on the master
Browse files Browse the repository at this point in the history
  • Loading branch information
marhoily committed Sep 2, 2023
1 parent 1b094c9 commit d7cadc1
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 50 deletions.
10 changes: 6 additions & 4 deletions QueryBuilder.Tests/ApprovalTests/CompileFlatColumns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public Task ReturnId(Compiler compiler)
public Task InsertQueryClause(Compiler compiler)
{
return new Query("X")
.AsInsert(new[]{"a"}, new Query("Y"))
.AsInsert(new[] { "a" }, new Query("Y"))
.Verify(compiler);
}
}
Expand All @@ -676,9 +676,11 @@ public Task Join(Compiler compiler)
}
[Theory]
[ClassData(typeof(AllCompilers))]
public Task Join_NoFrom(Compiler compiler)
public void Join_NoFrom(Compiler compiler)
{
return new Query().CrossJoin("Y").AsDelete().Verify(compiler);
Assert.Throws<InvalidOperationException>(
() => compiler.Compile(new Query().CrossJoin("Y").AsDelete()))
.Message.Should().Be("No table set to delete");
}
}

Expand All @@ -690,7 +692,7 @@ public sealed class CompileUpdateQuery
public Task CompileUpdate(Compiler compiler)
{
return new Query("X")
.AsUpdate(new {a = 1})
.AsUpdate(new { a = 1 })
.Verify(compiler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

SELECT *
FROM "X"
WHERE "a" like 'K'%
WHERE "a" like 'K%'

----------- RAW -------------

SELECT *
FROM "X"
WHERE "a" like ?%
WHERE "a" like ?

--------PARAMETRIZED --------

SELECT *
FROM "X"
WHERE "a" like @p0%
WHERE "a" like @p0
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

SELECT *
FROM "X"
WHERE "a" ilike %'k'%
WHERE "a" ilike '%k%'

----------- RAW -------------

SELECT *
FROM "X"
WHERE "a" ilike %?%
WHERE "a" ilike ?

--------PARAMETRIZED --------

SELECT *
FROM "X"
WHERE "a" ilike %@p0%
WHERE "a" ilike @p0
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

SELECT *
FROM "X"
WHERE "a" ilike %'k'
WHERE "a" ilike '%k'

----------- RAW -------------

SELECT *
FROM "X"
WHERE "a" ilike %?
WHERE "a" ilike ?

--------PARAMETRIZED --------

SELECT *
FROM "X"
WHERE "a" ilike %@p0
WHERE "a" ilike @p0
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

SELECT *
FROM "X"
WHERE "a" ilike 'K*'% ESCAPE '*'
WHERE "a" ilike 'K*%' ESCAPE '*'

----------- RAW -------------

SELECT *
FROM "X"
WHERE "a" ilike ?% ESCAPE '*'
WHERE "a" ilike ? ESCAPE '*'

--------PARAMETRIZED --------

SELECT *
FROM "X"
WHERE "a" ilike @p0% ESCAPE '*'
WHERE "a" ilike @p0 ESCAPE '*'
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

SELECT *
FROM "X"
WHERE "a" ilike 'k'%
WHERE "a" ilike 'k%'

----------- RAW -------------

SELECT *
FROM "X"
WHERE "a" ilike ?%
WHERE "a" ilike ?

--------PARAMETRIZED --------

SELECT *
FROM "X"
WHERE "a" ilike @p0%
WHERE "a" ilike @p0
17 changes: 6 additions & 11 deletions QueryBuilder/Compilers/Compiler.Conditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,13 @@ private void CompileBasicCondition(Query query, BasicCondition x, Writer writer)
writer.Append(" ");
if (isLikeOperator)
{
switch (x.Operator)
value = x.Operator switch
{
case "starts":
value = $"{value}%";
break;
case "ends":
value = $"%{value}";
break;
case "contains":
value = $"%{value}%";
break;
}
"starts" => $"{value}%",
"ends" => $"%{value}",
"contains" => $"%{value}%",
_ => value
};
}
writer.AppendParameter(query,
x.CaseSensitive ? value : value.ToLowerInvariant());
Expand Down
4 changes: 2 additions & 2 deletions QueryBuilder/Compilers/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Compiler Whitelist(params string[] operators)
return this;
}

public void CompileRaw(Query query, Writer writer)
internal void CompileRaw(Query query, Writer writer)
{
// handle CTEs
if (query.HasComponent("cte", EngineCode))
Expand Down Expand Up @@ -162,7 +162,7 @@ private void CompileDeleteQuery(Query query, Writer writer)
{
var fromClause = query.GetOneComponent<AbstractFrom>("from", EngineCode);
if (fromClause is not FromClause c)
return;
throw new InvalidOperationException("No table set to delete");

writer.Append("DELETE ");
writer.AppendName(c.Alias);
Expand Down
25 changes: 7 additions & 18 deletions QueryBuilder/Compilers/PostgresCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,14 @@ public PostgresCompiler()
writer.Append(" ");
if (isLikeOperator)
{
switch (x.Operator)
value = x.Operator switch
{
case "starts":
writer.AppendParameter(query, value);
writer.Append("%");
break;
case "ends":
writer.Append("%");
writer.AppendParameter(query, value);
break;
case "contains":
writer.Append("%");
writer.AppendParameter(query, value);
writer.Append("%");
break;
default:
writer.AppendParameter(query, value);
break;
}
"starts" => $"{value}%",
"ends" => $"%{value}",
"contains" => $"%{value}%",
_ => value
};
writer.AppendParameter(query, value);
}
else
{
Expand Down

0 comments on commit d7cadc1

Please sign in to comment.