Skip to content

Array json #221

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 2 commits into from
Oct 18, 2018
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog for v2.2.x Series
## v2.3.0

_17 October 2018_

* Allow {:array, :map} via JSON library.
* Update error messages for clarity.

## v2.2.3

Expand Down
5 changes: 3 additions & 2 deletions lib/sqlite_db_connection/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ defmodule Sqlite.DbConnection.Protocol do
num_rows: num_rows,
columns: atoms_to_strings(column_names),
command: command}}
{:error, :wrong_type} -> {:error, %ArgumentError{message: "Wrong type"}, s}
{:error, {_sqlite_errcode, _message}} = err ->
sqlite_error(err, s)
{:error, %Sqlite.DbConnection.Error{} = err} ->
Expand Down Expand Up @@ -218,8 +219,8 @@ defmodule Sqlite.DbConnection.Protocol do
catch
:exit, {:timeout, _gen_server_call} ->
{:error, %Sqlite.DbConnection.Error{message: "Timeout"}}
:exit, _ex ->
{:error, %Sqlite.DbConnection.Error{message: "Disconnected"}}
:exit, ex ->
{:error, %Sqlite.DbConnection.Error{message: inspect(ex)}}
end
end
end
6 changes: 4 additions & 2 deletions lib/sqlite_ecto/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ if Code.ensure_loaded?(Sqlitex.Server) do
value
%{} = value ->
Ecto.Adapter.json_library().encode!(value)
value when is_list(value) ->
Ecto.Adapter.json_library().encode!(value)
value ->
value
end
Expand Down Expand Up @@ -496,7 +498,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do
[@pseudo_returning_statement, cmd, ?\s, fields]
end

defp ecto_to_db({:array, _}) do
defp ecto_to_db({:array, _data}) do
raise ArgumentError, "Array type is not supported by SQLite"
end

Expand Down Expand Up @@ -772,7 +774,7 @@ if Code.ensure_loaded?(Sqlitex.Server) do
defp column_type(:string, _opts), do: "TEXT"
defp column_type(:map, _opts), do: "TEXT"
defp column_type({:map, _}, _opts), do: "TEXT"
defp column_type({:array, _}, _opts), do: raise(ArgumentError, "Array type is not supported by SQLite")
defp column_type({:array, _}, _opts), do: "TEXT"
defp column_type(:decimal, opts) do
# We only store precision and scale for DECIMAL.
precision = Keyword.get(opts, :precision)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Sqlite.Ecto2.Mixfile do

def project do
[app: :sqlite_ecto2,
version: "2.2.5",
version: "2.3.0",
name: "Sqlite.Ecto2",
elixir: "~> 1.4",
deps: deps(),
Expand Down
6 changes: 3 additions & 3 deletions test/sqlite_ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,9 @@ defmodule Sqlite.Ecto2.Test do
create = {:create, table(:posts),
[{:add, :name, {:array, :numeric}, []}]}

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

test "create table illegal options" do
Expand Down