Fathom (fathom v0.1.0)

Copy Markdown View Source

A program database for Elixir codebases.

Fathom compiles a project under a compiler tracer and writes what the compiler resolved into SQLite: definitions, calls, module dependencies, behaviours, protocols, Ecto schemas, Phoenix routes, and the sites where dispatch is dynamic enough that the call graph stops being complete.

Most use goes through the Mix tasks:

mix fathom.install   # wire the database into AGENTS.md
mix fathom.build     # compile under the tracer and write the database
mix fathom.query     # run a read-only query

This module is for reading the database from Elixir, which is mainly useful for building linters on top of it.

Pieces

Summary

Functions

The conventional location of the database.

Asserts that a query returns no rows, which is how architecture rules are written.

Runs a read-only query and returns {:ok, columns, rows}.

Runs a query and returns its rows as maps keyed by column name.

Functions

default_path()

The conventional location of the database.

forbid(sql, params \\ [], path \\ ".fathom/program.db")

Asserts that a query returns no rows, which is how architecture rules are written.

Returns :ok, or {:error, rows} with the violations.

Fathom.forbid("""
SELECT caller, file, line FROM calls
WHERE caller_module LIKE 'MyAppWeb.%' AND callee_module LIKE '%.Repo'
""")

query(sql, params \\ [], path \\ ".fathom/program.db")

Runs a read-only query and returns {:ok, columns, rows}.

The connection is opened read-only, so a statement that tries to write fails at SQLite rather than relying on anything here to inspect the SQL.

iex> Fathom.query("SELECT mfa FROM functions WHERE name = ?", ["create_user"])

query!(sql, params \\ [], path \\ ".fathom/program.db")

Runs a query and returns its rows as maps keyed by column name.

Raises if the query fails.