Skip to content

Commit 3645bb8

Browse files
committed
Cleanup documentation a little more about loading extensions
1 parent 2d0912f commit 3645bb8

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ The `Exqlite.Sqlite3` module usage is fairly straight forward.
172172
### Using SQLite3 native extensions
173173
174174
Exqlite supports loading [run-time loadable SQLite3 extensions](https://www.sqlite.org/loadext.html).
175-
A selection of precompiled extensions for popular CPU types / architectures is available by installing the [ExSqlean](https://github.com/mindreframer/ex_sqlean) package. This package wraps [SQLean: all the missing SQLite functions](https://github.com/nalgeon/sqlean).
175+
A selection of precompiled extensions for popular CPU types / architectures is
176+
available by installing the [ExSqlean](https://github.com/mindreframer/ex_sqlean)
177+
package. This package wraps [SQLean: all the missing SQLite functions](https://github.com/nalgeon/sqlean).
176178
177179
```elixir
178180
alias Exqlite.Basic
@@ -194,13 +196,33 @@ Basic.load_extension(conn, ExSqlean.path_for("re"))
194196
Basic.close(conn)
195197
```
196198
197-
It is also possible to load extensions using the `Connection` configuration. For example:
199+
It is also possible to load extensions using the `Connection` configuration. For example:
198200
199-
config :exqlite, load_extensions: [ "./priv/sqlite/\#{arch_dir}/rotate" ]
200-
201-
This method works with `Exqlite.Sqlite3`. For more info see the (Connection.connect/1)[https://hexdocs.pm/exqlite/Exqlite.Connection.html#connect/1]
202-
docs.
201+
```elixir
202+
arch_dir =
203+
System.cmd("uname", ["-sm"])
204+
|> elem(0)
205+
|> String.trim()
206+
|> String.replace(" ", "-")
207+
|> String.downcase() # => "darwin-arm64"
208+
209+
config :myapp, arch_dir: arch_dir
210+
211+
# global
212+
config :exqlite, load_extensions: [ "./priv/sqlite/\#{arch_dir}/rotate" ]
213+
214+
# per connection in a Phoenix app
215+
config :myapp, Myapp.Repo,
216+
database: "path/to/db",
217+
load_extensions: [
218+
"./priv/sqlite/\#{arch_dir}/vector0",
219+
"./priv/sqlite/\#{arch_dir}/vss0"
220+
]
221+
```
203222

223+
See [Exqlite.Connection.connect/1](https://hexdocs.pm/exqlite/Exqlite.Connection.html#connect/1)
224+
for more information. When using extensions for SQLite3, they must be compiled
225+
for the environment you are targeting.
204226

205227
## Why SQLite3
206228

0 commit comments

Comments
 (0)