on dev help sign in
fix some more test errors
commit186ba6355bfe489dbe86218cd858ead4ebcf2cd3 authorEitan Chatav <eitan.chatav@gmail.com> dateSat 24 Nov 2018, 18:35 (8 years ago) parent463bd94
4 files changed+67−54
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+49−36 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+16−16 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1−1
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+49−36
@@ -590,8 +590,8 @@ newtype AlterTable
590590-- >>> :{
591591-- let
592592-- definition :: Definition
593−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
594−-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
593+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
594+-- '["public" ::: '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
595595-- definition = alterTable #tab (addConstraint #positive (check #col (#col .> 0)))
596596-- in printSQL definition
597597-- :}
@@ -615,8 +615,8 @@ addConstraint alias constraint = UnsafeAlterTable $
615615-- >>> :{
616616-- let
617617-- definition :: Definition
618−-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
619−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
618+-- '["public" ::: '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
619+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
620620-- definition = alterTable #tab (dropConstraint #positive)
621621-- in printSQL definition
622622-- :}
@@ -641,10 +641,10 @@ class AddColumn ty where
641641 -- >>> :{
642642 -- let
643643 -- definition :: Definition
644− -- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
645− -- '["tab" ::: 'Table ('[] :=>
644+ -- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]]
645+ -- '["public" ::: '["tab" ::: 'Table ('[] :=>
646646 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
647− -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]
647+ -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]]
648648 -- definition = alterTable #tab (addColumn #col2 (text & nullable & default_ "foo"))
649649 -- in printSQL definition
650650 -- :}
@@ -653,10 +653,10 @@ class AddColumn ty where
653653 -- >>> :{
654654 -- let
655655 -- definition :: Definition
656− -- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
657− -- '["tab" ::: 'Table ('[] :=>
656+ -- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]]
657+ -- '["public" ::: '["tab" ::: 'Table ('[] :=>
658658 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
659− -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
659+ -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]]
660660 -- definition = alterTable #tab (addColumn #col2 (text & nullable))
661661 -- in printSQL definition
662662 -- :}
@@ -682,10 +682,10 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
682682-- >>> :{
683683-- let
684684-- definition :: Definition
685−-- '["tab" ::: 'Table ('[] :=>
685+-- '["public" ::: '["tab" ::: 'Table ('[] :=>
686686-- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
687−-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
688−-- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
687+-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]]
688+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]]
689689-- definition = alterTable #tab (dropColumn #col2)
690690-- in printSQL definition
691691-- :}
@@ -706,8 +706,8 @@ dropColumn column = UnsafeAlterTable $
706706-- >>> :{
707707-- let
708708-- definition :: Definition
709−-- '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]
710−-- '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]
709+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]]
710+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]]
711711-- definition = alterTable #tab (renameColumn #foo #bar)
712712-- in printSQL definition
713713-- :}
@@ -751,8 +751,8 @@ newtype AlterColumn (db :: DBType) (ty0 :: ColumnType) (ty1 :: ColumnType) =
751751-- >>> :{
752752-- let
753753-- definition :: Definition
754−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
755−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
754+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]]
755+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]]
756756-- definition = alterTable #tab (alterColumn #col (setDefault 5))
757757-- in printSQL definition
758758-- :}
@@ -768,8 +768,8 @@ setDefault expression = UnsafeAlterColumn $
768768-- >>> :{
769769-- let
770770-- definition :: Definition
771−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
772−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
771+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]]
772+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]]
773773-- definition = alterTable #tab (alterColumn #col dropDefault)
774774-- in printSQL definition
775775-- :}
@@ -784,8 +784,8 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
784784-- >>> :{
785785-- let
786786-- definition :: Definition
787−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
788−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
787+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]]
788+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
789789-- definition = alterTable #tab (alterColumn #col setNotNull)
790790-- in printSQL definition
791791-- :}
@@ -799,8 +799,8 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
799799-- >>> :{
800800-- let
801801-- definition :: Definition
802−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
803−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
802+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
803+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]]
804804-- definition = alterTable #tab (alterColumn #col dropNotNull)
805805-- in printSQL definition
806806-- :}
@@ -816,8 +816,8 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
816816-- >>> :{
817817-- let
818818-- definition :: Definition
819−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
820−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]
819+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
820+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]]
821821-- definition =
822822-- alterTable #tab (alterColumn #col (alterType (numeric & notNullable)))
823823-- in printSQL definition
@@ -831,9 +831,9 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
831831-- >>> :{
832832-- let
833833-- definition :: Definition
834−-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
835−-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
836−-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
834+-- '[ "public" ::: '["abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]]
835+-- '[ "public" ::: '["abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
836+-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]]
837837-- definition =
838838-- createView #bc (select (#b :* #c) (from (table #abc)))
839839-- in printSQL definition
@@ -854,9 +854,9 @@ createView alias query = UnsafeDefinition $
854854-- >>> :{
855855-- let
856856-- definition :: Definition
857−-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
858−-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
859−-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
857+-- '[ "public" ::: '["abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
858+-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]]
859+-- '[ "public" ::: '["abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]]
860860-- definition = dropView #bc
861861-- in printSQL definition
862862-- :}
@@ -869,7 +869,7 @@ dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderQualifiedAlias vw <> ";"
869869
870870-- | Enumerated types are created using the `createTypeEnum` command, for example
871871--
872−-- >>> printSQL $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy")
872+-- >>> printSQL $ (createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy") :: Definition '["public" ::: '[]] '["public" ::: '["mood" ::: 'Typedef ('PGenum '["sad","ok","happy"])]])
873873-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
874874createTypeEnum
875875 :: (KnownSymbol enum, Has sch db schema, SOP.All KnownSymbol labels)
@@ -887,7 +887,13 @@ createTypeEnum enum labels = UnsafeDefinition $
887887-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
888888-- >>> instance SOP.Generic Schwarma
889889-- >>> instance SOP.HasDatatypeInfo Schwarma
890−-- >>> printSQL $ createTypeEnumFrom @Schwarma #schwarma
890+-- >>> :{
891+-- let
892+-- createSchwarma :: Definition '["public" ::: '[]] '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]]
893+-- createSchwarma = createTypeEnumFrom @Schwarma #schwarma
894+-- in
895+-- printSQL createSchwarma
896+-- :}
891897-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
892898createTypeEnumFrom
893899 :: forall hask sch enum db schema.
@@ -912,7 +918,7 @@ type PGcomplex = 'PGcomposite
912918
913919>>> :{
914920let
915− setup :: Definition '[] '["complex" ::: 'Typedef PGcomplex]
921+ setup :: Definition '["public" ::: '[]] '["public" ::: '["complex" ::: 'Typedef PGcomplex]]
916922 setup = createTypeComposite #complex
917923 (float8 `as` #real :* float8 `as` #imaginary)
918924in printSQL setup
@@ -939,7 +945,14 @@ createTypeComposite ty fields = UnsafeDefinition $
939945-- >>> data Complex = Complex {real :: Double, imaginary :: Double} deriving GHC.Generic
940946-- >>> instance SOP.Generic Complex
941947-- >>> instance SOP.HasDatatypeInfo Complex
942−-- >>> printSQL $ createTypeCompositeFrom @Complex #complex
948+-- >>> type DB = '["public" ::: '["complex" ::: 'Typedef (PG (Composite Complex))]]
949+-- >>> :{
950+-- let
951+-- createComplex :: Definition '["public" ::: '[]] DB
952+-- createComplex = createTypeCompositeFrom @Complex #complex
953+-- in
954+-- printSQL createComplex
955+-- :}
943956-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
944957createTypeCompositeFrom
945958 :: forall hask sch ty db schema.
@@ -964,7 +977,7 @@ instance (KnownSymbol alias, PGTyped db ty)
964977-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
965978-- >>> instance SOP.Generic Schwarma
966979-- >>> instance SOP.HasDatatypeInfo Schwarma
967−-- >>> printSQL (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))] '[])
980+-- >>> printSQL (dropType #schwarma :: Definition '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]] '["public" ::: '[]])
968981-- DROP TYPE "schwarma";
969982dropType
970983 :: (Has sch db schema, Has td schema ('Typedef ty))
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+1−1
@@ -484,7 +484,7 @@ row exprs = UnsafeExpression $ "ROW" <> parenthesized
484484--
485485-- >>> let i = row (0 `as` #real :* 1 `as` #imaginary) :: Expression DB from grp params ('NotNull Complex)
486486-- >>> printSQL $ i & field #complex #imaginary
487−-- (ROW(0, 1)::"public"."complex")."imaginary"
487+-- (ROW(0, 1)::"complex")."imaginary"
488488field
489489 :: ( Has sch db schema
490490 , Has tydef schema ('Typedef ('PGcomposite row))
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+16−16
@@ -65,9 +65,9 @@ simple insert:
6565>>> :{
6666let
6767 manipulation :: Manipulation
68− '[ "tab" ::: 'Table ('[] :=>
68+ '[ "public" ::: '["tab" ::: 'Table ('[] :=>
6969 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
70− , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[] '[]
70+ , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])]] '[] '[]
7171 manipulation =
7272 insertRow_ #tab (Set 2 `as` #col1 :* Default `as` #col2)
7373in printSQL manipulation
@@ -79,9 +79,9 @@ parameterized insert:
7979>>> :{
8080let
8181 manipulation :: Manipulation
82− '[ "tab" ::: 'Table ('[] :=>
82+ '[ "public" ::: '["tab" ::: 'Table ('[] :=>
8383 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
84− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
84+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]]
8585 '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
8686 manipulation =
8787 insertRow_ #tab
@@ -95,9 +95,9 @@ returning insert:
9595>>> :{
9696let
9797 manipulation :: Manipulation
98− '[ "tab" ::: 'Table ('[] :=>
98+ '[ "public" ::: '["tab" ::: 'Table ('[] :=>
9999 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
100− , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[]
100+ , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])]] '[]
101101 '["fromOnly" ::: 'NotNull 'PGint4]
102102 manipulation =
103103 insertRow #tab (Set 2 `as` #col1 :* Default `as` #col2)
@@ -111,9 +111,9 @@ upsert:
111111>>> :{
112112let
113113 manipulation :: Manipulation
114− '[ "tab" ::: 'Table ('[] :=>
114+ '[ "public" ::: '["tab" ::: 'Table ('[] :=>
115115 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
116− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
116+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]]
117117 '[] '[ "sum" ::: 'NotNull 'PGint4]
118118 manipulation =
119119 insertRows #tab
@@ -132,7 +132,7 @@ query insert:
132132>>> :{
133133let
134134 manipulation :: Manipulation
135− '[ "tab" ::: 'Table ('[] :=>
135+ '[ "public" ::: '["tab" ::: 'Table ('[] :=>
136136 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
137137 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4
138138 ])
@@ -140,7 +140,7 @@ let
140140 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
141141 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4
142142 ])
143− ] '[] '[]
143+ ]] '[] '[]
144144 manipulation =
145145 insertQuery_ #tab
146146 (selectStar (from (table (#other_tab `as` #t))))
@@ -153,9 +153,9 @@ update:
153153>>> :{
154154let
155155 manipulation :: Manipulation
156− '[ "tab" ::: 'Table ('[] :=>
156+ '[ "public" ::: '["tab" ::: 'Table ('[] :=>
157157 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
158− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[] '[]
158+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]] '[] '[]
159159 manipulation =
160160 update_ #tab (Set 2 `as` #col1 :* Same `as` #col2)
161161 (#col1 ./= #col2)
@@ -168,9 +168,9 @@ delete:
168168>>> :{
169169let
170170 manipulation :: Manipulation
171− '[ "tab" ::: 'Table ('[] :=>
171+ '[ "public" ::: '["tab" ::: 'Table ('[] :=>
172172 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
173− , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[]
173+ , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]] '[]
174174 '[ "col1" ::: 'NotNull 'PGint4
175175 , "col2" ::: 'NotNull 'PGint4 ]
176176 manipulation = deleteFrom #tab (#col1 .== #col2) ReturningStar
@@ -185,9 +185,9 @@ with manipulation:
185185>>> :{
186186let
187187 manipulation :: Manipulation
188− '[ "products" ::: 'Table ProductsTable
188+ '[ "public" ::: '["products" ::: 'Table ProductsTable
189189 , "products_deleted" ::: 'Table ProductsTable
190− ] '[ 'NotNull 'PGdate] '[]
190+ ]] '[ 'NotNull 'PGdate] '[]
191191 manipulation = with
192192 (deleteFrom #products (#date .< param @1) ReturningStar `as` #deleted_rows)
193193 (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rows `as` #t)))))
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1−1
@@ -495,7 +495,7 @@ renderQualifiedAlias _ =
495495 qualifier = renderAlias (Alias @q)
496496 alias = renderAlias (Alias @a)
497497 in
498− if qualifier == "public" then alias else qualifier <> "." <> alias
498+ if qualifier == "\"public\"" then alias else qualifier <> "." <> alias
499499
500500-- | @Elem@ is a promoted `Data.List.elem`.
501501type family Elem x xs where