Skip to content

Commit 8e44fc4

Browse files
committed
Allow version to be given on database start, closes #138
1 parent 2da22ea commit 8e44fc4

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/adbc.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ defmodule Adbc do
141141
url: "https://github.com/duckdb/duckdb/releases/download/v1.3.0/libduckdb-osx-universal.zip"
142142
)
143143
144-
You can also pass download options when configuring the `:adbc`:
144+
And then start the driver passing the version option:
145+
146+
{Adbc.Database, driver: :duckdb, version: "1.3.0"}
147+
148+
Note you can also configure the `:adbc` application to download
149+
a custom driver during compilation too:
145150
146151
config :adbc, :drivers,
147152
[{:duckdb, version: ..., url: ...}]

lib/adbc_database.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ defmodule Adbc.Database do
4141
"""
4242
def start_link(opts \\ []) do
4343
{driver, opts} = Keyword.pop(opts, :driver, nil)
44+
{driver_opts, opts} = Keyword.split(opts, [:version])
4445

4546
unless driver do
4647
raise ArgumentError, ":driver option must be specified"
@@ -50,7 +51,7 @@ defmodule Adbc.Database do
5051
opts = Keyword.merge(driver_default_options(driver), opts)
5152

5253
with {:ok, ref} <- Adbc.Nif.adbc_database_new(),
53-
:ok <- init_driver(ref, driver),
54+
:ok <- init_driver(ref, driver, driver_opts),
5455
:ok <- init_options(ref, opts),
5556
:ok <- Adbc.Nif.adbc_database_init(ref) do
5657
GenServer.start_link(__MODULE__, {driver, ref}, process_options)
@@ -153,8 +154,8 @@ defmodule Adbc.Database do
153154
@impl true
154155
def handle_info(_msg, state), do: {:noreply, state}
155156

156-
defp init_driver(ref, driver) do
157-
case Adbc.Driver.so_path(driver) do
157+
defp init_driver(ref, driver, driver_opts) do
158+
case Adbc.Driver.so_path(driver, driver_opts) do
158159
{:ok, path} -> Adbc.Helper.option(ref, :adbc_database_set_option, [:string, "driver", path])
159160
{:error, reason} -> {:error, reason}
160161
end

lib/adbc_driver.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ defmodule Adbc.Driver do
316316
{:ok, expected_filepath}
317317
else
318318
{:error,
319-
"driver #{driver_name} is not available (see Adbc moduledocs to learn how to install a driver)"}
319+
"driver #{driver_name} (version #{version}) is not available (see Adbc moduledocs to learn how to install a driver)"}
320320
end
321321

322322
{:error, reason} ->

0 commit comments

Comments
 (0)