@@ -33,12 +33,31 @@ import Rel8.Schema.Spec ( SSpec(..) )
33import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
33import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
36+-- | Construct a table in the 'Name' context containing the names of all
37+-- columns. Nested column names will be combined with @/@.
39+-- See also: 'namesFromLabelsWith'.
36namesFromLabels :: Table Name a => a
40namesFromLabels :: Table Name a => a
37namesFromLabels = namesFromLabelsWith go
41namesFromLabels = namesFromLabelsWith go
39 go = fold . intersperse "/"
43 go = fold . intersperse "/"
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.
49+-- This function can be used to generically derive the columns for a
50+-- 'TableSchema'. For example,
53+-- myTableSchema :: TableSchema (MyTable Name)
54+-- myTableSchema = TableSchema
55+-- { columns = namesFromLabelsWith last
59+-- will construct a 'TableSchema' where each columns names exactly corresponds
60+-- to the name of the Haskell field.
42namesFromLabelsWith :: Table Name a
61namesFromLabelsWith :: Table Name a
43 => (NonEmpty String -> String) -> a
62 => (NonEmpty String -> String) -> a
44namesFromLabelsWith f = fromColumns $ htabulate $ \field ->
63namesFromLabelsWith f = fromColumns $ htabulate $ \field ->