on dev help sign in
Update RELEASE NOTES.md

more enum notes

commit0d779f5dac3e7c0de0337cfbb52030172e6a80ca authorEitan Chatav <eitan.chatav@gmail.com> dateMon 25 Jun 2018, 10:42 (8 years ago) parentd3b55de
1 file changed+31−6
RELEASE NOTES.md+31−6
RELEASE NOTES.md+31−6
@@ -55,8 +55,7 @@ type BC =
5555>>> :{
5656let
5757 definition :: Definition '["abc" ::: 'Table ABC ] '["abc" ::: 'Table ABC, "bc" ::: 'View BC]
58− definition =
59− createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
58+ definition = createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
6059in printSQL definition
6160:}
6261CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
@@ -82,26 +81,52 @@ SELECT * FROM "bc" AS "bc"
8281
8382PostgreSQL has a powerful type system. It even allows for user defined types.
8483For instance, you can define enumerated types which are data types that comprise
85−a static, ordered set of values. An example of an enum type might be the days of the week,
84+a static, ordered set of values. They are equivalent to Haskell algebraic data
85+types whose constructors are nullary. An example of an enum type might be the days of the week,
8686or a set of status values for a piece of data.
8787
8888Enumerated types are created using the `createTypeEnum` command, for example
8989
9090```Haskell
91−>>> printSQL $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
91+>>> :{
92+let
93+ definition :: Definition '[] '["mood" ::: 'Typedef ('PGenum '["sad", "ok", "happy"])]
94+ definition = createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
95+:}
96+>>> printSQL definition
9297CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
9398```
9499
95−Enumerated types can also be generated from a Haskell type, for example
100+Enumerated types can also be generated from a Haskell algbraic data type with nullary constructors, for example
96101
97102```Haskell
98103>>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
99104>>> instance SOP.Generic Schwarma
100105>>> instance SOP.HasDatatypeInfo Schwarma
101−>>> printSQL $ createTypeEnumFrom @Schwarma #schwarma
106+>>> :{
107+let
108+ definition :: Definition '[] '["schwarma" ::: 'Typedef (EnumFrom Schwarma)]
109+ definition = createTypeEnumFrom @Schwarma #schwarma
110+:}
111+>>> printSQL definition
102112CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
103113```
104114
115+You can express values of an enum type using `label`, which is an overloaded method
116+of the `IsPGlabel` typeclass.
117+
118+>>> :{
119+let
120+ expression :: Expression sch rels grp params ('NotNull (EnumFrom Schwarma))
121+ expression = label @"Chicken"
122+in printSQL expression
123+:}
124+'Chicken'
125+
126+**Composite Types**
127+
128+
129+
105130### Version 0.2.1 - April 7, 2018
106131
107132This minor update fixes an issue where alias identifiers could conflict with