mirror of
https://github.com/circuithub/rel8.git
synced 2024-09-11 16:05:41 +03:00
Document namesFromLabels and namesFromLabelsWith
This commit is contained in:
parent
7f5801f051
commit
7133acedfe
@ -33,12 +33,31 @@ import Rel8.Schema.Spec ( SSpec(..) )
|
||||
import Rel8.Table ( Table, Columns, Context, fromColumns, toColumns )
|
||||
|
||||
|
||||
-- | Construct a table in the 'Name' context containing the names of all
|
||||
-- columns. Nested column names will be combined with @/@.
|
||||
--
|
||||
-- See also: 'namesFromLabelsWith'.
|
||||
namesFromLabels :: Table Name a => a
|
||||
namesFromLabels = namesFromLabelsWith go
|
||||
where
|
||||
go = fold . intersperse "/"
|
||||
|
||||
|
||||
-- | Construct a table in the 'Name' context containing the names of all
|
||||
-- columns. The supplied function can be used to transform column names.
|
||||
--
|
||||
-- This function can be used to generically derive the columns for a
|
||||
-- 'TableSchema'. For example,
|
||||
--
|
||||
-- @
|
||||
-- myTableSchema :: TableSchema (MyTable Name)
|
||||
-- myTableSchema = TableSchema
|
||||
-- { columns = namesFromLabelsWith last
|
||||
-- }
|
||||
-- @
|
||||
--
|
||||
-- will construct a 'TableSchema' where each columns names exactly corresponds
|
||||
-- to the name of the Haskell field.
|
||||
namesFromLabelsWith :: Table Name a
|
||||
=> (NonEmpty String -> String) -> a
|
||||
namesFromLabelsWith f = fromColumns $ htabulate $ \field ->
|
||||
|
Loading…
Reference in New Issue
Block a user