beancount_ex stores directives in a database via Ecto. The default backend is SQLite in-memory (:memory:), which requires no configuration and runs in-process. For persistence, configure a file path.

Configuration

# config/config.exs — default (in-memory)
config :beancount_ex, Beancount.Repo,
  database: ":memory:"

# For file persistence:
config :beancount_ex, Beancount.Repo,
  database: "path/to/ledger.db"

Import and export

Import a .bean file into the database:

{:ok, count} = Beancount.Storage.import_file("ledger.bean")

Export the database back to a .bean file:

:ok = Beancount.Storage.export_file("out.bean")

Store a directive list directly:

{:ok, count} = Beancount.Storage.store(directives)

Load all directives from the database:

directives = Beancount.Storage.load()

Clear all directives:

:ok = Beancount.Storage.clear()

Schema overview

Each directive type maps to a database table under the Beancount.Schemas namespace:

TableSchemaKey fields
beancount_opensSchemas.Opendate, account, currencies, booking
beancount_closesSchemas.Closedate, account
beancount_commoditiesSchemas.Commoditydate, currency
beancount_transactionsSchemas.Transactiondate, flag, payee, narration, postings (JSON)
beancount_balancesSchemas.Balancedate, account, amount, currency, tolerance
beancount_pricesSchemas.Pricedate, commodity, amount, currency
beancount_notesSchemas.Notedate, account, comment
beancount_documentsSchemas.Documentdate, account, path
beancount_eventsSchemas.Eventdate, type, description
beancount_customsSchemas.Customdate, type, values (JSON)
beancount_padsSchemas.Paddate, account, source_account
beancount_optionsSchemas.Optionname, value (type-tagged map)
beancount_includesSchemas.Includepath
beancount_pluginsSchemas.Pluginmodule, config
beancount_push_tagsSchemas.PushTagtag
beancount_pop_tagsSchemas.PopTagtag
beancount_queriesSchemas.Querydate, name, bql

Transaction postings are stored as a JSON column (embeds_many). Cost specs are embedded within each posting. Metadata is stored as JSON (:map).

All tables include a file_order integer column that preserves source-file ordering for deterministic rendering and round-trip fidelity.

Future backends

  • PostgreSQL (via postgrex + ecto_sql): durable, queryable, app-friendly. JSONB for metadata and postings. Window functions for running balances.
  • Mnesia (via ecto_mnesia): distributed persistence without external services. ETS-backed RAM tables for fast access.