liveBook · Manning

Field

As explained in Learn Haskell by Example

field is a sqlite-simple function that creates a RowParser for a value whose type has a FromField instance.

field creates a RowParser for one database-column value when its type has a FromField instance. FromField supplies a FieldParser, while RowParser combines parsers for complete rows. section 16.3.2

Use field repeatedly with applicative operators to build a FromRow parser. Each field consumes the next column and converts it to the requested Haskell type. section 16.3.2

Parsing a TodoEntry row

instance FromRow TodoEntry where fromRow = TodoEntry <$> field <*> field <*> field <*> field A query can then return [TodoEntry], with each field parser handling one selected column.

How Learn Haskell by Example covers it

How deep it goes
Defines the type and demonstrates repeated use, but stops short of implementing FieldParser.
Examples
Demonstrates four field parsers assembling a TodoEntry and decoding rows returned by query_.
What it assumes
Assumes familiarity with Haskell data constructors and FromField instances while introducing RowParser composition.
What you can do after
Apply it via sqlite-simple to define FromRow instances for database-backed Haskell types.
How it connects
Connects FromField, FieldParser, RowParser, FromRow, applicative parsing, and SQLite query results.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.