From af05dcdf180c7a745f893f7e27efad10ec74e002 Mon Sep 17 00:00:00 2001 From: Matthew Johnston Date: Thu, 12 Sep 2024 21:43:06 -0500 Subject: [PATCH] Stop converting strings `to_charlist` --- lib/exqlite/sqlite3.ex | 10 ++++------ lib/exqlite/sqlite3_nif.ex | 10 +++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/exqlite/sqlite3.ex b/lib/exqlite/sqlite3.ex index efb4766..1f25044 100644 --- a/lib/exqlite/sqlite3.ex +++ b/lib/exqlite/sqlite3.ex @@ -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)) @@ -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()} @@ -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 """ @@ -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 diff --git a/lib/exqlite/sqlite3_nif.ex b/lib/exqlite/sqlite3_nif.ex index bdb6065..356daca 100644 --- a/lib/exqlite/sqlite3_nif.ex +++ b/lib/exqlite/sqlite3_nif.ex @@ -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()} @@ -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()) :: @@ -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()}