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

Commit b0471de

Browse files
Jeremy NealConnorRigby
Jeremy Neal
authored andcommitted
Consistent SQLite spelling, grammar fixes, line breaks.
1 parent 025f281 commit b0471de

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
# Sqlitex
77

8-
An Elixir wrapper around [esqlite](https://github.com/mmzeeman/esqlite). The main aim here is to provide convenient usage of sqlite databases.
8+
An Elixir wrapper around [esqlite](https://github.com/mmzeeman/esqlite). The main aim here is to provide convenient usage of SQLite databases.
99

1010
# Updated to 1.0
1111

12-
With the 1.0 release we made just a single breaking change. `Sqlitex.Query.query` previously returned just the raw query results on success and `{:error, reason}` on failure.
13-
This has been bothering us for a while so we changed it in 1.0 to return `{:ok, results}` on success and `{:error, reason}` on failure.
12+
With the 1.0 release, we made just a single breaking change. `Sqlitex.Query.query` previously returned just the raw query results on success and `{:error, reason}` on failure.
13+
This has been bothering us for a while, so we changed it in 1.0 to return `{:ok, results}` on success and `{:error, reason}` on failure.
1414
This should make it easier to pattern match on. The `Sqlitex.Query.query!` function has kept its same functionality of returning bare results on success and raising an error on failure.
1515

1616
# Usage
1717

18-
The simple way to use sqlitex is just to open a database and run a query
18+
The simple way to use `sqlitex` is just to open a database and run a query:
1919

2020
```elixir
2121
Sqlitex.with_db('test/fixtures/golfscores.sqlite3', fn(db) ->
@@ -36,21 +36,21 @@ Sqlitex.with_db('test/fixtures/golfscores.sqlite3', fn(db) ->
3636
Sqlitex.query(
3737
db,
3838
"INSERT INTO players (name, created_at, updated_at) VALUES (?1, ?2, ?3, ?4)",
39-
bind: ['Mikey', '2012-10-14 05:46:28.318107', '2013-09-06 22:29:36.610911'])
39+
bind: ['Mikey', '2012-10-14 05:46:28.318107', '2013-09-06 22:29:36.610911']
40+
)
4041
end)
4142
# => [[id: 1, name: "Mikey", created_at: {{2012,10,14},{05,46,28}}, updated_at: {{2013,09,06},{22,29,36}}, type: nil]]
42-
4343
```
4444

45-
If you want to keep the database open during the lifetime of your project you can use the `Sqlitex.Server` GenServer module.
45+
If you want to keep the database open during the lifetime of your project, you can use the `Sqlitex.Server` GenServer module.
4646
Here's a sample from a phoenix projects main supervisor definition.
47+
4748
```elixir
4849
children = [
49-
# Start the endpoint when the application starts
50-
worker(Golf.Endpoint, []),
51-
52-
worker(Sqlitex.Server, ['golf.sqlite3', [name: Golf.DB]])
53-
]
50+
# Start the endpoint when the application starts
51+
worker(Golf.Endpoint, []),
52+
worker(Sqlitex.Server, ['golf.sqlite3', [name: Golf.DB]])
53+
]
5454
```
5555

5656
Now that the GenServer is running you can make queries via
@@ -63,4 +63,4 @@ Sqlitex.Server.query(Golf.DB,
6363
```
6464

6565
# Looking for Ecto?
66-
Check out the [Sqlite Ecto2 adapter](https://github.com/Sqlite-Ecto/sqlite_ecto2)
66+
Check out the [SQLite Ecto2 adapter](https://github.com/Sqlite-Ecto/sqlite_ecto2)

lib/sqlitex.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule Sqlitex do
88
@type sqlite_error :: {:error, {:sqlite_error, charlist}}
99

1010
@moduledoc """
11-
Sqlitex gives you a way to create and query sqlite databases.
11+
Sqlitex gives you a way to create and query SQLite databases.
1212
1313
## Basic Example
1414
@@ -30,7 +30,7 @@ defmodule Sqlitex do
3030
Sqlitex uses the Erlang library [esqlite](https://github.com/mmzeeman/esqlite)
3131
which accepts a timeout parameter for almost all interactions with the database.
3232
The default value for this timeout is 5000 ms. Many functions in Sqlitex accept
33-
a `:db_timeout` option that is passed on to the esqlite calls and that also defaults
33+
a `:db_timeout` option that is passed on to the esqlite calls and also defaults
3434
to 5000 ms. If required, this default value can be overridden globally with the
3535
following in your `config.exs`:
3636
@@ -78,8 +78,8 @@ defmodule Sqlitex do
7878
def query_rows!(db, sql, opts \\ []), do: Sqlitex.Query.query_rows!(db, sql, opts)
7979

8080
@doc """
81-
Create a new table `name` where `table_opts` are a list of table constraints
82-
and `cols` are a keyword list of columns. The following table constraints are
81+
Create a new table `name` where `table_opts` is a list of table constraints
82+
and `cols` is a keyword list of columns. The following table constraints are
8383
supported: `:temp` and `:primary_key`. Example:
8484
8585
**[:temp, {:primary_key, [:id]}]**

lib/sqlitex/query.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Sqlitex.Query do
66
77
## Parameters
88
9-
* `db` - A sqlite database.
9+
* `db` - A SQLite database.
1010
* `sql` - The query to run as a string.
1111
* `opts` - Options to pass into the query. See below for details.
1212
@@ -16,7 +16,7 @@ defmodule Sqlitex.Query do
1616
to bind as a list.
1717
* `into` - The collection to put results into. This defaults to a list.
1818
* `db_timeout` - The timeout (in ms) to apply to each of the underlying SQLite operations. Defaults
19-
to `Application.get_env(:sqlitex, :db_timeout)` or `5000`ms if not configured.
19+
to `Application.get_env(:sqlitex, :db_timeout)` or `5000` ms if not configured.
2020
2121
## Returns
2222
* [results...] on success
@@ -56,7 +56,7 @@ defmodule Sqlitex.Query do
5656
5757
## Parameters
5858
59-
* `db` - A sqlite database.
59+
* `db` - A SQLite database.
6060
* `sql` - The query to run as a string.
6161
* `opts` - Options to pass into the query. See below for details.
6262
@@ -65,7 +65,7 @@ defmodule Sqlitex.Query do
6565
* `bind` - If your query has parameters in it, you should provide the options
6666
to bind as a list.
6767
* `db_timeout` - The timeout (in ms) to apply to each of the underlying SQLite operations. Defaults
68-
to `Application.get_env(:sqlitex, :db_timeout)` or `5000`ms if not configured.
68+
to `Application.get_env(:sqlitex, :db_timeout)` or `5000` ms if not configured.
6969
7070
## Returns
7171
* {:ok, %{rows: [[1, 2], [2, 3]], columns: [:a, :b], types: [:INTEGER, :INTEGER]}} on success

lib/sqlitex/server.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Sqlitex.Server do
22
@moduledoc """
33
Sqlitex.Server provides a GenServer to wrap a sqlitedb.
4-
This makes it easy to share a sqlite database between multiple processes without worrying about concurrency issues.
4+
This makes it easy to share a SQLite database between multiple processes without worrying about concurrency issues.
55
You can also register the process with a name so you can query by name later.
66
77
## Unsupervised Example
@@ -142,10 +142,10 @@ defmodule Sqlitex.Server do
142142
cached in the Server process. If a subsequent call to `query/3` or `query_rows/3`
143143
is made with a matching SQL statement, the prepared statement is reused.
144144
145-
Prepared statements are purged from the cache when the cache exceeds a pre-set
145+
Prepared statements are purged from the cache when the cache exceeds a preset
146146
limit (20 statements by default).
147147
148-
Returns summary information about the prepared statement
148+
Returns summary information about the prepared statement.
149149
`{:ok, %{columns: [:column1_name, :column2_name,... ], types: [:column1_type, ...]}}`
150150
on success or `{:error, {:reason_code, 'SQLite message'}}` if the statement
151151
could not be prepared.

lib/sqlitex/server/statement_cache.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule Sqlitex.Server.StatementCache do
1919
Given a statement cache and an SQL statement (string), returns a tuple containing
2020
the updated statement cache and a prepared SQL statement.
2121
22-
If possible, reuses an existing prepared statement; if not, prepares the statement
22+
If possible, reuses an existing prepared statement. If not, prepares the statement
2323
and adds it to the cache, possibly removing the least-recently used prepared
2424
statement if the designated cache size limit would be exceeded.
2525
@@ -63,6 +63,7 @@ defmodule Sqlitex.Server.StatementCache do
6363
cached_stmts: Map.drop(cached_stmts, [purge_victim]),
6464
lru: lru}
6565
end
66+
6667
defp purge_cache_if_full(cache), do: cache
6768

6869
defp update_cache_for_read(%__MODULE__{lru: lru} = cache, sql) do

lib/sqlitex/statement.ex

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Sqlitex.Statement do
22
alias Sqlitex.Row
33
@moduledoc """
4-
Provides an interface for working with sqlite prepared statements.
4+
Provides an interface for working with SQLite prepared statements.
55
66
Care should be taken when using prepared statements directly - they are not
77
immutable objects like most things in Elixir. Sharing a statement between
@@ -115,7 +115,7 @@ defmodule Sqlitex.Statement do
115115
end
116116

117117
@doc """
118-
Binds values to a Sqlitex.Statement
118+
Binds values to a Sqlitex.Statement.
119119
120120
## Parameters
121121
@@ -226,7 +226,7 @@ defmodule Sqlitex.Statement do
226226
timeout = Keyword.get(opts, :db_timeout, Config.db_timeout())
227227

228228
case :esqlite3.step(statement.statement, timeout) do
229-
# esqlite3.step returns some odd values, so lets translate them:
229+
# esqlite3.step returns some odd values, so let's translate them:
230230
:"$done" -> :ok
231231
:"$busy" -> {:error, {:busy, "Sqlite database is busy"}}
232232
other -> other
@@ -323,14 +323,17 @@ defmodule Sqlitex.Statement do
323323
[table | cols] = String.split(values, ",")
324324
{table, cols, "INSERT", "NEW"}
325325
end
326+
326327
defp parse_return_contents(<<"UPDATE ", values::binary>>) do
327328
[table | cols] = String.split(values, ",")
328329
{table, cols, "UPDATE", "NEW"}
329330
end
331+
330332
defp parse_return_contents(<<"DELETE ", values::binary>>) do
331333
[table | cols] = String.split(values, ",")
332334
{table, cols, "DELETE", "OLD"}
333335
end
336+
334337
defp parse_return_contents(_) do
335338
{:error, :invalid_returning_clause}
336339
end

0 commit comments

Comments
 (0)