liveBook · Manning

FromRow

As explained in Learn Haskell by Example

FromRow is a sqlite-simple type class whose instances define parsing of SQL row data into Haskell values.

FromRow is a sqlite-simple type class for reading SQL query results as Haskell values. Its fromRow method defines a RowParser that converts database row data into a chosen result type. section 16.3.2

Each column is parsed with FromField through field. Applicative syntax combines those field parsers in column order, matching a constructor’s arguments. section 16.3.2

Parsing a TodoEntry

A TodoEntry instance can read four selected columns directly: fromRow = TodoEntry <$> field <*> field <*> field <*> field. Registering this instance lets query_ return [TodoEntry], while SQLite integer values are converted into the corresponding Haskell fields.

For standard data types, sqlite-simple supplies FromField parsers. Generic can also derive FromRow and ToRow instances when the datatype definition provides the required structure. section 16.4

How Learn Haskell by Example covers it

How deep it goes
Defines RowParser construction with FromField and field, then demonstrates explicit and generic instances without detailing custom parser internals.
Examples
Demonstrates TodoEntry parsing, query_ returning [TodoEntry], and generic FromRow and ToRow instances.
What it assumes
Assumes basic Haskell data constructors and applicative syntax, while introducing FromField, RowParser, and database type classes.
What you can do after
Build it from scratch by defining a FromRow instance that maps ordered SQL columns through field.
How it connects
Connects FromField, RowParser, ToRow, ToField, Generic, and SQLite query functions.

Also explained in

Compare how 2 books explain FromRow →

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.