From 00ceb86b28689f70febe36783f80ee47012f23d2 Mon Sep 17 00:00:00 2001 From: Greg Rychlewski Date: Sun, 10 Dec 2023 09:57:40 -0500 Subject: [PATCH] allow subquery values in insert_all (#137) --- lib/ecto/adapters/sqlite3/connection.ex | 3 +++ test/ecto/integration/crud_test.exs | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ecto/adapters/sqlite3/connection.ex b/lib/ecto/adapters/sqlite3/connection.ex index 25da099..a991f5e 100644 --- a/lib/ecto/adapters/sqlite3/connection.ex +++ b/lib/ecto/adapters/sqlite3/connection.ex @@ -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 ``? ? ?`` diff --git a/test/ecto/integration/crud_test.exs b/test/ecto/integration/crud_test.exs index d6eb232..01ee1ec 100644 --- a/test/ecto/integration/crud_test.exs +++ b/test/ecto/integration/crud_test.exs @@ -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