on dev help sign in
printSQL and docs
5f2840cEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+33−28
@@ -113,6 +113,9 @@ newtype Definition
113 = UnsafeDefinition { renderDefinition :: ByteString }
113 = UnsafeDefinition { renderDefinition :: ByteString }
114 deriving (GHC.Generic,Show,Eq,Ord,NFData)
114 deriving (GHC.Generic,Show,Eq,Ord,NFData)
115
115
116+instance RenderSQL (Definition schema0 schema1) where
117+ renderSQL = renderDefinition
118+
116instance Category Definition where
119instance Category Definition where
117 id = UnsafeDefinition ";"
120 id = UnsafeDefinition ";"
118 ddl1 . ddl0 = UnsafeDefinition $
121 ddl1 . ddl0 = UnsafeDefinition $
@@ -126,7 +129,7 @@ CREATE statements
126
129
127>>> :set -XOverloadedLabels
130>>> :set -XOverloadedLabels
128>>> :{
131>>> :{
129−Data.ByteString.Char8.putStrLn . renderDefinition $
132+printSQL $
130 createTable #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
133 createTable #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
131:}
134:}
132CREATE TABLE "tab" ("a" int NULL, "b" real NULL);
135CREATE TABLE "tab" ("a" int NULL, "b" real NULL);
@@ -154,8 +157,10 @@ Instead, the schema already has the table so if the table did not yet exist, the
154>>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
157>>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
155>>> type Schema = '["tab" ::: 'Table Table]
158>>> type Schema = '["tab" ::: 'Table Table]
156>>> :{
159>>> :{
157−Data.ByteString.Char8.putStrLn $ renderDefinition
160+let
161+ setup :: Definition Schema Schema
158− (createTableIfNotExists #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil :: Definition Schema Schema)
162+ setup = createTableIfNotExists #tab ((int & nullable) `As` #a :* (real & nullable) `As` #b :* Nil) Nil
163+in printSQL setup
159:}
164:}
160CREATE TABLE IF NOT EXISTS "tab" ("a" int NULL, "b" real NULL);
165CREATE TABLE IF NOT EXISTS "tab" ("a" int NULL, "b" real NULL);
161-}
166-}
@@ -243,7 +248,7 @@ let
243 ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
248 ( check (#a :* #b :* Nil) (#a .> #b) `As` #inequality :* Nil )
244:}
249:}
245
250
246−>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
251+>>> printSQL definition
247CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
252CREATE TABLE "tab" ("a" int NOT NULL, "b" int NOT NULL, CONSTRAINT "inequality" CHECK (("a" > "b")));
248-}
253-}
249check
254check
@@ -277,7 +282,7 @@ let
277 ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
282 ( unique (#a :* #b :* Nil) `As` #uq_a_b :* Nil )
278:}
283:}
279
284
280−>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
285+>>> printSQL definition
281CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
286CREATE TABLE "tab" ("a" int NULL, "b" int NULL, CONSTRAINT "uq_a_b" UNIQUE ("a", "b"));
282-}
287-}
283unique
288unique
@@ -310,7 +315,7 @@ let
310 ( primaryKey #id `As` #pk_id :* Nil )
315 ( primaryKey #id `As` #pk_id :* Nil )
311:}
316:}
312
317
313−>>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
318+>>> printSQL definition
314CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
319CREATE TABLE "tab" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_id" PRIMARY KEY ("id"));
315-}
320-}
316primaryKey
321primaryKey
@@ -361,7 +366,7 @@ let
361 ( primaryKey #id `As` #pk_emails :*
366 ( primaryKey #id `As` #pk_emails :*
362 foreignKey #user_id #users #id
367 foreignKey #user_id #users #id
363 OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
368 OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
364−in Data.ByteString.Char8.putStrLn $ renderDefinition setup
369+in printSQL setup
365:}
370:}
366CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
371CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
367CREATE TABLE "emails" ("id" serial, "user_id" int NOT NULL, "email" text NULL, CONSTRAINT "pk_emails" PRIMARY KEY ("id"), CONSTRAINT "fk_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE);
372CREATE TABLE "emails" ("id" serial, "user_id" int NOT NULL, "email" text NULL, CONSTRAINT "pk_emails" PRIMARY KEY ("id"), CONSTRAINT "fk_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE);
@@ -392,7 +397,7 @@ let
392 ( primaryKey #id `As` #employees_pk :*
397 ( primaryKey #id `As` #employees_pk :*
393 foreignKey #employer_id #employees #id
398 foreignKey #employer_id #employees #id
394 OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
399 OnDeleteCascade OnUpdateCascade `As` #employees_employer_fk :* Nil )
395−in Data.ByteString.Char8.putStrLn $ renderDefinition setup
400+in printSQL setup
396:}
401:}
397CREATE TABLE "employees" ("id" serial, "name" text NOT NULL, "employer_id" integer NULL, CONSTRAINT "employees_pk" PRIMARY KEY ("id"), CONSTRAINT "employees_employer_fk" FOREIGN KEY ("employer_id") REFERENCES "employees" ("id") ON DELETE CASCADE ON UPDATE CASCADE);
402CREATE TABLE "employees" ("id" serial, "name" text NOT NULL, "employer_id" integer NULL, CONSTRAINT "employees_pk" PRIMARY KEY ("id"), CONSTRAINT "employees_employer_fk" FOREIGN KEY ("employer_id") REFERENCES "employees" ("id") ON DELETE CASCADE ON UPDATE CASCADE);
398-}
403-}
@@ -487,7 +492,7 @@ DROP statements
487-- definition = dropTable #muh_table
492-- definition = dropTable #muh_table
488-- :}
493-- :}
489--
494--
490−-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition definition
495+-- >>> printSQL definition
491-- DROP TABLE "muh_table";
496-- DROP TABLE "muh_table";
492dropTable
497dropTable
493 :: Has table schema ('Table t)
498 :: Has table schema ('Table t)
@@ -513,7 +518,7 @@ alterTable tab alteration = UnsafeDefinition $
513
518
514-- | `alterTableRename` changes the name of a table from the schema.
519-- | `alterTableRename` changes the name of a table from the schema.
515--
520--
516−-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ alterTableRename #foo #bar
521+-- >>> printSQL $ alterTableRename #foo #bar
517-- ALTER TABLE "foo" RENAME TO "bar";
522-- ALTER TABLE "foo" RENAME TO "bar";
518alterTableRename
523alterTableRename
519 :: (KnownSymbol table0, KnownSymbol table1)
524 :: (KnownSymbol table0, KnownSymbol table1)
@@ -541,7 +546,7 @@ newtype AlterTable
541-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
546-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
542-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
547-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
543-- definition = alterTable #tab (addConstraint #positive (check (#col :* Nil) (#col .> 0)))
548-- definition = alterTable #tab (addConstraint #positive (check (#col :* Nil) (#col .> 0)))
544−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
549+-- in printSQL definition
545-- :}
550-- :}
546-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
551-- ALTER TABLE "tab" ADD CONSTRAINT "positive" CHECK (("col" > 0));
547addConstraint
552addConstraint
@@ -565,7 +570,7 @@ addConstraint alias constraint = UnsafeAlterTable $
565-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
570-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
566-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
571-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
567-- definition = alterTable #tab (dropConstraint #positive)
572-- definition = alterTable #tab (dropConstraint #positive)
568−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
573+-- in printSQL definition
569-- :}
574-- :}
570-- ALTER TABLE "tab" DROP CONSTRAINT "positive";
575-- ALTER TABLE "tab" DROP CONSTRAINT "positive";
571dropConstraint
576dropConstraint
@@ -592,7 +597,7 @@ class AddColumn ty where
592 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
597 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
593 -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]
598 -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]
594 -- definition = alterTable #tab (addColumn #col2 (text & nullable & default_ "foo"))
599 -- definition = alterTable #tab (addColumn #col2 (text & nullable & default_ "foo"))
595− -- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
600+ -- in printSQL definition
596 -- :}
601 -- :}
597 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL DEFAULT E'foo';
602 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL DEFAULT E'foo';
598 --
603 --
@@ -604,7 +609,7 @@ class AddColumn ty where
604 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
609 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
605 -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
610 -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
606 -- definition = alterTable #tab (addColumn #col2 (text & nullable))
611 -- definition = alterTable #tab (addColumn #col2 (text & nullable))
607− -- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
612+ -- in printSQL definition
608 -- :}
613 -- :}
609 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
614 -- ALTER TABLE "tab" ADD COLUMN "col2" text NULL;
610 addColumn
615 addColumn
@@ -633,7 +638,7 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
633-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
638-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
634-- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
639-- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
635-- definition = alterTable #tab (dropColumn #col2)
640-- definition = alterTable #tab (dropColumn #col2)
636−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
641+-- in printSQL definition
637-- :}
642-- :}
638-- ALTER TABLE "tab" DROP COLUMN "col2";
643-- ALTER TABLE "tab" DROP COLUMN "col2";
639dropColumn
644dropColumn
@@ -654,7 +659,7 @@ dropColumn column = UnsafeAlterTable $
654-- '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]
659-- '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]
655-- '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]
660-- '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]
656-- definition = alterTable #tab (renameColumn #foo #bar)
661-- definition = alterTable #tab (renameColumn #foo #bar)
657−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
662+-- in printSQL definition
658-- :}
663-- :}
659-- ALTER TABLE "tab" RENAME COLUMN "foo" TO "bar";
664-- ALTER TABLE "tab" RENAME COLUMN "foo" TO "bar";
660renameColumn
665renameColumn
@@ -697,7 +702,7 @@ newtype AlterColumn (schema :: SchemaType) (ty0 :: ColumnType) (ty1 :: ColumnTyp
697-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
702-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
698-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
703-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
699-- definition = alterTable #tab (alterColumn #col (setDefault 5))
704-- definition = alterTable #tab (alterColumn #col (setDefault 5))
700−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
705+-- in printSQL definition
701-- :}
706-- :}
702-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
707-- ALTER TABLE "tab" ALTER COLUMN "col" SET DEFAULT 5;
703setDefault
708setDefault
@@ -714,7 +719,7 @@ setDefault expression = UnsafeAlterColumn $
714-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
719-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
715-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
720-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
716-- definition = alterTable #tab (alterColumn #col dropDefault)
721-- definition = alterTable #tab (alterColumn #col dropDefault)
717−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
722+-- in printSQL definition
718-- :}
723-- :}
719-- ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;
724-- ALTER TABLE "tab" ALTER COLUMN "col" DROP DEFAULT;
720dropDefault :: AlterColumn schema ('Def :=> ty) ('NoDef :=> ty)
725dropDefault :: AlterColumn schema ('Def :=> ty) ('NoDef :=> ty)
@@ -730,7 +735,7 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
730-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
735-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
731-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
736-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
732-- definition = alterTable #tab (alterColumn #col setNotNull)
737-- definition = alterTable #tab (alterColumn #col setNotNull)
733−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
738+-- in printSQL definition
734-- :}
739-- :}
735-- ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;
740-- ALTER TABLE "tab" ALTER COLUMN "col" SET NOT NULL;
736setNotNull
741setNotNull
@@ -745,7 +750,7 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
745-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
750-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
746-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
751-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
747-- definition = alterTable #tab (alterColumn #col dropNotNull)
752-- definition = alterTable #tab (alterColumn #col dropNotNull)
748−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
753+-- in printSQL definition
749-- :}
754-- :}
750-- ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;
755-- ALTER TABLE "tab" ALTER COLUMN "col" DROP NOT NULL;
751dropNotNull
756dropNotNull
@@ -763,7 +768,7 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
763-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]
768-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]
764-- definition =
769-- definition =
765-- alterTable #tab (alterColumn #col (alterType (numeric & notNullable)))
770-- alterTable #tab (alterColumn #col (alterType (numeric & notNullable)))
766−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
771+-- in printSQL definition
767-- :}
772-- :}
768-- ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;
773-- ALTER TABLE "tab" ALTER COLUMN "col" TYPE numeric NOT NULL;
769alterType :: ColumnTypeExpression schema ty -> AlterColumn schema ty0 ty
774alterType :: ColumnTypeExpression schema ty -> AlterColumn schema ty0 ty
@@ -779,7 +784,7 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
779-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
784-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
780-- definition =
785-- definition =
781-- createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
786-- createView #bc (select (#b :* #c :* Nil) (from (table #abc)))
782−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
787+-- in printSQL definition
783-- :}
788-- :}
784-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
789-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
785createView
790createView
@@ -801,7 +806,7 @@ createView alias query = UnsafeDefinition $
801-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
806-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
802-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
807-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
803-- definition = dropView #bc
808-- definition = dropView #bc
804−-- in Data.ByteString.Char8.putStrLn $ renderDefinition definition
809+-- in printSQL definition
805-- :}
810-- :}
806-- DROP VIEW "bc";
811-- DROP VIEW "bc";
807dropView
812dropView
@@ -812,7 +817,7 @@ dropView v = UnsafeDefinition $ "DROP VIEW" <+> renderAlias v <> ";"
812
817
813-- | Enumerated types are created using the `createTypeEnum` command, for example
818-- | Enumerated types are created using the `createTypeEnum` command, for example
814--
819--
815−-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
820+-- >>> printSQL $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy" :* Nil)
816-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
821-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
817createTypeEnum
822createTypeEnum
818 :: (KnownSymbol enum, SOP.All KnownSymbol labels)
823 :: (KnownSymbol enum, SOP.All KnownSymbol labels)
@@ -830,7 +835,7 @@ createTypeEnum enum labels = UnsafeDefinition $
830-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
835-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
831-- >>> instance SOP.Generic Schwarma
836-- >>> instance SOP.Generic Schwarma
832-- >>> instance SOP.HasDatatypeInfo Schwarma
837-- >>> instance SOP.HasDatatypeInfo Schwarma
833−-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeEnumWith @Schwarma #schwarma
838+-- >>> printSQL $ createTypeEnumWith @Schwarma #schwarma
834-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
839-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
835createTypeEnumWith
840createTypeEnumWith
836 :: forall hask enum schema.
841 :: forall hask enum schema.
@@ -847,7 +852,7 @@ createTypeEnumWith enum = createTypeEnum enum
847-- | `createTypeComposite` creates a composite type. The composite type is
852-- | `createTypeComposite` creates a composite type. The composite type is
848-- specified by a list of attribute names and data types.
853-- specified by a list of attribute names and data types.
849--
854--
850−-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeComposite #complex (float8 `As` #real :* float8 `As` #imaginary :* Nil)
855+-- >>> printSQL $ createTypeComposite #complex (float8 `As` #real :* float8 `As` #imaginary :* Nil)
851-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
856-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
852createTypeComposite
857createTypeComposite
853 :: (KnownSymbol ty, SOP.SListI fields)
858 :: (KnownSymbol ty, SOP.SListI fields)
@@ -869,7 +874,7 @@ createTypeComposite ty fields = UnsafeDefinition $
869-- >>> data Complex = Complex {real :: Maybe Double, imaginary :: Maybe Double} deriving GHC.Generic
874-- >>> data Complex = Complex {real :: Maybe Double, imaginary :: Maybe Double} deriving GHC.Generic
870-- >>> instance SOP.Generic Complex
875-- >>> instance SOP.Generic Complex
871-- >>> instance SOP.HasDatatypeInfo Complex
876-- >>> instance SOP.HasDatatypeInfo Complex
872−-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition $ createTypeCompositeWith @Complex #complex
877+-- >>> printSQL $ createTypeCompositeWith @Complex #complex
873-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
878-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
874createTypeCompositeWith
879createTypeCompositeWith
875 :: forall hask ty schema.
880 :: forall hask ty schema.
@@ -890,7 +895,7 @@ createTypeCompositeWith ty = createTypeComposite ty $ zipAs
890-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
895-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
891-- >>> instance SOP.Generic Schwarma
896-- >>> instance SOP.Generic Schwarma
892-- >>> instance SOP.HasDatatypeInfo Schwarma
897-- >>> instance SOP.HasDatatypeInfo Schwarma
893−-- >>> Data.ByteString.Char8.putStrLn $ renderDefinition (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (EnumWith Schwarma)] '[])
898+-- >>> printSQL (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (EnumWith Schwarma)] '[])
894-- DROP TYPE "schwarma";
899-- DROP TYPE "schwarma";
895dropType
900dropType
896 :: Has tydef schema ('Typedef ty)
901 :: Has tydef schema ('Typedef ty)
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+128−122
@@ -172,6 +172,9 @@ newtype Expression
172 = UnsafeExpression { renderExpression :: ByteString }
172 = UnsafeExpression { renderExpression :: ByteString }
173 deriving (GHC.Generic,Show,Eq,Ord,NFData)
173 deriving (GHC.Generic,Show,Eq,Ord,NFData)
174
174
175+instance RenderSQL (Expression schema relations grouping params ty) where
176+ renderSQL = renderExpression
177+
175{- | A `HasParameter` constraint is used to indicate a value that is
178{- | A `HasParameter` constraint is used to indicate a value that is
176supplied externally to a SQL statement.
179supplied externally to a SQL statement.
177`Squeal.PostgreSQL.PQ.manipulateParams`,
180`Squeal.PostgreSQL.PQ.manipulateParams`,
@@ -278,15 +281,15 @@ instance
278
281
279-- | analagous to `Nothing`
282-- | analagous to `Nothing`
280--
283--
281−-- >>> renderExpression $ null_
284+-- >>> printSQL null_
282−-- "NULL"
285+-- NULL
283null_ :: Expression schema rels grouping params ('Null ty)
286null_ :: Expression schema rels grouping params ('Null ty)
284null_ = UnsafeExpression "NULL"
287null_ = UnsafeExpression "NULL"
285
288
286-- | analagous to `Just`
289-- | analagous to `Just`
287--
290--
288−-- >>> renderExpression $ notNull true
291+-- >>> printSQL $ notNull true
289−-- "TRUE"
292+-- TRUE
290notNull
293notNull
291 :: Expression schema rels grouping params ('NotNull ty)
294 :: Expression schema rels grouping params ('NotNull ty)
292 -> Expression schema rels grouping params ('Null ty)
295 -> Expression schema rels grouping params ('Null ty)
@@ -294,8 +297,8 @@ notNull = UnsafeExpression . renderExpression
294
297
295-- | return the leftmost value which is not NULL
298-- | return the leftmost value which is not NULL
296--
299--
297−-- >>> renderExpression $ coalesce [null_, notNull true] false
300+-- >>> printSQL $ coalesce [null_, notNull true] false
298−-- "COALESCE(NULL, TRUE, FALSE)"
301+-- COALESCE(NULL, TRUE, FALSE)
299coalesce
302coalesce
300 :: [Expression schema relations grouping params ('Null ty)]
303 :: [Expression schema relations grouping params ('Null ty)]
301 -- ^ @NULL@s may be present
304 -- ^ @NULL@s may be present
@@ -308,8 +311,8 @@ coalesce nullxs notNullx = UnsafeExpression $
308
311
309-- | analagous to `Data.Maybe.fromMaybe` using @COALESCE@
312-- | analagous to `Data.Maybe.fromMaybe` using @COALESCE@
310--
313--
311−-- >>> renderExpression $ fromNull true null_
314+-- >>> printSQL $ fromNull true null_
312−-- "COALESCE(NULL, TRUE)"
315+-- COALESCE(NULL, TRUE)
313fromNull
316fromNull
314 :: Expression schema relations grouping params ('NotNull ty)
317 :: Expression schema relations grouping params ('NotNull ty)
315 -- ^ what to convert @NULL@ to
318 -- ^ what to convert @NULL@ to
@@ -317,16 +320,16 @@ fromNull
317 -> Expression schema relations grouping params ('NotNull ty)
320 -> Expression schema relations grouping params ('NotNull ty)
318fromNull notNullx nullx = coalesce [nullx] notNullx
321fromNull notNullx nullx = coalesce [nullx] notNullx
319
322
320−-- | >>> renderExpression $ null_ & isNull
323+-- | >>> printSQL $ null_ & isNull
321−-- "NULL IS NULL"
324+-- NULL IS NULL
322isNull
325isNull
323 :: Expression schema relations grouping params ('Null ty)
326 :: Expression schema relations grouping params ('Null ty)
324 -- ^ possibly @NULL@
327 -- ^ possibly @NULL@
325 -> Condition schema relations grouping params
328 -> Condition schema relations grouping params
326isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
329isNull x = UnsafeExpression $ renderExpression x <+> "IS NULL"
327
330
328−-- | >>> renderExpression $ null_ & isNotNull
331+-- | >>> printSQL $ null_ & isNotNull
329−-- "NULL IS NOT NULL"
332+-- NULL IS NOT NULL
330isNotNull
333isNotNull
331 :: Expression schema relations grouping params ('Null ty)
334 :: Expression schema relations grouping params ('Null ty)
332 -- ^ possibly @NULL@
335 -- ^ possibly @NULL@
@@ -335,8 +338,8 @@ isNotNull x = UnsafeExpression $ renderExpression x <+> "IS NOT NULL"
335
338
336-- | analagous to `maybe` using @IS NULL@
339-- | analagous to `maybe` using @IS NULL@
337--
340--
338−-- >>> renderExpression $ matchNull true not_ null_
341+-- >>> printSQL $ matchNull true not_ null_
339−-- "CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END"
342+-- CASE WHEN NULL IS NULL THEN TRUE ELSE (NOT NULL) END
340matchNull
343matchNull
341 :: Expression schema relations grouping params (nullty)
344 :: Expression schema relations grouping params (nullty)
342 -- ^ what to convert @NULL@ to
345 -- ^ what to convert @NULL@ to
@@ -348,12 +351,14 @@ matchNull
348matchNull y f x = ifThenElse (isNull x) y
351matchNull y f x = ifThenElse (isNull x) y
349 (f (UnsafeExpression (renderExpression x)))
352 (f (UnsafeExpression (renderExpression x)))
350
353
351−-- | right inverse to `fromNull`, if its arguments are equal then
354+{-| right inverse to `fromNull`, if its arguments are equal then
352−-- `nullIf` gives @NULL@.
355+`nullIf` gives @NULL@.
353−--
356+
354−-- >>> :set -XTypeApplications -XDataKinds
357+>>> :set -XTypeApplications -XDataKinds
355−-- >>> renderExpression @'[] @_ @_ @'[_] $ fromNull false (nullIf false (param @1))
358+>>> let expr = nullIf false (param @1) :: Expression schema rels grp '[ 'NotNull 'PGbool] ('Null 'PGbool)
359+>>> printSQL expr
356−-- "COALESCE(NULL IF (FALSE, ($1 :: bool)), FALSE)"
360+NULL IF (FALSE, ($1 :: bool))
361+-}
357nullIf
362nullIf
358 :: Expression schema relations grouping params ('NotNull ty)
363 :: Expression schema relations grouping params ('NotNull ty)
359 -- ^ @NULL@ is absent
364 -- ^ @NULL@ is absent
@@ -363,8 +368,8 @@ nullIf
363nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
368nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
364 (renderExpression x <> ", " <> renderExpression y)
369 (renderExpression x <> ", " <> renderExpression y)
365
370
366−-- | >>> renderExpression $ array [null_, notNull false, notNull true]
371+-- | >>> printSQL $ array [null_, notNull false, notNull true]
367−-- "ARRAY[NULL, FALSE, TRUE]"
372+-- ARRAY[NULL, FALSE, TRUE]
368array
373array
369 :: [Expression schema relations grouping params ('Null ty)]
374 :: [Expression schema relations grouping params ('Null ty)]
370 -- ^ array elements
375 -- ^ array elements
@@ -381,8 +386,8 @@ instance (KnownSymbol label, label `In` labels) => IsPGlabel label
381--
386--
382-- >>> type Complex = PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
387-- >>> type Complex = PGcomposite '["real" ::: 'PGfloat8, "imaginary" ::: 'PGfloat8]
383-- >>> let i = row (0 `As` #real :* 1 `As` #imaginary :* Nil) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
388-- >>> let i = row (0 `As` #real :* 1 `As` #imaginary :* Nil) :: Expression '[] '[] 'Ungrouped '[] ('NotNull Complex)
384−-- >>> renderExpression i
389+-- >>> printSQL i
385−-- "ROW(0, 1)"
390+-- ROW(0, 1)
386row
391row
387 :: SListI (Nulls fields)
392 :: SListI (Nulls fields)
388 => NP (Aliased (Expression schema relations grouping params)) (Nulls fields)
393 => NP (Aliased (Expression schema relations grouping params)) (Nulls fields)
@@ -407,8 +412,9 @@ instance Monoid
407 mempty = array []
412 mempty = array []
408 mappend = (<>)
413 mappend = (<>)
409
414
410−-- | >>> renderExpression @'[] @_ @_ @'[_] $ greatest currentTimestamp [param @1]
415+-- | >>> let expr = greatest currentTimestamp [param @1] :: Expression sch rels grp '[ 'NotNull 'PGtimestamptz] ('NotNull 'PGtimestamptz)
416+-- >>> printSQL expr
411−-- "GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))"
417+-- GREATEST(CURRENT_TIMESTAMP, ($1 :: timestamp with time zone))
412greatest
418greatest
413 :: Expression schema relations grouping params (nullty)
419 :: Expression schema relations grouping params (nullty)
414 -- ^ needs at least 1 argument
420 -- ^ needs at least 1 argument
@@ -418,8 +424,8 @@ greatest
418greatest x xs = UnsafeExpression $ "GREATEST("
424greatest x xs = UnsafeExpression $ "GREATEST("
419 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
425 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
420
426
421−-- | >>> renderExpression $ least currentTimestamp [null_]
427+-- | >>> printSQL $ least currentTimestamp [null_]
422−-- "LEAST(CURRENT_TIMESTAMP, NULL)"
428+-- LEAST(CURRENT_TIMESTAMP, NULL)
423least
429least
424 :: Expression schema relations grouping params (nullty)
430 :: Expression schema relations grouping params (nullty)
425 -- ^ needs at least 1 argument
431 -- ^ needs at least 1 argument
@@ -429,8 +435,8 @@ least
429least x xs = UnsafeExpression $ "LEAST("
435least x xs = UnsafeExpression $ "LEAST("
430 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
436 <> commaSeparated (renderExpression <$> (x:xs)) <> ")"
431
437
432−-- | >>> renderExpression $ unsafeBinaryOp "OR" true false
438+-- | >>> printSQL $ unsafeBinaryOp "OR" true false
433−-- "(TRUE OR FALSE)"
439+-- (TRUE OR FALSE)
434unsafeBinaryOp
440unsafeBinaryOp
435 :: ByteString
441 :: ByteString
436 -- ^ operator
442 -- ^ operator
@@ -440,8 +446,8 @@ unsafeBinaryOp
440unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
446unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
441 renderExpression x <+> op <+> renderExpression y
447 renderExpression x <+> op <+> renderExpression y
442
448
443−-- | >>> renderExpression $ unsafeUnaryOp "NOT" true
449+-- | >>> printSQL $ unsafeUnaryOp "NOT" true
444−-- "(NOT TRUE)"
450+-- (NOT TRUE)
445unsafeUnaryOp
451unsafeUnaryOp
446 :: ByteString
452 :: ByteString
447 -- ^ operator
453 -- ^ operator
@@ -450,8 +456,8 @@ unsafeUnaryOp
450unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
456unsafeUnaryOp op x = UnsafeExpression $ parenthesized $
451 op <+> renderExpression x
457 op <+> renderExpression x
452
458
453−-- | >>> renderExpression $ unsafeFunction "f" true
459+-- | >>> printSQL $ unsafeFunction "f" true
454−-- "f(TRUE)"
460+-- f(TRUE)
455unsafeFunction
461unsafeFunction
456 :: ByteString
462 :: ByteString
457 -- ^ function
463 -- ^ function
@@ -503,9 +509,9 @@ instance (PGNum ty, PGFloating ty) => Floating
503-- let
509-- let
504-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
510-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
505-- expression = atan2_ pi 2
511-- expression = atan2_ pi 2
506−-- in renderExpression expression
512+-- in printSQL expression
507-- :}
513-- :}
508−-- "atan2(pi(), 2)"
514+-- atan2(pi(), 2)
509atan2_
515atan2_
510 :: PGFloating float
516 :: PGFloating float
511 => Expression schema relations grouping params (nullity float)
517 => Expression schema relations grouping params (nullity float)
@@ -520,8 +526,8 @@ atan2_ y x = UnsafeExpression $
520-- represents a run-time type conversion. The cast will succeed only if a
526-- represents a run-time type conversion. The cast will succeed only if a
521-- suitable type conversion operation has been defined.
527-- suitable type conversion operation has been defined.
522--
528--
523−-- | >>> renderExpression $ true & cast int4
529+-- | >>> printSQL $ true & cast int4
524−-- "(TRUE :: int4)"
530+-- (TRUE :: int4)
525cast
531cast
526 :: TypeExpression schema ty1
532 :: TypeExpression schema ty1
527 -- ^ type to cast as
533 -- ^ type to cast as
@@ -537,9 +543,9 @@ cast ty x = UnsafeExpression $ parenthesized $
537-- let
543-- let
538-- expression :: Expression schema relations grouping params (nullity 'PGint2)
544-- expression :: Expression schema relations grouping params (nullity 'PGint2)
539-- expression = 5 `quot_` 2
545-- expression = 5 `quot_` 2
540−-- in renderExpression expression
546+-- in printSQL expression
541-- :}
547-- :}
542−-- "(5 / 2)"
548+-- (5 / 2)
543quot_
549quot_
544 :: PGIntegral int
550 :: PGIntegral int
545 => Expression schema relations grouping params (nullity int)
551 => Expression schema relations grouping params (nullity int)
@@ -555,9 +561,9 @@ quot_ = unsafeBinaryOp "/"
555-- let
561-- let
556-- expression :: Expression schema relations grouping params (nullity 'PGint2)
562-- expression :: Expression schema relations grouping params (nullity 'PGint2)
557-- expression = 5 `rem_` 2
563-- expression = 5 `rem_` 2
558−-- in renderExpression expression
564+-- in printSQL expression
559-- :}
565-- :}
560−-- "(5 % 2)"
566+-- (5 % 2)
561rem_
567rem_
562 :: PGIntegral int
568 :: PGIntegral int
563 => Expression schema relations grouping params (nullity int)
569 => Expression schema relations grouping params (nullity int)
@@ -571,9 +577,9 @@ rem_ = unsafeBinaryOp "%"
571-- let
577-- let
572-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
578-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
573-- expression = trunc pi
579-- expression = trunc pi
574−-- in renderExpression expression
580+-- in printSQL expression
575-- :}
581-- :}
576−-- "trunc(pi())"
582+-- trunc(pi())
577trunc
583trunc
578 :: PGFloating frac
584 :: PGFloating frac
579 => Expression schema relations grouping params (nullity frac)
585 => Expression schema relations grouping params (nullity frac)
@@ -585,9 +591,9 @@ trunc = unsafeFunction "trunc"
585-- let
591-- let
586-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
592-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
587-- expression = round_ pi
593-- expression = round_ pi
588−-- in renderExpression expression
594+-- in printSQL expression
589-- :}
595-- :}
590−-- "round(pi())"
596+-- round(pi())
591round_
597round_
592 :: PGFloating frac
598 :: PGFloating frac
593 => Expression schema relations grouping params (nullity frac)
599 => Expression schema relations grouping params (nullity frac)
@@ -599,9 +605,9 @@ round_ = unsafeFunction "round"
599-- let
605-- let
600-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
606-- expression :: Expression schema relations grouping params (nullity 'PGfloat4)
601-- expression = ceiling_ pi
607-- expression = ceiling_ pi
602−-- in renderExpression expression
608+-- in printSQL expression
603-- :}
609-- :}
604−-- "ceiling(pi())"
610+-- ceiling(pi())
605ceiling_
611ceiling_
606 :: PGFloating frac
612 :: PGFloating frac
607 => Expression schema relations grouping params (nullity frac)
613 => Expression schema relations grouping params (nullity frac)
@@ -616,33 +622,33 @@ ceiling_ = unsafeFunction "ceiling"
616type Condition schema relations grouping params =
622type Condition schema relations grouping params =
617 Expression schema relations grouping params ('NotNull 'PGbool)
623 Expression schema relations grouping params ('NotNull 'PGbool)
618
624
619−-- | >>> renderExpression true
625+-- | >>> printSQL true
620−-- "TRUE"
626+-- TRUE
621true :: Condition schema relations grouping params
627true :: Condition schema relations grouping params
622true = UnsafeExpression "TRUE"
628true = UnsafeExpression "TRUE"
623
629
624−-- | >>> renderExpression false
630+-- | >>> printSQL false
625−-- "FALSE"
631+-- FALSE
626false :: Condition schema relations grouping params
632false :: Condition schema relations grouping params
627false = UnsafeExpression "FALSE"
633false = UnsafeExpression "FALSE"
628
634
629−-- | >>> renderExpression $ not_ true
635+-- | >>> printSQL $ not_ true
630−-- "(NOT TRUE)"
636+-- (NOT TRUE)
631not_
637not_
632 :: Condition schema relations grouping params
638 :: Condition schema relations grouping params
633 -> Condition schema relations grouping params
639 -> Condition schema relations grouping params
634not_ = unsafeUnaryOp "NOT"
640not_ = unsafeUnaryOp "NOT"
635
641
636−-- | >>> renderExpression $ true .&& false
642+-- | >>> printSQL $ true .&& false
637−-- "(TRUE AND FALSE)"
643+-- (TRUE AND FALSE)
638(.&&)
644(.&&)
639 :: Condition schema relations grouping params
645 :: Condition schema relations grouping params
640 -> Condition schema relations grouping params
646 -> Condition schema relations grouping params
641 -> Condition schema relations grouping params
647 -> Condition schema relations grouping params
642(.&&) = unsafeBinaryOp "AND"
648(.&&) = unsafeBinaryOp "AND"
643
649
644−-- | >>> renderExpression $ true .|| false
650+-- | >>> printSQL $ true .|| false
645−-- "(TRUE OR FALSE)"
651+-- (TRUE OR FALSE)
646(.||)
652(.||)
647 :: Condition schema relations grouping params
653 :: Condition schema relations grouping params
648 -> Condition schema relations grouping params
654 -> Condition schema relations grouping params
@@ -653,9 +659,9 @@ not_ = unsafeUnaryOp "NOT"
653-- let
659-- let
654-- expression :: Expression schema relations grouping params (nullity 'PGint2)
660-- expression :: Expression schema relations grouping params (nullity 'PGint2)
655-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
661-- expression = caseWhenThenElse [(true, 1), (false, 2)] 3
656−-- in renderExpression expression
662+-- in printSQL expression
657-- :}
663-- :}
658−-- "CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END"
664+-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
659caseWhenThenElse
665caseWhenThenElse
660 :: [ ( Condition schema relations grouping params
666 :: [ ( Condition schema relations grouping params
661 , Expression schema relations grouping params (ty)
667 , Expression schema relations grouping params (ty)
@@ -681,9 +687,9 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
681-- let
687-- let
682-- expression :: Expression schema relations grouping params (nullity 'PGint2)
688-- expression :: Expression schema relations grouping params (nullity 'PGint2)
683-- expression = ifThenElse true 1 0
689-- expression = ifThenElse true 1 0
684−-- in renderExpression expression
690+-- in printSQL expression
685-- :}
691-- :}
686−-- "CASE WHEN TRUE THEN 1 ELSE 0 END"
692+-- CASE WHEN TRUE THEN 1 ELSE 0 END
687ifThenElse
693ifThenElse
688 :: Condition schema relations grouping params
694 :: Condition schema relations grouping params
689 -> Expression schema relations grouping params (ty) -- ^ then
695 -> Expression schema relations grouping params (ty) -- ^ then
@@ -694,8 +700,8 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
694-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
700-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
695-- will produce @NULL@s if one of their arguments is @NULL@.
701-- will produce @NULL@s if one of their arguments is @NULL@.
696--
702--
697−-- >>> renderExpression $ notNull true .== null_
703+-- >>> printSQL $ notNull true .== null_
698−-- "(TRUE = NULL)"
704+-- (TRUE = NULL)
699(.==)
705(.==)
700 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
706 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
701 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
707 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
@@ -703,8 +709,8 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
703(.==) = unsafeBinaryOp "="
709(.==) = unsafeBinaryOp "="
704infix 4 .==
710infix 4 .==
705
711
706−-- | >>> renderExpression $ notNull true ./= null_
712+-- | >>> printSQL $ notNull true ./= null_
707−-- "(TRUE <> NULL)"
713+-- (TRUE <> NULL)
708(./=)
714(./=)
709 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
715 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
710 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
716 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
@@ -712,8 +718,8 @@ infix 4 .==
712(./=) = unsafeBinaryOp "<>"
718(./=) = unsafeBinaryOp "<>"
713infix 4 ./=
719infix 4 ./=
714
720
715−-- | >>> renderExpression $ notNull true .>= null_
721+-- | >>> printSQL $ notNull true .>= null_
716−-- "(TRUE >= NULL)"
722+-- (TRUE >= NULL)
717(.>=)
723(.>=)
718 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
724 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
719 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
725 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
@@ -721,8 +727,8 @@ infix 4 ./=
721(.>=) = unsafeBinaryOp ">="
727(.>=) = unsafeBinaryOp ">="
722infix 4 .>=
728infix 4 .>=
723
729
724−-- | >>> renderExpression $ notNull true .< null_
730+-- | >>> printSQL $ notNull true .< null_
725−-- "(TRUE < NULL)"
731+-- (TRUE < NULL)
726(.<)
732(.<)
727 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
733 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
728 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
734 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
@@ -730,8 +736,8 @@ infix 4 .>=
730(.<) = unsafeBinaryOp "<"
736(.<) = unsafeBinaryOp "<"
731infix 4 .<
737infix 4 .<
732
738
733−-- | >>> renderExpression $ notNull true .<= null_
739+-- | >>> printSQL $ notNull true .<= null_
734−-- "(TRUE <= NULL)"
740+-- (TRUE <= NULL)
735(.<=)
741(.<=)
736 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
742 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
737 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
743 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
@@ -739,8 +745,8 @@ infix 4 .<
739(.<=) = unsafeBinaryOp "<="
745(.<=) = unsafeBinaryOp "<="
740infix 4 .<=
746infix 4 .<=
741
747
742−-- | >>> renderExpression $ notNull true .> null_
748+-- | >>> printSQL $ notNull true .> null_
743−-- "(TRUE > NULL)"
749+-- (TRUE > NULL)
744(.>)
750(.>)
745 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
751 :: Expression schema relations grouping params (nullity ty) -- ^ lhs
746 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
752 -> Expression schema relations grouping params (nullity ty) -- ^ rhs
@@ -748,32 +754,32 @@ infix 4 .<=
748(.>) = unsafeBinaryOp ">"
754(.>) = unsafeBinaryOp ">"
749infix 4 .>
755infix 4 .>
750
756
751−-- | >>> renderExpression currentDate
757+-- | >>> printSQL currentDate
752−-- "CURRENT_DATE"
758+-- CURRENT_DATE
753currentDate
759currentDate
754 :: Expression schema relations grouping params (nullity 'PGdate)
760 :: Expression schema relations grouping params (nullity 'PGdate)
755currentDate = UnsafeExpression "CURRENT_DATE"
761currentDate = UnsafeExpression "CURRENT_DATE"
756
762
757−-- | >>> renderExpression currentTime
763+-- | >>> printSQL currentTime
758−-- "CURRENT_TIME"
764+-- CURRENT_TIME
759currentTime
765currentTime
760 :: Expression schema relations grouping params (nullity 'PGtimetz)
766 :: Expression schema relations grouping params (nullity 'PGtimetz)
761currentTime = UnsafeExpression "CURRENT_TIME"
767currentTime = UnsafeExpression "CURRENT_TIME"
762
768
763−-- | >>> renderExpression currentTimestamp
769+-- | >>> printSQL currentTimestamp
764−-- "CURRENT_TIMESTAMP"
770+-- CURRENT_TIMESTAMP
765currentTimestamp
771currentTimestamp
766 :: Expression schema relations grouping params (nullity 'PGtimestamptz)
772 :: Expression schema relations grouping params (nullity 'PGtimestamptz)
767currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
773currentTimestamp = UnsafeExpression "CURRENT_TIMESTAMP"
768
774
769−-- | >>> renderExpression localTime
775+-- | >>> printSQL localTime
770−-- "LOCALTIME"
776+-- LOCALTIME
771localTime
777localTime
772 :: Expression schema relations grouping params (nullity 'PGtime)
778 :: Expression schema relations grouping params (nullity 'PGtime)
773localTime = UnsafeExpression "LOCALTIME"
779localTime = UnsafeExpression "LOCALTIME"
774
780
775−-- | >>> renderExpression localTimestamp
781+-- | >>> printSQL localTimestamp
776−-- "LOCALTIMESTAMP"
782+-- LOCALTIMESTAMP
777localTimestamp
783localTimestamp
778 :: Expression schema relations grouping params (nullity 'PGtimestamp)
784 :: Expression schema relations grouping params (nullity 'PGtimestamp)
779localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
785localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
@@ -807,24 +813,24 @@ instance Monoid
807 mempty = fromString ""
813 mempty = fromString ""
808 mappend = (<>)
814 mappend = (<>)
809
815
810−-- | >>> renderExpression $ lower "ARRRGGG"
816+-- | >>> printSQL $ lower "ARRRGGG"
811−-- "lower(E'ARRRGGG')"
817+-- lower(E'ARRRGGG')
812lower
818lower
813 :: Expression schema relations grouping params (nullity 'PGtext)
819 :: Expression schema relations grouping params (nullity 'PGtext)
814 -- ^ string to lower case
820 -- ^ string to lower case
815 -> Expression schema relations grouping params (nullity 'PGtext)
821 -> Expression schema relations grouping params (nullity 'PGtext)
816lower = unsafeFunction "lower"
822lower = unsafeFunction "lower"
817
823
818−-- | >>> renderExpression $ upper "eeee"
824+-- | >>> printSQL $ upper "eeee"
819−-- "upper(E'eeee')"
825+-- upper(E'eeee')
820upper
826upper
821 :: Expression schema relations grouping params (nullity 'PGtext)
827 :: Expression schema relations grouping params (nullity 'PGtext)
822 -- ^ string to upper case
828 -- ^ string to upper case
823 -> Expression schema relations grouping params (nullity 'PGtext)
829 -> Expression schema relations grouping params (nullity 'PGtext)
824upper = unsafeFunction "upper"
830upper = unsafeFunction "upper"
825
831
826−-- | >>> renderExpression $ charLength "four"
832+-- | >>> printSQL $ charLength "four"
827−-- "char_length(E'four')"
833+-- char_length(E'four')
828charLength
834charLength
829 :: Expression schema relations grouping params (nullity 'PGtext)
835 :: Expression schema relations grouping params (nullity 'PGtext)
830 -- ^ string to measure
836 -- ^ string to measure
@@ -838,8 +844,8 @@ charLength = unsafeFunction "char_length"
838-- in pattern stands for (matches) any single character; a percent sign (%)
844-- in pattern stands for (matches) any single character; a percent sign (%)
839-- matches any sequence of zero or more characters.
845-- matches any sequence of zero or more characters.
840--
846--
841−-- >>> renderExpression $ "abc" `like` "a%"
847+-- >>> printSQL $ "abc" `like` "a%"
842−-- "(E'abc' LIKE E'a%')"
848+-- (E'abc' LIKE E'a%')
843like
849like
844 :: Expression schema relations grouping params (nullity 'PGtext)
850 :: Expression schema relations grouping params (nullity 'PGtext)
845 -- ^ string
851 -- ^ string
@@ -872,9 +878,9 @@ unsafeAggregateDistinct fun x = UnsafeExpression $ mconcat
872-- let
878-- let
873-- expression :: Expression schema '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
879-- expression :: Expression schema '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Grouped bys) params ('Null 'PGnumeric)
874-- expression = sum_ #col
880-- expression = sum_ #col
875−-- in renderExpression expression
881+-- in printSQL expression
876-- :}
882-- :}
877−-- "sum(\"col\")"
883+-- sum("col")
878sum_
884sum_
879 :: PGNum ty
885 :: PGNum ty
880 => Expression schema relations 'Ungrouped params (nullity ty)
886 => Expression schema relations 'Ungrouped params (nullity ty)
@@ -886,9 +892,9 @@ sum_ = unsafeAggregate "sum"
886-- let
892-- let
887-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
893-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGnumeric]] ('Grouped bys) params (nullity 'PGnumeric)
888-- expression = sumDistinct #col
894-- expression = sumDistinct #col
889−-- in renderExpression expression
895+-- in printSQL expression
890-- :}
896-- :}
891−-- "sum(DISTINCT \"col\")"
897+-- sum(DISTINCT "col")
892sumDistinct
898sumDistinct
893 :: PGNum ty
899 :: PGNum ty
894 => Expression schema relations 'Ungrouped params (nullity ty)
900 => Expression schema relations 'Ungrouped params (nullity ty)
@@ -917,9 +923,9 @@ instance PGAvg 'PGinterval 'PGinterval
917-- let
923-- let
918-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
924-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
919-- expression = bitAnd #col
925-- expression = bitAnd #col
920−-- in renderExpression expression
926+-- in printSQL expression
921-- :}
927-- :}
922−-- "bit_and(\"col\")"
928+-- bit_and("col")
923bitAnd
929bitAnd
924 :: PGIntegral int
930 :: PGIntegral int
925 => Expression schema relations 'Ungrouped params (nullity int)
931 => Expression schema relations 'Ungrouped params (nullity int)
@@ -931,9 +937,9 @@ bitAnd = unsafeAggregate "bit_and"
931-- let
937-- let
932-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
938-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
933-- expression = bitOr #col
939-- expression = bitOr #col
934−-- in renderExpression expression
940+-- in printSQL expression
935-- :}
941-- :}
936−-- "bit_or(\"col\")"
942+-- bit_or("col")
937bitOr
943bitOr
938 :: PGIntegral int
944 :: PGIntegral int
939 => Expression schema relations 'Ungrouped params (nullity int)
945 => Expression schema relations 'Ungrouped params (nullity int)
@@ -945,9 +951,9 @@ bitOr = unsafeAggregate "bit_or"
945-- let
951-- let
946-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
952-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
947-- expression = bitAndDistinct #col
953-- expression = bitAndDistinct #col
948−-- in renderExpression expression
954+-- in printSQL expression
949-- :}
955-- :}
950−-- "bit_and(DISTINCT \"col\")"
956+-- bit_and(DISTINCT "col")
951bitAndDistinct
957bitAndDistinct
952 :: PGIntegral int
958 :: PGIntegral int
953 => Expression schema relations 'Ungrouped params (nullity int)
959 => Expression schema relations 'Ungrouped params (nullity int)
@@ -959,9 +965,9 @@ bitAndDistinct = unsafeAggregateDistinct "bit_and"
959-- let
965-- let
960-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
966-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGint4]] (Grouped bys) params (nullity 'PGint4)
961-- expression = bitOrDistinct #col
967-- expression = bitOrDistinct #col
962−-- in renderExpression expression
968+-- in printSQL expression
963-- :}
969-- :}
964−-- "bit_or(DISTINCT \"col\")"
970+-- bit_or(DISTINCT "col")
965bitOrDistinct
971bitOrDistinct
966 :: PGIntegral int
972 :: PGIntegral int
967 => Expression schema relations 'Ungrouped params (nullity int)
973 => Expression schema relations 'Ungrouped params (nullity int)
@@ -973,9 +979,9 @@ bitOrDistinct = unsafeAggregateDistinct "bit_or"
973-- let
979-- let
974-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
980-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
975-- expression = boolAnd #col
981-- expression = boolAnd #col
976−-- in renderExpression expression
982+-- in printSQL expression
977-- :}
983-- :}
978−-- "bool_and(\"col\")"
984+-- bool_and("col")
979boolAnd
985boolAnd
980 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
986 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
981 -- ^ what to aggregate
987 -- ^ what to aggregate
@@ -986,9 +992,9 @@ boolAnd = unsafeAggregate "bool_and"
986-- let
992-- let
987-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
993-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
988-- expression = boolOr #col
994-- expression = boolOr #col
989−-- in renderExpression expression
995+-- in printSQL expression
990-- :}
996-- :}
991−-- "bool_or(\"col\")"
997+-- bool_or("col")
992boolOr
998boolOr
993 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
999 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
994 -- ^ what to aggregate
1000 -- ^ what to aggregate
@@ -999,9 +1005,9 @@ boolOr = unsafeAggregate "bool_or"
999-- let
1005-- let
1000-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1006-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1001-- expression = boolAndDistinct #col
1007-- expression = boolAndDistinct #col
1002−-- in renderExpression expression
1008+-- in printSQL expression
1003-- :}
1009-- :}
1004−-- "bool_and(DISTINCT \"col\")"
1010+-- bool_and(DISTINCT "col")
1005boolAndDistinct
1011boolAndDistinct
1006 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1012 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1007 -- ^ what to aggregate
1013 -- ^ what to aggregate
@@ -1012,9 +1018,9 @@ boolAndDistinct = unsafeAggregateDistinct "bool_and"
1012-- let
1018-- let
1013-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1019-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1014-- expression = boolOrDistinct #col
1020-- expression = boolOrDistinct #col
1015−-- in renderExpression expression
1021+-- in printSQL expression
1016-- :}
1022-- :}
1017−-- "bool_or(DISTINCT \"col\")"
1023+-- bool_or(DISTINCT "col")
1018boolOrDistinct
1024boolOrDistinct
1019 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1025 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1020 -- ^ what to aggregate
1026 -- ^ what to aggregate
@@ -1023,8 +1029,8 @@ boolOrDistinct = unsafeAggregateDistinct "bool_or"
1023
1029
1024-- | A special aggregation that does not require an input
1030-- | A special aggregation that does not require an input
1025--
1031--
1026−-- >>> renderExpression countStar
1032+-- >>> printSQL countStar
1027−-- "count(*)"
1033+-- count(*)
1028countStar
1034countStar
1029 :: Expression schema relations ('Grouped bys) params ('NotNull 'PGint8)
1035 :: Expression schema relations ('Grouped bys) params ('NotNull 'PGint8)
1030countStar = UnsafeExpression $ "count(*)"
1036countStar = UnsafeExpression $ "count(*)"
@@ -1033,9 +1039,9 @@ countStar = UnsafeExpression $ "count(*)"
1033-- let
1039-- let
1034-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1040-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1035-- expression = count #col
1041-- expression = count #col
1036−-- in renderExpression expression
1042+-- in printSQL expression
1037-- :}
1043-- :}
1038−-- "count(\"col\")"
1044+-- count("col")
1039count
1045count
1040 :: Expression schema relations 'Ungrouped params ty
1046 :: Expression schema relations 'Ungrouped params ty
1041 -- ^ what to count
1047 -- ^ what to count
@@ -1046,9 +1052,9 @@ count = unsafeAggregate "count"
1046-- let
1052-- let
1047-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1053-- expression :: Expression schema '[tab ::: '["col" ::: nullity ty]] (Grouped bys) params ('NotNull 'PGint8)
1048-- expression = countDistinct #col
1054-- expression = countDistinct #col
1049−-- in renderExpression expression
1055+-- in printSQL expression
1050-- :}
1056-- :}
1051−-- "count(DISTINCT \"col\")"
1057+-- count(DISTINCT "col")
1052countDistinct
1058countDistinct
1053 :: Expression schema relations 'Ungrouped params ty
1059 :: Expression schema relations 'Ungrouped params ty
1054 -- ^ what to count
1060 -- ^ what to count
@@ -1061,9 +1067,9 @@ countDistinct = unsafeAggregateDistinct "count"
1061-- let
1067-- let
1062-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1068-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1063-- expression = every #col
1069-- expression = every #col
1064−-- in renderExpression expression
1070+-- in printSQL expression
1065-- :}
1071-- :}
1066−-- "every(\"col\")"
1072+-- every("col")
1067every
1073every
1068 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1074 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1069 -- ^ what to aggregate
1075 -- ^ what to aggregate
@@ -1076,9 +1082,9 @@ every = unsafeAggregate "every"
1076-- let
1082-- let
1077-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1083-- expression :: Expression schema '[tab ::: '["col" ::: nullity 'PGbool]] (Grouped bys) params (nullity 'PGbool)
1078-- expression = everyDistinct #col
1084-- expression = everyDistinct #col
1079−-- in renderExpression expression
1085+-- in printSQL expression
1080-- :}
1086-- :}
1081−-- "every(DISTINCT \"col\")"
1087+-- every(DISTINCT "col")
1082everyDistinct
1088everyDistinct
1083 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1089 :: Expression schema relations 'Ungrouped params (nullity 'PGbool)
1084 -- ^ what to aggregate
1090 -- ^ what to aggregate
squeal-postgresql/src/Squeal/PostgreSQL/Render.hs+12−1
@@ -9,7 +9,8 @@ Rendering helper functions.
9-}
9-}
10
10
11{-# LANGUAGE
11{-# LANGUAGE
12+ FlexibleContexts
12− MagicHash
13+ , MagicHash
13 , OverloadedStrings
14 , OverloadedStrings
14 , PolyKinds
15 , PolyKinds
15 , RankNTypes
16 , RankNTypes
@@ -25,8 +26,11 @@ module Squeal.PostgreSQL.Render
25 , renderCommaSeparated
26 , renderCommaSeparated
26 , renderCommaSeparatedMaybe
27 , renderCommaSeparatedMaybe
27 , renderNat
28 , renderNat
29+ , RenderSQL (..)
30+ , printSQL
28 ) where
31 ) where
29
32
33+import Control.Monad.Base
30import Data.ByteString (ByteString)
34import Data.ByteString (ByteString)
31import Data.Maybe
35import Data.Maybe
32import Data.Monoid ((<>))
36import Data.Monoid ((<>))
@@ -35,6 +39,7 @@ import GHC.Exts
35import GHC.TypeLits
39import GHC.TypeLits
36
40
37import qualified Data.ByteString as ByteString
41import qualified Data.ByteString as ByteString
42+import qualified Data.ByteString.Char8 as Char8
38
43
39-- | Parenthesize a `ByteString`.
44-- | Parenthesize a `ByteString`.
40parenthesized :: ByteString -> ByteString
45parenthesized :: ByteString -> ByteString
@@ -77,3 +82,9 @@ renderCommaSeparatedMaybe render
77-- | Render a promoted `Nat`.
82-- | Render a promoted `Nat`.
78renderNat :: KnownNat n => proxy n -> ByteString
83renderNat :: KnownNat n => proxy n -> ByteString
79renderNat (_ :: proxy n) = fromString (show (natVal' (proxy# :: Proxy# n)))
84renderNat (_ :: proxy n) = fromString (show (natVal' (proxy# :: Proxy# n)))
85+
86+class RenderSQL sql where
87+ renderSQL :: sql -> ByteString
88+
89+printSQL :: (RenderSQL sql, MonadBase IO io) => sql -> io ()
90+printSQL = liftBase . Char8.putStrLn . renderSQL