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

Commit 4fc7364

Browse files
mmmriesConnorRigby
authored andcommitted
add some documentation
1 parent 7f3b4d7 commit 4fc7364

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

lib/sqlitex.ex

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ defmodule Sqlitex do
7272
7373
* `action` -> `:insert | :update | :delete`
7474
* `table` -> charlist of the table name. Example: `'posts'`
75-
* `rowid` -> internal immutable rowid index of the row.
75+
* `rowid` -> internal immutable rowid index of the row.
7676
This is *NOT* the `id` or `primary key` of the row.
7777
See the [official docs](https://www.sqlite.org/c3ref/update_hook.html).
7878
"""
@@ -82,17 +82,38 @@ defmodule Sqlitex do
8282
:esqlite3.set_update_hook(pid, db, timeout)
8383
end
8484

85+
@doc """
86+
Send a raw SQL statement to the database
87+
88+
This function is intended for running fully-complete SQL statements.
89+
No query preparation, or binding of values takes place.
90+
This is generally useful for things like re-playing a SQL export back into the database.
91+
"""
8592
@spec exec(connection, string_or_charlist) :: :ok | sqlite_error
8693
@spec exec(connection, string_or_charlist, Keyword.t) :: :ok | sqlite_error
8794
def exec(db, sql, opts \\ []) do
8895
timeout = Keyword.get(opts, :db_timeout, Config.db_timeout())
8996
:esqlite3.exec(sql, db, timeout)
9097
end
9198

99+
@doc "A shortcut to `Sqlitex.Query.query/3`"
100+
@spec query(Sqlitex.connection, String.t | charlist) :: {:ok, [[]]} | {:error, term()}
101+
@spec query(Sqlitex.connection, String.t | charlist, [{atom, term}]) :: {:ok, [[]]} | {:error, term()}
92102
def query(db, sql, opts \\ []), do: Sqlitex.Query.query(db, sql, opts)
103+
104+
@doc "A shortcut to `Sqlitex.Query.query!/3`"
105+
@spec query!(Sqlitex.connection, String.t | charlist) :: [[]]
106+
@spec query!(Sqlitex.connection, String.t | charlist, [bind: [], into: Enum.t, db_timeout: integer()]) :: [Enum.t]
93107
def query!(db, sql, opts \\ []), do: Sqlitex.Query.query!(db, sql, opts)
94108

109+
@doc "A shortcut to `Sqlitex.Query.query_rows/3`"
110+
@spec query_rows(Sqlitex.connection, String.t | charlist) :: {:ok, %{}} | Sqlitex.sqlite_error
111+
@spec query_rows(Sqlitex.connection, String.t | charlist, [bind: [], db_timeout: integer()]) :: {:ok, %{}} | Sqlitex.sqlite_error
95112
def query_rows(db, sql, opts \\ []), do: Sqlitex.Query.query_rows(db, sql, opts)
113+
114+
@doc "A shortcut to `Sqlitex.Query.query_rows!/3`"
115+
@spec query_rows!(Sqlitex.connection, String.t | charlist) :: %{}
116+
@spec query_rows!(Sqlitex.connection, String.t | charlist, [bind: [], db_timeout: integer()]) :: %{}
96117
def query_rows!(db, sql, opts \\ []), do: Sqlitex.Query.query_rows!(db, sql, opts)
97118

98119
@doc """

lib/sqlitex/query.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
defmodule Sqlitex.Query do
2+
@moduledoc """
3+
Functions for running queries against a SQLite database.
4+
5+
These query functions handle details such as preparing a statement, binding values, etc.
6+
If you need to deal with these details on your own, please take a look at the `Sqlitex.Statement` module.
7+
"""
8+
29
alias Sqlitex.Statement
310

411
@doc """
@@ -19,7 +26,7 @@ defmodule Sqlitex.Query do
1926
to `Application.get_env(:sqlitex, :db_timeout)` or `5000` ms if not configured.
2027
2128
## Returns
22-
* [results...] on success
29+
* {:ok, [results...]} on success
2330
* {:error, _} on failure.
2431
"""
2532

lib/sqlitex/row.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
defmodule Sqlitex.Row do
2+
@moduledoc false
3+
24
def from(types, columns, rows, into) do
35
for row <- rows do
46
build_row(types, columns, row, into)

mix.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ defmodule Sqlitex.Mixfile do
2020
description: """
2121
A thin Elixir wrapper around esqlite
2222
""",
23-
dialyzer: [plt_add_deps: :transitive]
24-
]
23+
dialyzer: [plt_add_deps: :transitive],
24+
docs: [main: "readme", # The main page in the docs
25+
extras: ["README.md"]]]
2526
end
2627

2728
# Configuration for the OTP application

0 commit comments

Comments
 (0)