Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ dev-efsql

# Local dev launcher; also the name mix escript.build would write here.
/efsql
/src/efsql_sql_*.erl
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,17 @@ Connected to /etc/foundationdb/fdb.cluster

## Supported SQL

All queries require at minimum a `tenant_id.table_name` form in the `FROM` clause. Column names that are reserved SQL words (e.g. `ref`) are supported.
All queries require at minimum a `tenant_id.table_name` form in the `FROM` clause.

Keywords and unquoted names are case-insensitive; double-quote a name to keep
its case (`"CreatedAt"`). Most SQL keywords work as bare names, so columns like
`day`, `user`, `date` or `value` need no quoting. The few that can't, such as
`order`, `select`, `limit` or `and`, must be quoted (`"order"`). The error says
so if you forget.

Comments (`-- ...` and `/* ... */`) can go anywhere. A syntax error reports the
line and column it was found at, and features efsql doesn't support (`OR`,
`NOT`, `<>`, joins, functions, `GROUP BY`) are rejected by name.

### Storage IDs

Expand Down Expand Up @@ -287,9 +297,11 @@ which the adapter keys by the `Decimal`'s term encoding rather than its value.
Ecto stores `Ecto.Enum` fields as strings, so query those with a plain string
literal, not an atom.

`BETWEEN` and `LIKE` don't accept typed literals; write a range as
`inserted_at >= '2024-01-01'::timestamp and inserted_at < '2025-01-01'::timestamp`
instead.
Typed literals work anywhere a value does, including `IN` and `BETWEEN`:

```sql
select col_a from tenant_id.table_name where inserted_at between '2024-01-01'::timestamp and '2025-01-01'::timestamp;
```

### Limit

Expand Down
2 changes: 0 additions & 2 deletions lib/efsql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ defmodule Efsql do

import Ecto.Query

def lex_and_parse(sql), do: Efsql.Parser.parse(sql)

def hello() do
tenant = EctoFoundationDB.Tenant.open!(Efsql.Repo, "localhost")

Expand Down
8 changes: 5 additions & 3 deletions lib/efsql/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ defmodule Efsql.Cli do
|> then(&"async union (#{length(nodes)}):\n#{&1}")
end

defp print_error(term) do
Owl.IO.puts(Owl.Data.tag(inspect(term), :red))
end
defp print_error(%{__exception__: true} = e),
do: Owl.IO.puts(Owl.Data.tag(Exception.message(e), :red))

defp print_error(term) when is_binary(term), do: Owl.IO.puts(Owl.Data.tag(term, :red))
defp print_error(term), do: Owl.IO.puts(Owl.Data.tag(inspect(term), :red))
end
Loading
Loading