diff --git a/README.md b/README.md index 994c7b3..4bb91f1 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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