Skip to content

Commit 4931a54

Browse files
committed
Make open readonly with nomutex by default.
1 parent 643e27c commit 4931a54

File tree

3 files changed

+5
-31
lines changed

3 files changed

+5
-31
lines changed

lib/exqlite/connection.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ defmodule Exqlite.Connection do
5858

5959
@type connection_opt() ::
6060
{:database, String.t()}
61-
| {:mode, :readwrite | :readonly | :readonly_nomutex}
61+
| {:mode, :readwrite | :readonly}
6262
| {:journal_mode, journal_mode()}
6363
| {:temp_store, temp_store()}
6464
| {:synchronous, synchronous()}
@@ -92,8 +92,7 @@ defmodule Exqlite.Connection do
9292
* `:database` - The path to the database. In memory is allowed. You can use
9393
`:memory` or `":memory:"` to designate that.
9494
* `:mode` - use `:readwrite` to open the database for reading and writing
95-
, `:readonly` to open it in read-only mode or `:readonly_nomutex` to open
96-
it in read-only with nomutex mode. `:readwrite` will also create
95+
or `:readonly` to open it in read-only mode. `:readwrite` will also create
9796
the database if it doesn't already exist. Defaults to `:readwrite`.
9897
* `:journal_mode` - Sets the journal mode for the sqlite connection. Can be
9998
one of the following `:delete`, `:truncate`, `:persist`, `:memory`,

lib/exqlite/sqlite3.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule Exqlite.Sqlite3 do
1919
@type statement() :: reference()
2020
@type reason() :: atom() | String.t()
2121
@type row() :: list()
22-
@type open_opt :: {:mode, :readwrite | :readonly | :readonly_nomutex}
22+
@type open_opt :: {:mode, :readwrite | :readonly}
2323

2424
@doc """
2525
Opens a new sqlite database at the Path provided.
@@ -29,7 +29,7 @@ defmodule Exqlite.Sqlite3 do
2929
## Options
3030
3131
* `:mode` - use `:readwrite` to open the database for reading and writing
32-
, `:readonly` to open it in read-only mode or `:readonly_nomutex` to open it in read-only with nomutex mode. `:readwrite` will also create
32+
or `:readonly` to open it in read-only mode. `:readwrite` will also create
3333
the database if it doesn't already exist. Defaults to `:readwrite`.
3434
"""
3535
@spec open(String.t(), [open_opt()]) :: {:ok, db()} | {:error, reason()}
@@ -42,7 +42,7 @@ defmodule Exqlite.Sqlite3 do
4242
do: Flags.put_file_open_flags([:sqlite_open_readwrite, :sqlite_open_create])
4343

4444
defp flags_from_mode(:readonly),
45-
do: Flags.put_file_open_flags([:sqlite_open_readonly])
45+
do: Flags.put_file_open_flags([:sqlite_open_readonly, :sqlite_open_nomutex])
4646

4747
defp flags_from_mode(:readonly_nomutex),
4848
do: Flags.put_file_open_flags([:sqlite_open_readonly, :sqlite_open_nomutex])

test/exqlite/sqlite3_test.exs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,6 @@ defmodule Exqlite.Sqlite3Test do
5353
Sqlite3.execute(ro_conn, insert_value_query)
5454
end
5555

56-
test "opens a database in readonly_nomutex mode" do
57-
# Create database with readwrite connection
58-
{:ok, path} = Temp.path()
59-
{:ok, rw_conn} = Sqlite3.open(path)
60-
61-
create_table_query = "create table test (id integer primary key, stuff text)"
62-
:ok = Sqlite3.execute(rw_conn, create_table_query)
63-
64-
insert_value_query = "insert into test (stuff) values ('This is a test')"
65-
:ok = Sqlite3.execute(rw_conn, insert_value_query)
66-
67-
# Read from database with a readonly_nomutex connection
68-
{:ok, ro_conn} = Sqlite3.open(path, mode: :readonly_nomutex)
69-
70-
select_query = "select id, stuff from test order by id asc"
71-
{:ok, statement} = Sqlite3.prepare(ro_conn, select_query)
72-
{:row, columns} = Sqlite3.step(ro_conn, statement)
73-
74-
assert [1, "This is a test"] == columns
75-
76-
# Readonly nomutex connection cannot insert
77-
assert {:error, "attempt to write a readonly database"} ==
78-
Sqlite3.execute(ro_conn, insert_value_query)
79-
end
80-
8156
test "opens a database with invalid mode" do
8257
{:ok, path} = Temp.path()
8358

0 commit comments

Comments
 (0)