Skip to content

Commit

Permalink
allow subquery values in insert_all (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski committed Dec 10, 2023
1 parent 4378ca8 commit 00ceb86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/ecto/adapters/sqlite3/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ defmodule Ecto.Adapters.SQLite3.Connection do
raise ArgumentError,
"Cell-wise default values are not supported on INSERT statements by SQLite3"

{%Ecto.Query{} = query, params_counter}, counter ->
{[?(, all(query), ?)], counter + params_counter}

_, counter ->
# TODO: Should we have cell wise value support?
# Essentially ``?1 ?2 ?3`` instead of ``? ? ?``
Expand Down
7 changes: 6 additions & 1 deletion test/ecto/integration/crud_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@ defmodule Ecto.Integration.CrudTest do
end

test "insert_all" do
TestRepo.insert!(%User{name: "John"}, [])
timestamp = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
# doing this a weird way to test multiple query parameters
name_query =
from(u in User, where: u.name == ^"John" and ^true, select: u.name)

account = %{
name: "John",
name: name_query,
inserted_at: timestamp,
updated_at: timestamp
}

{1, nil} = TestRepo.insert_all(Account, [account], [])
%{name: "John"} = TestRepo.one(Account)
end
end

Expand Down

0 comments on commit 00ceb86

Please sign in to comment.