Sekisho.SQL.Dialect behaviour (Sekisho v0.1.1)

Copy Markdown View Source

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:

  • 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.
  • 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.

Summary

Callbacks

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

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

Functions

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

Callbacks

column(name)

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

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

upsert_grant(repo, t)

@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.

Functions

for_repo(repo)

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