Skip to content

Commit 0d42d0a

Browse files
authored
Fix bug in loading json arrays (#222)
1 parent 323c2dd commit 0d42d0a

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# Changelog for v2.2.x Series
2+
## v2.3.1
3+
4+
__23 October 2018_
5+
6+
* Fix bug in array loading.
7+
28
## v2.3.0
39

410
_17 October 2018_

lib/sqlite_ecto.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ defmodule Sqlite.Ecto2 do
5151
do: [&json_decode/1, &Ecto.Adapters.SQL.load_embed(type, &1)]
5252
def loaders(:map, type), do: [&json_decode/1, type]
5353
def loaders({:map, _}, type), do: [&json_decode/1, type]
54+
def loaders({:array, _}, type), do: [&json_decode/1, type]
5455
def loaders(:float, type), do: [&float_decode/1, type]
5556
def loaders(_primitive, type), do: [type]
5657

lib/sqlite_ecto/connection.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,8 @@ if Code.ensure_loaded?(Sqlitex.Server) do
773773
defp column_type(:bigserial, _opts), do: "INTEGER"
774774
defp column_type(:string, _opts), do: "TEXT"
775775
defp column_type(:map, _opts), do: "TEXT"
776-
defp column_type({:map, _}, _opts), do: "TEXT"
777-
defp column_type({:array, _}, _opts), do: "TEXT"
776+
defp column_type({:map, _}, _opts), do: "JSON"
777+
defp column_type({:array, _}, _opts), do: "JSON"
778778
defp column_type(:decimal, opts) do
779779
# We only store precision and scale for DECIMAL.
780780
precision = Keyword.get(opts, :precision)

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule Sqlite.Ecto2.Mixfile do
33

44
def project do
55
[app: :sqlite_ecto2,
6-
version: "2.3.0",
6+
version: "2.3.1",
77
name: "Sqlite.Ecto2",
88
elixir: "~> 1.4",
99
deps: deps(),

test/sqlite_ecto_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ defmodule Sqlite.Ecto2.Test do
865865
[{:add, :name, {:array, :numeric}, []}]}
866866

867867
assert execute_ddl(create) == ["""
868-
CREATE TABLE "posts" ("name" TEXT)
868+
CREATE TABLE "posts" ("name" JSON)
869869
""" |> remove_newlines()]
870870
end
871871

0 commit comments

Comments
 (0)