-
-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #614 from sqlkata/iss-182_delete_join_support
Issue 182 - delete with join support
- Loading branch information
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using SqlKata.Compilers; | ||
using SqlKata.Extensions; | ||
using SqlKata.Tests.Infrastructure; | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace SqlKata.Tests | ||
{ | ||
public class DeleteTests : TestSupport | ||
{ | ||
[Fact] | ||
public void BasicDelete() | ||
{ | ||
var q = new Query("Posts").AsDelete(); | ||
|
||
var c = Compile(q); | ||
|
||
Assert.Equal("DELETE FROM [Posts]", c[EngineCodes.SqlServer]); | ||
} | ||
|
||
[Fact] | ||
public void DeleteWithJoin() | ||
{ | ||
var q = new Query("Posts") | ||
.Join("Authors", "Authors.Id", "Posts.AuthorId") | ||
.Where("Authors.Id", 5) | ||
.AsDelete(); | ||
|
||
var c = Compile(q); | ||
|
||
Assert.Equal("DELETE [Posts] FROM [Posts] \nINNER JOIN [Authors] ON [Authors].[Id] = [Posts].[AuthorId] WHERE [Authors].[Id] = 5", c[EngineCodes.SqlServer]); | ||
Assert.Equal("DELETE `Posts` FROM `Posts` \nINNER JOIN `Authors` ON `Authors`.`Id` = `Posts`.`AuthorId` WHERE `Authors`.`Id` = 5", c[EngineCodes.MySql]); | ||
} | ||
|
||
[Fact] | ||
public void DeleteWithJoinAndAlias() | ||
{ | ||
var q = new Query("Posts as P") | ||
.Join("Authors", "Authors.Id", "P.AuthorId") | ||
.Where("Authors.Id", 5) | ||
.AsDelete(); | ||
|
||
var c = Compile(q); | ||
|
||
Assert.Equal("DELETE [P] FROM [Posts] AS [P] \nINNER JOIN [Authors] ON [Authors].[Id] = [P].[AuthorId] WHERE [Authors].[Id] = 5", c[EngineCodes.SqlServer]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters