@@ -33,12 +33,31 @@ import Rel8.Schema.Spec ( SSpec(..) )
3333import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
3434
3535
36+-- | Construct a table in the 'Name' context containing the names of all
37+-- columns. Nested column names will be combined with @/@.
38+--
39+-- See also: 'namesFromLabelsWith'.
3640namesFromLabels :: Table Name a => a
3741namesFromLabels = namesFromLabelsWith go
3842 where
3943 go = fold . intersperse "/"
4044
4145
46+-- | Construct a table in the 'Name' context containing the names of all
47+-- columns. The supplied function can be used to transform column names.
48+--
49+-- This function can be used to generically derive the columns for a
50+-- 'TableSchema'. For example,
51+--
52+-- @
53+-- myTableSchema :: TableSchema (MyTable Name)
54+-- myTableSchema = TableSchema
55+-- { columns = namesFromLabelsWith last
56+-- }
57+-- @
58+--
59+-- will construct a 'TableSchema' where each columns names exactly corresponds
60+-- to the name of the Haskell field.
4261namesFromLabelsWith :: Table Name a
4362 => (NonEmpty String -> String) -> a
4463namesFromLabelsWith f = fromColumns $ htabulate $ \field ->