Skip to content

Allow subquery values in insert_all #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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