Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit e4e37ac

Browse files
committed
require esqlite ~>0.2.4 which fixes typespecs
also change to pass strings to Decimal.new/1 as per the typespec of that function
1 parent f14ad12 commit e4e37ac

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

lib/sqlitex/row.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ defmodule Sqlitex.Row do
5555
defp translate_value({float, "decimal(" <> rest}) do
5656
[precision, scale] = rest |> string_rstrip(?)) |> String.split(",") |> Enum.map(&String.to_integer/1)
5757
Decimal.with_context %Decimal.Context{precision: precision, rounding: :down}, fn ->
58-
float |> Float.round(scale) |> Decimal.new |> Decimal.plus
58+
float |> Float.round(scale) |> Float.to_string |> Decimal.new |> Decimal.plus
5959
end
6060
end
6161

mix.exs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ defmodule Sqlitex.Mixfile do
22
use Mix.Project
33

44
def project do
5-
[app: :sqlitex,
6-
version: "1.4.0",
7-
elixir: "~> 1.2",
8-
deps: deps(),
9-
package: package(),
10-
test_coverage: [tool: ExCoveralls],
11-
preferred_cli_env: [
12-
"coveralls": :test,
13-
"coveralls.detail": :test,
14-
"coveralls.post": :test,
15-
"coveralls.html": :test],
16-
description: """
17-
A thin Elixir wrapper around esqlite
18-
"""]
5+
[
6+
app: :sqlitex,
7+
version: "1.4.0",
8+
elixir: "~> 1.2",
9+
deps: deps(),
10+
package: package(),
11+
test_coverage: [tool: ExCoveralls],
12+
preferred_cli_env: [
13+
"coveralls": :test,
14+
"coveralls.detail": :test,
15+
"coveralls.post": :test,
16+
"coveralls.html": :test],
17+
description: """
18+
A thin Elixir wrapper around esqlite
19+
""",
20+
dialyzer: [plt_add_deps: :transitive],
21+
]
1922
end
2023

2124
# Configuration for the OTP application
@@ -26,7 +29,7 @@ defmodule Sqlitex.Mixfile do
2629
# Type `mix help deps` for more examples and options
2730
defp deps do
2831
[
29-
{:esqlite, "~> 0.2.3"},
32+
{:esqlite, "~> 0.2.4"},
3033
{:decimal, "~> 1.1"},
3134

3235
{:credo, "~> 0.4", only: :dev},

test/sqlitex_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ defmodule SqlitexTest do
193193
test "decimal types" do
194194
{:ok, db} = Sqlitex.open(":memory:")
195195
:ok = Sqlitex.exec(db, "CREATE TABLE t (f DECIMAL)")
196-
d = Decimal.new(1.123)
196+
d = Decimal.new("1.123")
197197
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?)", bind: [d])
198198
{:ok, [row]} = Sqlitex.query(db, "SELECT f FROM t")
199199
assert row[:f] == d
@@ -202,14 +202,14 @@ defmodule SqlitexTest do
202202
test "decimal types with scale and precision" do
203203
{:ok, db} = Sqlitex.open(":memory:")
204204
:ok = Sqlitex.exec(db, "CREATE TABLE t (id INTEGER, f DECIMAL(3,2))")
205-
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?,?)", bind: [1, Decimal.new(1.123)])
206-
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?,?)", bind: [2, Decimal.new(244.37)])
207-
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?,?)", bind: [3, Decimal.new(1997)])
205+
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?,?)", bind: [1, Decimal.new("1.123")])
206+
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?,?)", bind: [2, Decimal.new("244.37")])
207+
{:ok, []} = Sqlitex.query(db, "INSERT INTO t VALUES (?,?)", bind: [3, Decimal.new("1997")])
208208

209209
# results should be truncated to the appropriate precision and scale:
210210
Sqlitex.query!(db, "SELECT f FROM t ORDER BY id")
211211
|> Enum.map(fn row -> row[:f] end)
212-
|> Enum.zip([Decimal.new(1.12), Decimal.new(244), Decimal.new(1990)])
212+
|> Enum.zip([Decimal.new("1.12"), Decimal.new(244), Decimal.new(1990)])
213213
|> Enum.each(fn {res, ans} -> assert Decimal.equal?(res, ans) end)
214214
end
215215

0 commit comments

Comments
 (0)