Skip to content

Commit

Permalink
Cleanup documentation a little more about loading extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
warmwaffles committed Jan 16, 2024
1 parent 2d0912f commit 3645bb8
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ The `Exqlite.Sqlite3` module usage is fairly straight forward.
### Using SQLite3 native extensions
Exqlite supports loading [run-time loadable SQLite3 extensions](https://www.sqlite.org/loadext.html).
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).
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).
```elixir
alias Exqlite.Basic
Expand All @@ -194,13 +196,33 @@ Basic.load_extension(conn, ExSqlean.path_for("re"))
Basic.close(conn)
```
It is also possible to load extensions using the `Connection` configuration. For example:
It is also possible to load extensions using the `Connection` configuration. For example:
config :exqlite, load_extensions: [ "./priv/sqlite/\#{arch_dir}/rotate" ]

This method works with `Exqlite.Sqlite3`. For more info see the (Connection.connect/1)[https://hexdocs.pm/exqlite/Exqlite.Connection.html#connect/1]
docs.
```elixir
arch_dir =
System.cmd("uname", ["-sm"])
|> elem(0)
|> String.trim()
|> String.replace(" ", "-")
|> String.downcase() # => "darwin-arm64"
config :myapp, arch_dir: arch_dir
# global
config :exqlite, load_extensions: [ "./priv/sqlite/\#{arch_dir}/rotate" ]

# per connection in a Phoenix app
config :myapp, Myapp.Repo,
database: "path/to/db",
load_extensions: [
"./priv/sqlite/\#{arch_dir}/vector0",
"./priv/sqlite/\#{arch_dir}/vss0"
]
```

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

## Why SQLite3

Expand Down

0 comments on commit 3645bb8

Please sign in to comment.