Skip to content

Commit 95d4d8c

Browse files
author
Étienne Lévesque
authored
Fix/create table options list guard (#69)
* fix: Fix bad error when creating a table with option * test: Add test for succesful options usage
1 parent 69984fa commit 95d4d8c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/ecto/adapters/sqlite3/connection.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ defmodule Ecto.Adapters.SQLite3.Connection do
333333
##
334334

335335
@impl true
336-
def execute_ddl({_command, %Table{options: keyword}, _}) when keyword != nil do
336+
def execute_ddl({_command, %Table{options: options}, _}) when is_list(options) do
337337
raise ArgumentError, "SQLite3 adapter does not support keyword lists in :options"
338338
end
339339

@@ -1624,7 +1624,7 @@ defmodule Ecto.Adapters.SQLite3.Connection do
16241624

16251625
defp options_expr(nil), do: []
16261626

1627-
defp options_expr(keyword) when is_list(keyword) do
1627+
defp options_expr(options) when is_list(options) do
16281628
raise ArgumentError, "SQLite3 adapter does not support keyword lists in :options"
16291629
end
16301630

test/ecto/adapters/sqlite3/connection_test.exs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2233,11 +2233,28 @@ defmodule Ecto.Adapters.SQLite3.ConnectionTest do
22332233
end
22342234

22352235
test "create table with options" do
2236+
create =
2237+
{:create, table(:posts, options: "WITH FOO=BAR"),
2238+
[
2239+
{:add, :id, :serial, [primary_key: true]}
2240+
]}
2241+
2242+
assert execute_ddl(create) == [
2243+
"""
2244+
CREATE TABLE "posts" (\
2245+
"id" INTEGER PRIMARY KEY AUTOINCREMENT\
2246+
) \
2247+
WITH FOO=BAR\
2248+
"""
2249+
]
2250+
end
2251+
2252+
test "create table with list as options" do
22362253
assert_raise(
22372254
ArgumentError,
22382255
"SQLite3 adapter does not support keyword lists in :options",
22392256
fn ->
2240-
{:create, table(:posts, options: "WITH FOO=BAR"),
2257+
{:create, table(:posts, options: ["WITH FOO=BAR"]),
22412258
[{:add, :id, :serial, [primary_key: true]}, {:add, :created_at, :datetime, []}]}
22422259
|> execute_ddl()
22432260
end

0 commit comments

Comments
 (0)