# `Sekisho.SQL.Dialect`
[🔗](https://github.com/hattoriai/sekisho/blob/v0.1.1/lib/sekisho/sql/dialect.ex#L1)

What Sekisho does differently on one SQL database: the only place it
does.

Everything else is plain Ecto that every SQL database runs (joins,
`UNION`, `EXISTS`, a recursive `WITH` for nested records). Where a
database has a faster way, or needs another column type, a dialect says
so:

  * `c:upsert_grant/2`: a grant made, or made again (its expiry and who
    gave it updated). The default reads, then writes, in a transaction;
    PostgreSQL and SQLite do it in one statement.
  * `c:column/1`: the type of a column of Sekisho's tables, where the
    default does not fit.

Sekisho picks the dialect from the repo's adapter: `Sekisho.SQL.Dialect.Postgres`,
`Sekisho.SQL.Dialect.SQLite`, `Sekisho.SQL.Dialect.MySQL`, and
`Sekisho.SQL.Dialect.Standard` for any other. For another database, write a
module with `use Sekisho.SQL.Dialect`, override what differs, and name it
for its adapter:

    config :sekisho, :dialects, %{Ecto.Adapters.Tds => MyApp.TdsDialect}

It counts for the migrations too, so set it before you run them.

# `column`

```elixir
@callback column(name :: atom()) :: {atom(), keyword()}
```

The type and options of a column of Sekisho's tables (`:token_hash`).

# `upsert_grant`

```elixir
@callback upsert_grant(repo :: module(), Sekisho.Grant.t()) ::
  {:ok, Sekisho.Grant.t()} | {:error, Ecto.Changeset.t()}
```

Inserts the grant, or updates the one of the same record, grantee and role.

# `for_repo`

The dialect of a repo: the app's for its adapter, else Sekisho's, else the standard one.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
