on dev help sign in
docs
0fcdcd0Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL.hs+1−1
@@ -83,7 +83,7 @@ let
83 OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
83 OnDeleteCascade OnUpdateCascade `As` #fk_user_id :* Nil )
84:}
84:}
85
85
86−We can easily see the generated SQL is unsuprising looking.
86+We can easily see the generated SQL is unsurprising looking.
87
87
88>>> printSQL setup
88>>> printSQL setup
89CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
89CREATE TABLE "users" ("id" serial, "name" text NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"));
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+1−1
@@ -314,7 +314,7 @@ instance ToParam x ty => ToAliasedParam x (alias ::: ty) where
314 Just x -> K . Just . unK $ toParam @x @ty x
314 Just x -> K . Just . unK $ toParam @x @ty x
315
315
316-- | A `ToColumnParam` constraint lifts the `ToParam` encoding
316-- | A `ToColumnParam` constraint lifts the `ToParam` encoding
317−-- of a `Type` to a `ColumnType`, encoding `Maybe`s to `Null`s. You should
317+-- of a `Type` to a `NullityType`, encoding `Maybe`s to `Null`s. You should
318-- not define instances of `ToColumnParam`, just use the provided instances.
318-- not define instances of `ToColumnParam`, just use the provided instances.
319class ToColumnParam (x :: Type) (ty :: NullityType) where
319class ToColumnParam (x :: Type) (ty :: NullityType) where
320 -- | >>> toColumnParam @Int16 @('NotNull 'PGint2) 0
320 -- | >>> toColumnParam @Int16 @('NotNull 'PGint2) 0
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+6−5
@@ -151,7 +151,8 @@ createTable tab columns constraints = UnsafeDefinition $
151
151
152{-| `createTableIfNotExists` creates a table if it doesn't exist, but does not add it to the schema.
152{-| `createTableIfNotExists` creates a table if it doesn't exist, but does not add it to the schema.
153Instead, the schema already has the table so if the table did not yet exist, the schema was wrong.
153Instead, the schema already has the table so if the table did not yet exist, the schema was wrong.
154−`createTableIfNotExists` fixes this. Interestingly, this property makes it an idempotent in the `Category` `Definition`.
154+`createTableIfNotExists` fixes this. Interestingly, this property makes it an idempotent in
155+the `Category` of `Definition`s.
155
156
156>>> :set -XOverloadedLabels -XTypeApplications
157>>> :set -XOverloadedLabels -XTypeApplications
157>>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
158>>> type Table = '[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGfloat4]
@@ -789,7 +790,7 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
789-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
790-- CREATE VIEW "bc" AS SELECT "b" AS "b", "c" AS "c" FROM "abc" AS "abc";
790createView
791createView
791 :: KnownSymbol view
792 :: KnownSymbol view
792− => Alias view -- ^ the name of the table to add
793+ => Alias view -- ^ the name of the view to add
793 -> Query schema '[] relation
794 -> Query schema '[] relation
794 -- ^ query
795 -- ^ query
795 -> Definition schema (Create view ('View relation) schema)
796 -> Definition schema (Create view ('View relation) schema)
@@ -932,19 +933,19 @@ default_ x ty = UnsafeColumnTypeExpression $
932 renderColumnTypeExpression ty <+> "DEFAULT" <+> renderExpression x
933 renderColumnTypeExpression ty <+> "DEFAULT" <+> renderExpression x
933
934
934-- | not a true type, but merely a notational convenience for creating
935-- | not a true type, but merely a notational convenience for creating
935−-- unique identifier columns with type `'PGint2`
936+-- unique identifier columns with type `PGint2`
936serial2, smallserial
937serial2, smallserial
937 :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint2)
938 :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint2)
938serial2 = UnsafeColumnTypeExpression "serial2"
939serial2 = UnsafeColumnTypeExpression "serial2"
939smallserial = UnsafeColumnTypeExpression "smallserial"
940smallserial = UnsafeColumnTypeExpression "smallserial"
940-- | not a true type, but merely a notational convenience for creating
941-- | not a true type, but merely a notational convenience for creating
941−-- unique identifier columns with type `'PGint4`
942+-- unique identifier columns with type `PGint4`
942serial4, serial
943serial4, serial
943 :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint4)
944 :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint4)
944serial4 = UnsafeColumnTypeExpression "serial4"
945serial4 = UnsafeColumnTypeExpression "serial4"
945serial = UnsafeColumnTypeExpression "serial"
946serial = UnsafeColumnTypeExpression "serial"
946-- | not a true type, but merely a notational convenience for creating
947-- | not a true type, but merely a notational convenience for creating
947−-- unique identifier columns with type `'PGint8`
948+-- unique identifier columns with type `PGint8`
948serial8, bigserial
949serial8, bigserial
949 :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint8)
950 :: ColumnTypeExpression schema ('Def :=> 'NotNull 'PGint8)
950serial8 = UnsafeColumnTypeExpression "serial8"
951serial8 = UnsafeColumnTypeExpression "serial8"
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+4−4
@@ -302,11 +302,11 @@ insertQuery_
302insertQuery_ tab query =
302insertQuery_ tab query =
303 insertQuery tab query OnConflictDoRaise (Returning Nil)
303 insertQuery tab query OnConflictDoRaise (Returning Nil)
304
304
305−-- | `ColumnValue`s are values to insert or update in a row
305+-- | `ColumnValue`s are values to insert or update in a row.
306-- `Same` updates with the same value.
306-- `Same` updates with the same value.
307−-- `Default` inserts or updates with the @DEFAULT@ value
307+-- `Default` inserts or updates with the @DEFAULT@ value.
308−-- `Set` a value to be an `Expression`, relative to the given
308+-- `Set` sets a value to be an `Expression`, which can refer to
309−-- row for an update, and closed for an insert.
309+-- existing value in the row for an update.
310data ColumnValue
310data ColumnValue
311 (schema :: SchemaType)
311 (schema :: SchemaType)
312 (columns :: RelationType)
312 (columns :: RelationType)
squeal-postgresql/src/Squeal/PostgreSQL/Render.hs+2
@@ -83,8 +83,10 @@ renderCommaSeparatedMaybe render
83renderNat :: KnownNat n => proxy n -> ByteString
83renderNat :: KnownNat n => proxy n -> ByteString
84renderNat (_ :: proxy n) = fromString (show (natVal' (proxy# :: Proxy# n)))
84renderNat (_ :: proxy n) = fromString (show (natVal' (proxy# :: Proxy# n)))
85
85
86+-- | A class for rendering SQL
86class RenderSQL sql where
87class RenderSQL sql where
87 renderSQL :: sql -> ByteString
88 renderSQL :: sql -> ByteString
88
89
90+-- | Print SQL.
89printSQL :: (RenderSQL sql, MonadBase IO io) => sql -> io ()
91printSQL :: (RenderSQL sql, MonadBase IO io) => sql -> io ()
90printSQL = liftBase . Char8.putStrLn . renderSQL
92printSQL = liftBase . Char8.putStrLn . renderSQL
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+1−4
@@ -226,10 +226,7 @@ type (:=>) constraint ty = '(constraint,ty)
226infixr 7 :=>
226infixr 7 :=>
227
227
228-- | The alias operator `:::` is like a promoted version of `As`,
228-- | The alias operator `:::` is like a promoted version of `As`,
229−-- a type level pair between
229+-- a type level pair between an alias and some type.
230−-- an alias and some type, like a column alias and either a `ColumnType` or
231−-- `NullityType` or a table alias and either a `TableType` or a `RelationType`
232−-- or a constraint alias and a `TableConstraint`.
233type (:::) (alias :: Symbol) ty = '(alias,ty)
230type (:::) (alias :: Symbol) ty = '(alias,ty)
234infixr 6 :::
231infixr 6 :::
235
232