Beancount.Schemas (beancount_ex v0.6.0)

Copy Markdown View Source

Ecto schemas for persisting Beancount directives.

These schemas are the storage-layer counterpart of the Beancount.Directives.* structs. Beancount.Storage.store/1 converts each directive into the matching schema and inserts it; Beancount.Storage.load/0 reads the rows back and rebuilds the original directive structs.

Each dated directive is stored in its own table and carries a file_order integer that records the directive's zero-based position in the original source, so the ledger can be reconstructed in its authored order.

Schema to directive map

SchemaDirectiveTable
Beancount.Schemas.OpenBeancount.Directives.Openbeancount_opens
Beancount.Schemas.CloseBeancount.Directives.Closebeancount_closes
Beancount.Schemas.CommodityBeancount.Directives.Commoditybeancount_commodities
Beancount.Schemas.TransactionBeancount.Directives.Transactionbeancount_transactions
Beancount.Schemas.BalanceBeancount.Directives.Balancebeancount_balances
Beancount.Schemas.PriceBeancount.Directives.Pricebeancount_prices
Beancount.Schemas.NoteBeancount.Directives.Notebeancount_notes
Beancount.Schemas.DocumentBeancount.Directives.Documentbeancount_documents
Beancount.Schemas.EventBeancount.Directives.Eventbeancount_events
Beancount.Schemas.CustomBeancount.Directives.Custombeancount_customs
Beancount.Schemas.PadBeancount.Directives.Padbeancount_pads
Beancount.Schemas.IncludeBeancount.Directives.Includebeancount_includes
Beancount.Schemas.OptionBeancount.Directives.Optionbeancount_options
Beancount.Schemas.PluginBeancount.Directives.Pluginbeancount_plugins
Beancount.Schemas.PushTagBeancount.Directives.PushTagbeancount_push_tags
Beancount.Schemas.PopTagBeancount.Directives.PopTagbeancount_pop_tags
Beancount.Schemas.QueryBeancount.Directives.Querybeancount_queries

Beancount.Schemas.Posting and Beancount.Schemas.CostSpec are embedded schemas nested inside Beancount.Schemas.Transaction; they have no table of their own.

Example

Beancount.Storage.store([Beancount.open(~D[2026-01-01], "Assets:Bank", ["USD"])])
[%Beancount.Directives.Open{account: "Assets:Bank"}] = Beancount.Storage.load()