beam provides a Haskell interface for declaring relational schemas and constructing type-safe SQL queries without building another type-level database abstraction. It targets applications that need typed models while supporting multiple SQL backends. section 12.2.1 section 12.2.2
Its design uses advanced Haskell machinery—type families, multiparameter type classes, phantom types, existential types, ADTs, and HKD-style records—to represent tables, schemas, keys, and queries. This broad genericity supports unknown backends and backend-specific plugins, but makes the interface difficult to understand and tightly coupled when embedded in a larger framework. section 12.2.2
Listing 12.3 DBMeteor table definition
import Database.Beam (Columnar, Beamable)
data DBMeteorT f = DBMeteor #1
{ _id :: Columnar f Int #2
, _size :: Columnar f Int
, _mass :: Columnar f Int
, _azimuth :: Columnar f Int
, _altitude :: Columnar f Int
, _timestamp :: Columnar f UTCTime
}
deriving (Generic, Beamable) #3
A representative table declaration uses an HKD-style parameterized record, Columnar fields, Generic derivation, and Beamable derivation to model meteor data. section 12.2.2
Schema and query flow
A database model declares DBMeteorT with typed fields such as _id, _mass, and _timestamp. A Table instance identifies the primary key, CatalogueDB registers the table for a backend, and a query composes select, filter_, and all_ to retrieve meteors matching a size. Backend execution then runs the selected statement through a connection. section 12.2.2 section 12.2.2
