Skip to content

Commit 427c1da

Browse files
committed
Adds credo and adds a check to the workflow
1 parent d50b6af commit 427c1da

File tree

13 files changed

+41
-53
lines changed

13 files changed

+41
-53
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
- run: mix deps.compile
3232
- run: mix format --check-formatted
3333
- run: mix deps.unlock --check-unused
34+
- run: mix credo --all
3435

3536
test:
3637
runs-on: ${{ matrix.os }}

lib/exqlite.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
defmodule Exqlite do
2+
@moduledoc false
23
end

lib/exqlite/basic.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ defmodule Exqlite.Basic do
1313
Connection.connect(database: path)
1414
end
1515

16-
def close(conn = %Connection{}) do
17-
with :ok <- Sqlite3.close(conn.db) do
18-
:ok
19-
else
16+
def close(%Connection{} = conn) do
17+
case Sqlite3.close(conn.db) do
18+
:ok -> :ok
2019
{:error, reason} -> {:error, %Error{message: reason}}
2120
end
2221
end
2322

24-
def exec(conn = %Connection{}, stmt, args \\ []) do
23+
def exec(%Connection{} = conn, stmt, args \\ []) do
2524
%Query{statement: stmt} |> Connection.handle_execute(args, [], conn)
2625
end
2726

lib/exqlite/connection.ex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ defmodule Exqlite.Connection do
127127

128128
@impl true
129129
def disconnect(_err, %__MODULE__{db: db}) do
130-
with :ok <- Sqlite3.close(db) do
131-
:ok
132-
else
130+
case Sqlite3.close(db) do
131+
:ok -> :ok
133132
{:error, reason} -> {:error, %Error{message: reason}}
134133
end
135134
end
@@ -173,7 +172,7 @@ defmodule Exqlite.Connection do
173172
"""
174173
@impl true
175174
def handle_begin(options, %{transaction_status: transaction_status} = state) do
176-
# TODO: This doesn't handle more than 2 levels of transactions.
175+
# This doesn't handle more than 2 levels of transactions.
177176
#
178177
# One possible solution would be to just track the number of open
179178
# transactions and use that for driving the transaction status being idle or

lib/exqlite/query.ex

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,6 @@ defmodule Exqlite.Query do
5353
query
5454
end
5555

56-
# TODO: See also Connection.bind/3
57-
#
58-
# def encode(%{ref: nil} = query, _params, _opts) do
59-
# raise ArgumentError, "query #{inspect(query)} has not been prepared"
60-
# end
61-
#
62-
# def encode(%{num_params: nil} = query, _params, _opts) do
63-
# raise ArgumentError, "query #{inspect(query)} has not been prepared"
64-
# end
65-
#
66-
# def encode(%{num_params: num_params} = query, params, _opts)
67-
# when num_params != length(params) do
68-
# message =
69-
# "expected params count: #{inspect(num_params)}, got values: #{inspect(params)}" <>
70-
# " for query: #{inspect(query)}"
71-
#
72-
# raise ArgumentError, message
73-
# end
74-
7556
def encode(_query, params, _opts) do
7657
params
7758
end

lib/exqlite/result.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
defmodule Exqlite.Result do
2+
@moduledoc false
3+
24
@type t :: %__MODULE__{
35
command: atom,
46
columns: [String.t()] | nil,

lib/exqlite/sqlite3.ex

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ defmodule Exqlite.Sqlite3 do
33
The interface to the NIF implementation.
44
"""
55

6+
# If the database reference is closed, any prepared statements should be
7+
# dereferenced as well. It is entirely possible that an application does
8+
# not properly remove a stale reference.
69
#
7-
# TODO: If the database reference is closed, any prepared statements should be
8-
# dereferenced as well. It is entirely possible that an application does
9-
# not properly remove a stale reference.
10-
#
11-
# Will need to add a test for this and think of possible solution.
12-
#
10+
# Will need to add a test for this and think of possible solution.
1311

14-
# TODO: Need to figure out if we can just stream results where we use this
15-
# module as a sink.
12+
# Need to figure out if we can just stream results where we use this
13+
# module as a sink.
1614

1715
alias Exqlite.Sqlite3NIF
1816

@@ -125,8 +123,8 @@ defmodule Exqlite.Sqlite3 do
125123

126124
@spec fetch_all(db(), statement()) :: {:ok, [row()]} | {:error, reason()}
127125
def fetch_all(conn, statement) do
128-
# TODO: Should this be done in the NIF? It can be _much_ faster to build a
129-
# list there, but at the expense that it could block other dirty nifs from
126+
# Should this be done in the NIF? It can be _much_ faster to build a list
127+
# there, but at the expense that it could block other dirty nifs from
130128
# getting work done.
131129
#
132130
# For now this just works
@@ -159,7 +157,8 @@ defmodule Exqlite.Sqlite3 do
159157
end
160158

161159
@doc """
162-
Disconnect from database and then reopen as an in-memory database based on the serialized binary.
160+
Disconnect from database and then reopen as an in-memory database based on
161+
the serialized binary.
163162
"""
164163
@spec deserialize(db(), String.t(), binary()) :: :ok | {:error, reason()}
165164
def deserialize(conn, database \\ "main", serialized) do

lib/exqlite/sqlite3_nif.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ defmodule Exqlite.Sqlite3NIF do
6464
@spec enable_load_extension(db(), integer()) :: :ok | {:error, reason()}
6565
def enable_load_extension(_conn, _flag), do: :erlang.nif_error(:not_loaded)
6666

67-
# TODO: add statement inspection tooling https://sqlite.org/c3ref/expanded_sql.html
67+
# add statement inspection tooling https://sqlite.org/c3ref/expanded_sql.html
6868
end

lib/exqlite/stream.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Exqlite.Stream do
55

66
defimpl Enumerable do
77
def reduce(%Exqlite.Stream{query: %Exqlite.Query{} = query} = stream, acc, fun) do
8-
# TODO: Possibly need to pass a chunk size option along so that we can let
8+
# Possibly need to pass a chunk size option along so that we can let
99
# the NIF chunk it.
1010
%Exqlite.Stream{conn: conn, params: params, options: opts} = stream
1111

mix.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ defmodule Exqlite.MixProject do
4040
{:ex_sqlean, "~> 0.8.5", only: [:dev, :test]},
4141
{:elixir_make, "~> 0.6", runtime: false},
4242
{:ex_doc, "~> 0.27", only: :dev, runtime: false},
43-
{:temp, "~> 0.4", only: [:dev, :test]}
43+
{:temp, "~> 0.4", only: [:dev, :test]},
44+
{:credo, "~> 1.6", only: [:dev, :test], runtime: false}
4445
]
4546
end
4647

@@ -63,7 +64,8 @@ defmodule Exqlite.MixProject do
6364
name: "exqlite",
6465
licenses: ["MIT"],
6566
links: %{
66-
"GitHub" => "https://github.com/elixir-sqlite/exqlite"
67+
"GitHub" => "https://github.com/elixir-sqlite/exqlite",
68+
"Changelog" => "https://github.com/elixir-sqlite/exqlite/blob/main/CHANGELOG.md"
6769
}
6870
]
6971
end

0 commit comments

Comments
 (0)