Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop converting strings to_charlist #291

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/exqlite/sqlite3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ defmodule Exqlite.Sqlite3 do
the database if it doesn't already exist. Defaults to `:readwrite`.
Note: [:readwrite, :nomutex] is not recommended.
"""
@spec open(String.t() | String.Chars.t(), [open_opt()]) ::
{:ok, db()}
| {:error, reason()}
@spec open(String.t(), [open_opt()]) :: {:ok, db()} | {:error, reason()}
def open(path, opts \\ []) do
mode = Keyword.get(opts, :mode, :readwrite)
Sqlite3NIF.open(path, flags_from_mode(mode))
Expand Down Expand Up @@ -163,7 +161,7 @@ defmodule Exqlite.Sqlite3 do
"""
@spec shrink_memory(db()) :: :ok | {:error, reason()}
def shrink_memory(conn) do
Sqlite3NIF.execute(conn, String.to_charlist("PRAGMA shrink_memory"))
Sqlite3NIF.execute(conn, "PRAGMA shrink_memory")
end

@spec fetch_all(db(), statement(), integer()) :: {:ok, [row()]} | {:error, reason()}
Expand Down Expand Up @@ -198,7 +196,7 @@ defmodule Exqlite.Sqlite3 do
"""
@spec serialize(db(), String.t()) :: {:ok, binary()} | {:error, reason()}
def serialize(conn, database \\ "main") do
Sqlite3NIF.serialize(conn, String.to_charlist(database))
Sqlite3NIF.serialize(conn, database)
end

@doc """
Expand All @@ -207,7 +205,7 @@ defmodule Exqlite.Sqlite3 do
"""
@spec deserialize(db(), String.t(), binary()) :: :ok | {:error, reason()}
def deserialize(conn, database \\ "main", serialized) do
Sqlite3NIF.deserialize(conn, String.to_charlist(database), serialized)
Sqlite3NIF.deserialize(conn, database, serialized)
end

def release(_conn, nil), do: :ok
Expand Down
10 changes: 5 additions & 5 deletions lib/exqlite/sqlite3_nif.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Exqlite.Sqlite3NIF do
:erlang.load_nif(path, 0)
end

@spec open(String.Chars.t(), integer()) :: {:ok, db()} | {:error, reason()}
@spec open(String.t(), integer()) :: {:ok, db()} | {:error, reason()}
def open(_path, _flags), do: :erlang.nif_error(:not_loaded)

@spec close(db()) :: :ok | {:error, reason()}
Expand All @@ -26,13 +26,13 @@ defmodule Exqlite.Sqlite3NIF do
@spec interrupt(db()) :: :ok | {:error, reason()}
def interrupt(_conn), do: :erlang.nif_error(:not_loaded)

@spec execute(db(), String.Chars.t()) :: :ok | {:error, reason()}
@spec execute(db(), String.t()) :: :ok | {:error, reason()}
def execute(_conn, _sql), do: :erlang.nif_error(:not_loaded)

@spec changes(db()) :: {:ok, integer()} | {:error, reason()}
def changes(_conn), do: :erlang.nif_error(:not_loaded)

@spec prepare(db(), String.Chars.t()) :: {:ok, statement()} | {:error, reason()}
@spec prepare(db(), String.t()) :: {:ok, statement()} | {:error, reason()}
def prepare(_conn, _sql), do: :erlang.nif_error(:not_loaded)

@spec bind(db(), statement(), list()) ::
Expand All @@ -55,10 +55,10 @@ defmodule Exqlite.Sqlite3NIF do
@spec transaction_status(db()) :: {:ok, :idle | :transaction}
def transaction_status(_conn), do: :erlang.nif_error(:not_loaded)

@spec serialize(db(), String.Chars.t()) :: {:ok, binary()} | {:error, reason()}
@spec serialize(db(), String.t()) :: {:ok, binary()} | {:error, reason()}
def serialize(_conn, _database), do: :erlang.nif_error(:not_loaded)

@spec deserialize(db(), String.Chars.t(), binary()) :: :ok | {:error, reason()}
@spec deserialize(db(), String.t(), binary()) :: :ok | {:error, reason()}
def deserialize(_conn, _database, _serialized), do: :erlang.nif_error(:not_loaded)

@spec release(db(), statement()) :: :ok | {:error, reason()}
Expand Down
Loading