Work in progress.
Efsql is a SQL Layer for FoundationDB. It's implemented via the EctoFoundationDB Layer for Elixir.
#!/bin/bash
mix run efsql.exs -C ../path/to/etc/fdb.clusterThe default cluster file is chosen using the same logic as fdbcli's default cluster file.
~/d/efsql ❯❯❯ mix run efsql.exs -C ../path/to/etc/fdb.cluster
Connected to ../path/to/etc/fdb.cluster
[Ctrl+D to exit]
> select id, inserted_at from my_tenant_id.my_table_name;
┌─────────────────┬─────────────────────┐
│ Id │ Inserted At │
├─────────────────┼─────────────────────┤
│ trmD6RQjbPTQmMD │ 2025-05-15 22:35:38 │
└─────────────────┴─────────────────────┘Use a readline-wrapper, such as rlwrap, to enable command history:
# Enable history and navigation
~/d/efsql ❯❯❯ rlwrap mix run efsql.exs
# Some other helpful options
~/d/efsql ❯❯❯ rlwrap -ra -pgreen -f completions mix run efsql.exsselect col_a, col_b from tenant_id.schema_name;
select col_a, col_b from tenant_id.schema_name where _ = 'foobar';
select col_a, col_b from tenant_id.schema_name where _ >= 'bar' and _ < 'foo';
select col_a, col_b from tenant_id.schema_name where _ > 'bar';
select col_a, col_b from tenant_id.schema_name where _ < 'foo';
select col_a, col_b from tenant_id.schema_name where _ between 'bar' and 'foo';
select col_a, col_b from tenant_id.schema_name where index_col = 'baz';
select col_a, col_b from tenant_id.schema_name where index_col >= 'baz' and index_col < 'zaz';
select col_a, col_b from tenant_id.schema_name where index_col between 'baz' and 'zaz';
See EctoFoundationDB's Default indexes. Since we don't require access to the Ecto.Schema, and EctoFDB doesn't store the schema in the database, we loosen the type checking for these queries. For example, if the indexed column is a naive_datetime, then you must query using the string representation for the timestamp.
Sadly, it's not possible to have a self-contained escript at this time because of the erlfdb NIF.
If available in Hex, the package can be installed
by adding efsql to your list of dependencies in mix.exs:
def deps do
[
{:efsql, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/efsql.