querybuilder icon indicating copy to clipboard operation
querybuilder copied to clipboard

Allow sub queries in inserts alongside parameters

Open patrickratzow opened this issue 3 years ago • 1 comments

Allow mixing parameterized insert queries & query inserts. This is very useful when you have some of the data, but is looking to get the rest of the data directly in the database without having to execute another query in C#, due to it increasing the overall time spent as a result of the extra round trip.

Example use case

var discordId = "discord_id_value";
var steamId = "steam_id_value";
var query = new Query("Discord")
    .AsInsert(
        new[] {"Id", "UserId"},
        new object[]
        {
            discordId,
            new Query("User")
                .Select("Id")
                .Where("SteamId", steamId)
        }
    );

Which would then compile into

INSERT INTO
  [Discord] ([Id], [UserId])
VALUES
  ('discord_id_value', (SELECT [Id] FROM [User] WHERE [SteamId] = 'steam_id_value'))

patrickratzow avatar Apr 27 '21 19:04 patrickratzow