Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Sep 17, 2024
1 parent 97cb1ac commit ec052eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 53 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ end

# prevent loading further extensions
:ok = Exqlite.enable_load_extension(db, false)
{:error, %Exqlite.Error{message: "not authorized"}} = exec.(db, "select load_extension(?)", [ExSqlean.path_for("re")])

{:error, %Exqlite.Error{message: "not authorized"}} =
exec.(db, "select load_extension(?)", [ExSqlean.path_for("stats")])

# close connection
Exqlite.close(db)
Expand All @@ -211,7 +213,7 @@ that would be resiliant to power outages and still maintain some state that

## Under The Hood

We are using the Dirty NIF scheduler to execute the sqlite calls. The rationale
We are using the Dirty NIF scheduler to execute most of the sqlite calls. The rationale
behind this is that maintaining each sqlite's connection command pool is
complicated and error prone.

Expand Down
83 changes: 32 additions & 51 deletions test/exqlite/pragma_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,73 +23,54 @@ defmodule Exqlite.PragmaTest do
test "journal_mode", %{db: db} do
assert [_default = "delete"] = one(db, "pragma journal_mode")

for journal_mode <- ["wal", "memory", "off", "delete", "truncate", "persist"] do
:ok = Exqlite.execute(db, "pragma journal_mode=#{journal_mode}")
assert [^journal_mode] = one(db, "pragma journal_mode")
for mode <- ["wal", "memory", "off", "delete", "truncate", "persist"] do
:ok = Exqlite.execute(db, "pragma journal_mode=#{mode}")
assert [^mode] = one(db, "pragma journal_mode")
end
end

test "temp_store", %{db: db} do
assert [_default = 0] = one(db, "pragma temp_store")

for {temp_store, code} <- [{"memory", 2}, {"default", 0}, {"file", 1}] do
:ok = Exqlite.execute(db, "pragma temp_store=#{temp_store}")
for {name, code} <- [{"memory", 2}, {"default", 0}, {"file", 1}] do
:ok = Exqlite.execute(db, "pragma temp_store=#{name}")
assert [^code] = one(db, "pragma temp_store")
end
end

# test ".synchronous/1" do
# assert Pragma.synchronous(synchronous: :extra) == 3
# assert Pragma.synchronous(synchronous: :full) == 2
# assert Pragma.synchronous(synchronous: :normal) == 1
# assert Pragma.synchronous(synchronous: :off) == 0
# assert Pragma.synchronous([]) == 1
# assert Pragma.synchronous(nil) == 1
test "synchronous", %{db: db} do
assert [_full = 2] = one(db, "pragma synchronous")

# assert_raise(
# ArgumentError,
# "invalid :synchronous",
# fn ->
# Pragma.synchronous(synchronous: :invalid)
# end
# )
# end
for {name, code} <- [{"extra", 3}, {"off", 0}, {"full", 2}, {"normal", 1}] do
:ok = Exqlite.execute(db, "pragma synchronous=#{name}")
assert [^code] = one(db, "pragma synchronous")
end
end

# test ".foreign_keys/1" do
# assert Pragma.foreign_keys(foreign_keys: :on) == 1
# assert Pragma.foreign_keys(foreign_keys: :off) == 0
# assert Pragma.foreign_keys([]) == 1
# assert Pragma.foreign_keys(nil) == 1
test "foreign_keys", %{db: db} do
assert [_off = 0] = one(db, "pragma foreign_keys")

# assert_raise(
# ArgumentError,
# "invalid :foreign_keys",
# fn ->
# Pragma.foreign_keys(foreign_keys: :invalid)
# end
# )
# end
for {name, code} <- [{"on", 1}, {"off", 0}] do
:ok = Exqlite.execute(db, "pragma foreign_keys=#{name}")
assert [^code] = one(db, "pragma foreign_keys")
end
end

# test ".cache_size/1" do
# assert Pragma.cache_size(cache_size: -64_000) == -64_000
# assert Pragma.cache_size([]) == -2_000
# assert Pragma.cache_size(nil) == -2_000
# end
test "cache_size", %{db: db} do
assert [_default = -2000] = one(db, "pragma cache_size")
:ok = Exqlite.execute(db, "pragma cache_size=-64000")
assert [-64000] = one(db, "pragma cache_size")

Check warning on line 62 in test/exqlite/pragma_test.exs

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 1.17, 27)

Numbers larger than 9999 should be written with underscores: 64_000
end

# test ".cache_spill/1" do
# assert Pragma.cache_spill(cache_spill: :on) == 1
# assert Pragma.cache_spill(cache_spill: :off) == 0
# assert Pragma.cache_spill([]) == 1
# assert Pragma.cache_spill(nil) == 1
test "cache_spill", %{db: db} do
assert [_pages = 483] = one(db, "pragma cache_spill")

# assert_raise(
# ArgumentError,
# "invalid :cache_spill",
# fn ->
# Pragma.cache_spill(cache_spill: :invalid)
# end
# )
# end
:ok = Exqlite.execute(db, "pragma cache_spill=off")
assert [0] = one(db, "pragma cache_spill")

:ok = Exqlite.execute(db, "pragma cache_spill=on")
assert [483] = one(db, "pragma cache_spill")
end

# test ".case_sensitive_like/1" do
# assert Pragma.case_sensitive_like(case_sensitive_like: :on) == 1
Expand Down

0 comments on commit ec052eb

Please sign in to comment.