Skip to content

Commit 24fc077

Browse files
committed
Allow JSON arrays
1 parent 69aa108 commit 24fc077

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

lib/sqlite_db_connection/protocol.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ defmodule Sqlite.DbConnection.Protocol do
165165
num_rows: num_rows,
166166
columns: atoms_to_strings(column_names),
167167
command: command}}
168+
{:error, :wrong_type} -> {:error, %ArgumentError{message: "Wrong type"}, s}
168169
{:error, {_sqlite_errcode, _message}} = err ->
169170
sqlite_error(err, s)
170171
{:error, %Sqlite.DbConnection.Error{} = err} ->
@@ -218,8 +219,8 @@ defmodule Sqlite.DbConnection.Protocol do
218219
catch
219220
:exit, {:timeout, _gen_server_call} ->
220221
{:error, %Sqlite.DbConnection.Error{message: "Timeout"}}
221-
:exit, _ex ->
222-
{:error, %Sqlite.DbConnection.Error{message: "Disconnected"}}
222+
:exit, ex ->
223+
{:error, %Sqlite.DbConnection.Error{message: inspect(ex)}}
223224
end
224225
end
225226
end

lib/sqlite_ecto/connection.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ if Code.ensure_loaded?(Sqlitex.Server) do
6666
value
6767
%{} = value ->
6868
Ecto.Adapter.json_library().encode!(value)
69+
value when is_list(value) ->
70+
Ecto.Adapter.json_library().encode!(value)
6971
value ->
7072
value
7173
end
@@ -496,7 +498,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do
496498
[@pseudo_returning_statement, cmd, ?\s, fields]
497499
end
498500

499-
defp ecto_to_db({:array, _}) do
501+
defp ecto_to_db({:array, _data}) do
500502
raise ArgumentError, "Array type is not supported by SQLite"
501503
end
502504

@@ -772,7 +774,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do
772774
defp column_type(:string, _opts), do: "TEXT"
773775
defp column_type(:map, _opts), do: "TEXT"
774776
defp column_type({:map, _}, _opts), do: "TEXT"
775-
defp column_type({:array, _}, _opts), do: raise(ArgumentError, "Array type is not supported by SQLite")
777+
defp column_type({:array, _}, _opts), do: "TEXT"
776778
defp column_type(:decimal, opts) do
777779
# We only store precision and scale for DECIMAL.
778780
precision = Keyword.get(opts, :precision)

test/sqlite_ecto_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,9 @@ defmodule Sqlite.Ecto2.Test do
864864
create = {:create, table(:posts),
865865
[{:add, :name, {:array, :numeric}, []}]}
866866

867-
assert_raise ArgumentError, ~r"Array type is not supported by SQLite", fn ->
868-
execute_ddl(create)
869-
end
867+
assert execute_ddl(create) == ["""
868+
CREATE TABLE "posts" ("name" TEXT)
869+
""" |> remove_newlines()]
870870
end
871871

872872
test "create table illegal options" do

0 commit comments

Comments
 (0)