on dev help sign in
some haddocks
b643396Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+75−32
@@ -1,5 +1,5 @@
1{-|
1{-|
2−Module: Squeal.PostgreSQL.Query
2+Module: Squeal.PostgreSQL.Expression
3Description: Squeal expressions
3Description: Squeal expressions
4Copyright: (c) Eitan Chatav, 2017
4Copyright: (c) Eitan Chatav, 2017
5Maintainer: eitan@morphism.tech
5Maintainer: eitan@morphism.tech
@@ -210,7 +210,7 @@ import qualified Data.Aeson as JSON
210import Data.Ratio
210import Data.Ratio
211import Data.String
211import Data.String
212import Data.Word
212import Data.Word
213−import Generics.SOP hiding (from)
213+import Generics.SOP hiding (All, from)
214import GHC.Generics ((:*:) (..))
214import GHC.Generics ((:*:) (..))
215import GHC.OverloadedLabels
215import GHC.OverloadedLabels
216import GHC.TypeLits
216import GHC.TypeLits
@@ -218,6 +218,7 @@ import Prelude hiding (id, (.))
218
218
219import qualified Data.ByteString as ByteString
219import qualified Data.ByteString as ByteString
220import qualified GHC.Generics as GHC
220import qualified GHC.Generics as GHC
221+import qualified Generics.SOP as SOP
221
222
222import Squeal.PostgreSQL.Render
223import Squeal.PostgreSQL.Render
223import Squeal.PostgreSQL.Schema
224import Squeal.PostgreSQL.Schema
@@ -1216,11 +1217,11 @@ jsonbBuildArray
1216jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1217jsonbBuildArray = unsafeVariadicFunction "jsonb_build_array"
1217
1218
1218unsafeRowFunction
1219unsafeRowFunction
1219− :: All Top elems
1220+ :: SOP.All SOP.Top elems
1220 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1221 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1221 -> [ByteString]
1222 -> [ByteString]
1222unsafeRowFunction =
1223unsafeRowFunction =
1223− (`appEndo` []) . hcfoldMap (Proxy :: Proxy Top)
1224+ (`appEndo` []) . hcfoldMap (Proxy :: SOP.Proxy SOP.Top)
1224 (\(col `As` name) -> Endo $ \xs ->
1225 (\(col `As` name) -> Endo $ \xs ->
1225 renderAliasString name : renderSQL col : xs)
1226 renderAliasString name : renderSQL col : xs)
1226 where
1227 where
@@ -1231,7 +1232,7 @@ unsafeRowFunction =
1231-- argument list. The elements of the argument list must alternate between text
1232-- argument list. The elements of the argument list must alternate between text
1232-- and values.
1233-- and values.
1233jsonBuildObject
1234jsonBuildObject
1234− :: All Top elems
1235+ :: SOP.All SOP.Top elems
1235 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1236 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1236 -> Expression outer grp commons schemas params from (nullity 'PGjson)
1237 -> Expression outer grp commons schemas params from (nullity 'PGjson)
1237jsonBuildObject
1238jsonBuildObject
@@ -1244,7 +1245,7 @@ jsonBuildObject
1244-- variadic argument list. The elements of the argument list must alternate
1245-- variadic argument list. The elements of the argument list must alternate
1245-- between text and values.
1246-- between text and values.
1246jsonbBuildObject
1247jsonbBuildObject
1247− :: All Top elems
1248+ :: SOP.All SOP.Top elems
1248 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1249 => NP (Aliased (Expression outer grp commons schemas params from)) elems
1249 -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1250 -> Expression outer grp commons schemas params from (nullity 'PGjsonb)
1250jsonbBuildObject
1251jsonbBuildObject
@@ -1427,6 +1428,11 @@ jsonbPretty = unsafeFunction "jsonb_pretty"
1427aggregation
1428aggregation
1428-----------------------------------------}
1429-----------------------------------------}
1429
1430
1431+{- |
1432+`Aggregate` functions compute a single result from a set of input values.
1433+`Aggregate` functions can be used as `GroupedBy` `Expression`s as well
1434+as `WindowFunction`s.
1435+-}
1430class Aggregate expr1 expr2 aggr
1436class Aggregate expr1 expr2 aggr
1431 | aggr -> expr1, aggr -> expr2 where
1437 | aggr -> expr1, aggr -> expr2 where
1432
1438
@@ -1714,6 +1720,12 @@ class Aggregate expr1 expr2 aggr
1714 :: expr1 (nullity ty)
1720 :: expr1 (nullity ty)
1715 -> aggr (nullity (PGAvg ty))
1721 -> aggr (nullity (PGAvg ty))
1716
1722
1723+{- |
1724+`Distinction`s are used for the input of `Aggregate` `Expression`s.
1725+`All` invokes the aggregate once for each input row.
1726+`Distinct` invokes the aggregate once for each distinct value of the expression
1727+(or distinct set of values, for multiple expressions) found in the input
1728+-}
1717data Distinction expr ty
1729data Distinction expr ty
1718 = All (expr ty)
1730 = All (expr ty)
1719 | Distinct (expr ty)
1731 | Distinct (expr ty)
@@ -1839,7 +1851,8 @@ type family PGAvg ty where
1839type expressions
1851type expressions
1840-----------------------------------------}
1852-----------------------------------------}
1841
1853
1842−-- | `TypeExpression`s are used in `cast`s and `createTable` commands.
1854+-- | `TypeExpression`s are used in `cast`s and
1855+-- `Squeal.PostgreSQL.Definition.createTable` commands.
1843newtype TypeExpression (schemas :: SchemasType) (ty :: NullityType)
1856newtype TypeExpression (schemas :: SchemasType) (ty :: NullityType)
1844 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1857 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
1845 deriving (GHC.Generic,Show,Eq,Ord,NFData)
1858 deriving (GHC.Generic,Show,Eq,Ord,NFData)
@@ -1955,21 +1968,21 @@ vararray ty = UnsafeTypeExpression $ renderSQL ty <> "[]"
1955-- >>> renderSQL (fixarray @'[2] json)
1968-- >>> renderSQL (fixarray @'[2] json)
1956-- "json[2]"
1969-- "json[2]"
1957fixarray
1970fixarray
1958− :: forall dims schemas nullity pg. All KnownNat dims
1971+ :: forall dims schemas nullity pg. SOP.All KnownNat dims
1959 => TypeExpression schemas pg
1972 => TypeExpression schemas pg
1960 -> TypeExpression schemas (nullity ('PGfixarray dims pg))
1973 -> TypeExpression schemas (nullity ('PGfixarray dims pg))
1961fixarray ty = UnsafeTypeExpression $
1974fixarray ty = UnsafeTypeExpression $
1962 renderSQL ty <> renderDims @dims
1975 renderSQL ty <> renderDims @dims
1963 where
1976 where
1964− renderDims :: forall ns. All KnownNat ns => ByteString
1977+ renderDims :: forall ns. SOP.All KnownNat ns => ByteString
1965 renderDims =
1978 renderDims =
1966 ("[" <>)
1979 ("[" <>)
1967 . (<> "]")
1980 . (<> "]")
1968 . ByteString.intercalate "]["
1981 . ByteString.intercalate "]["
1969 . hcollapse
1982 . hcollapse
1970− $ hcmap (Proxy @KnownNat)
1983+ $ hcmap (SOP.Proxy @KnownNat)
1971 (K . fromString . show . natVal)
1984 (K . fromString . show . natVal)
1972− (hpure Proxy :: NP Proxy ns)
1985+ (hpure SOP.Proxy :: NP SOP.Proxy ns)
1973
1986
1974-- | `pgtype` is a demoted version of a `PGType`
1987-- | `pgtype` is a demoted version of a `PGType`
1975class PGTyped schemas (ty :: NullityType) where
1988class PGTyped schemas (ty :: NullityType) where
@@ -1999,7 +2012,7 @@ instance PGTyped schemas (nullity 'PGjsonb) where pgtype = jsonb
1999instance PGTyped schemas ty
2012instance PGTyped schemas ty
2000 => PGTyped schemas (nullity ('PGvararray ty)) where
2013 => PGTyped schemas (nullity ('PGvararray ty)) where
2001 pgtype = vararray (pgtype @schemas @ty)
2014 pgtype = vararray (pgtype @schemas @ty)
2002−instance (All KnownNat dims, PGTyped schemas ty)
2015+instance (SOP.All KnownNat dims, PGTyped schemas ty)
2003 => PGTyped schemas (nullity ('PGfixarray dims ty)) where
2016 => PGTyped schemas (nullity ('PGfixarray dims ty)) where
2004 pgtype = fixarray @dims (pgtype @schemas @ty)
2017 pgtype = fixarray @dims (pgtype @schemas @ty)
2005
2018
@@ -2007,8 +2020,9 @@ instance (All KnownNat dims, PGTyped schemas ty)
2007Sorting
2020Sorting
2008-----------------------------------------}
2021-----------------------------------------}
2009
2022
2010−-- | `SortExpression`s are used by `sortBy` to optionally sort the results
2023+-- | `SortExpression`s are used by `orderBy` to optionally sort the results
2024+-- of a `Squeal.PostgreSQL.Query.Query`. `Asc` or `Desc`
2011−-- of a `Query`. `Asc` or `Desc` set the sort direction of a `NotNull` result
2025+-- set the sort direction of a `NotNull` result
2012-- column to ascending or descending. Ascending order puts smaller values
2026-- column to ascending or descending. Ascending order puts smaller values
2013-- first, where "smaller" is defined in terms of the `.<` operator. Similarly,
2027-- first, where "smaller" is defined in terms of the `.<` operator. Similarly,
2014-- descending order is determined with the `.>` operator. `AscNullsFirst`,
2028-- descending order is determined with the `.>` operator. `AscNullsFirst`,
@@ -2016,26 +2030,37 @@ Sorting
2016-- determine whether nulls appear before or after non-null values in the sort
2030-- determine whether nulls appear before or after non-null values in the sort
2017-- ordering of a `Null` result column.
2031-- ordering of a `Null` result column.
2018data SortExpression outer grp commons schemas params from where
2032data SortExpression outer grp commons schemas params from where
2019− Asc
2033+ Asc
2020− :: Expression outer grp commons schemas params from ('NotNull ty)
2034+ :: Expression outer grp commons schemas params from ('NotNull ty)
2021− -> SortExpression outer grp commons schemas params from
2035+ -> SortExpression outer grp commons schemas params from
2022− Desc
2036+ Desc
2023− :: Expression outer grp commons schemas params from ('NotNull ty)
2037+ :: Expression outer grp commons schemas params from ('NotNull ty)
2024− -> SortExpression outer grp commons schemas params from
2038+ -> SortExpression outer grp commons schemas params from
2025− AscNullsFirst
2039+ AscNullsFirst
2026− :: Expression outer grp commons schemas params from ('Null ty)
2040+ :: Expression outer grp commons schemas params from ('Null ty)
2027− -> SortExpression outer grp commons schemas params from
2041+ -> SortExpression outer grp commons schemas params from
2028− AscNullsLast
2042+ AscNullsLast
2029− :: Expression outer grp commons schemas params from ('Null ty)
2043+ :: Expression outer grp commons schemas params from ('Null ty)
2030− -> SortExpression outer grp commons schemas params from
2044+ -> SortExpression outer grp commons schemas params from
2031− DescNullsFirst
2045+ DescNullsFirst
2032− :: Expression outer grp commons schemas params from ('Null ty)
2046+ :: Expression outer grp commons schemas params from ('Null ty)
2033− -> SortExpression outer grp commons schemas params from
2047+ -> SortExpression outer grp commons schemas params from
2034− DescNullsLast
2048+ DescNullsLast
2035− :: Expression outer grp commons schemas params from ('Null ty)
2049+ :: Expression outer grp commons schemas params from ('Null ty)
2036− -> SortExpression outer grp commons schemas params from
2050+ -> SortExpression outer grp commons schemas params from
2037deriving instance Show (SortExpression outer grp commons schemas params from)
2051deriving instance Show (SortExpression outer grp commons schemas params from)
2038
2052
2053+{- |
2054+The `orderBy` clause causes the result rows of a `Squeal.PostgreSQL.Query.TableExpression`
2055+to be sorted according to the specified `SortExpression`(s).
2056+If two rows are equal according to the leftmost expression,
2057+they are compared according to the next expression and so on.
2058+If they are equal according to all specified expressions,
2059+they are returned in an implementation-dependent order.
2060+
2061+You can also control the order in which rows are processed by window functions
2062+using `orderBy` within `Squeal.PostgreSQL.Query.Over`.
2063+-}
2039class OrderBy expr where
2064class OrderBy expr where
2040 orderBy
2065 orderBy
2041 :: [SortExpression outer grp commons schemas params from]
2066 :: [SortExpression outer grp commons schemas params from]
@@ -2054,6 +2079,8 @@ instance RenderSQL (SortExpression outer grp commons schemas params from) where
2054 AscNullsLast expression -> renderSQL expression <+> "ASC NULLS LAST"
2079 AscNullsLast expression -> renderSQL expression <+> "ASC NULLS LAST"
2055 DescNullsLast expression -> renderSQL expression <+> "DESC NULLS LAST"
2080 DescNullsLast expression -> renderSQL expression <+> "DESC NULLS LAST"
2056
2081
2082+-- | A `WindowDefinition` is a set of table rows that are somehow related
2083+-- to the current row
2057data WindowDefinition outer grp commons schemas params from where
2084data WindowDefinition outer grp commons schemas params from where
2058 WindowDefinition
2085 WindowDefinition
2059 :: SListI bys
2086 :: SListI bys
@@ -2077,12 +2104,28 @@ instance RenderSQL (WindowDefinition outer commons schemas from grp params) wher
2077 srts -> " ORDER" <+> "BY"
2104 srts -> " ORDER" <+> "BY"
2078 <+> commaSeparated (renderSQL <$> srts)
2105 <+> commaSeparated (renderSQL <$> srts)
2079
2106
2107+{- |
2108+The `partitionBy` clause within `Squeal.PostgreSQL.Query.Over` divides the rows into groups,
2109+or partitions, that share the same values of the `partitionBy` `Expression`(s).
2110+For each row, the window function is computed across the rows that fall into
2111+the same partition as the current row.
2112+-}
2080partitionBy
2113partitionBy
2081 :: SListI bys
2114 :: SListI bys
2082 => NP (Expression outer grp commons schemas params from) bys
2115 => NP (Expression outer grp commons schemas params from) bys
2083 -> WindowDefinition outer grp commons schemas params from
2116 -> WindowDefinition outer grp commons schemas params from
2084partitionBy bys = WindowDefinition bys []
2117partitionBy bys = WindowDefinition bys []
2085
2118
2119+{- |
2120+A window function performs a calculation across a set of table rows
2121+that are somehow related to the current row. This is comparable to the type
2122+of calculation that can be done with an aggregate function.
2123+However, window functions do not cause rows to become grouped into a single
2124+output row like non-window aggregate calls would.
2125+Instead, the rows retain their separate identities.
2126+Behind the scenes, the window function is able to access more than
2127+just the current row of the query result.
2128+-}
2086newtype WindowFunction
2129newtype WindowFunction
2087 (outer :: FromType)
2130 (outer :: FromType)
2088 (grp :: Grouping)
2131 (grp :: Grouping)
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+4−4
@@ -612,11 +612,11 @@ data TableExpression
612 -- will be returned (but possibly fewer, if the query itself yields
612 -- will be returned (but possibly fewer, if the query itself yields
613 -- fewer rows).
613 -- fewer rows).
614 , offsetClause :: [Word64]
614 , offsetClause :: [Word64]
615− -- ^ The `offsetClause` is combined with `+` to give an offset count
615+ -- ^ The `offsetClause` is combined with `Prelude.+` to give an offset count
616 -- if nonempty. The offset count says to skip that many rows before
616 -- if nonempty. The offset count says to skip that many rows before
617 -- beginning to return rows. The rows are skipped before the limit count
617 -- beginning to return rows. The rows are skipped before the limit count
618 -- is applied.
618 -- is applied.
619− }
619+ } deriving (GHC.Generic)
620
620
621-- | Render a `TableExpression`
621-- | Render a `TableExpression`
622instance RenderSQL (TableExpression outer grp commons schemas params from) where
622instance RenderSQL (TableExpression outer grp commons schemas params from) where
@@ -648,7 +648,7 @@ instance RenderSQL (TableExpression outer grp commons schemas params from) where
648-- | A `from` generates a `TableExpression` from a table reference that can be
648-- | A `from` generates a `TableExpression` from a table reference that can be
649-- a table name, or a derived table such as a subquery, a JOIN construct,
649-- a table name, or a derived table such as a subquery, a JOIN construct,
650-- or complex combinations of these. A `from` may be transformed by `where_`,
650-- or complex combinations of these. A `from` may be transformed by `where_`,
651−-- `group`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
651+-- `groupBy`, `having`, `orderBy`, `limit` and `offset`, using the `&` operator
652-- to match the left-to-right sequencing of their placement in SQL.
652-- to match the left-to-right sequencing of their placement in SQL.
653from
653from
654 :: FromClause outer commons schemas params from -- ^ table reference
654 :: FromClause outer commons schemas params from -- ^ table reference
@@ -987,7 +987,7 @@ fullOuterJoin right on left = UnsafeFromClause $
987Grouping
987Grouping
988-----------------------------------------}
988-----------------------------------------}
989
989
990−-- | `By`s are used in `group` to reference a list of columns which are then
990+-- | `By`s are used in `groupBy` to reference a list of columns which are then
991-- used to group together those rows in a table that have the same values
991-- used to group together those rows in a table that have the same values
992-- in all the columns listed. @By \#col@ will reference an unambiguous
992-- in all the columns listed. @By \#col@ will reference an unambiguous
993-- column @col@; otherwise @By2 (\#tab \! \#col)@ will reference a table
993-- column @col@; otherwise @By2 (\#tab \! \#col)@ will reference a table
squeal-postgresql/src/Squeal/PostgreSQL/Render.hs+7−5
@@ -41,9 +41,10 @@ import Data.Monoid ((<>))
41import Data.Text (Text)
41import Data.Text (Text)
42import Generics.SOP
42import Generics.SOP
43import GHC.Exts
43import GHC.Exts
44−import GHC.TypeLits
44+import GHC.TypeLits hiding (Text)
45+
45−import qualified Data.Text as T
46+import qualified Data.Text as Text
46−import qualified Data.Text.Encoding as T
47+import qualified Data.Text.Encoding as Text
47import qualified Data.ByteString as ByteString
48import qualified Data.ByteString as ByteString
48import qualified Data.ByteString.Char8 as Char8
49import qualified Data.ByteString.Char8 as Char8
49
50
@@ -66,11 +67,12 @@ doubleQuoted str = "\"" <> str <> "\""
66
67
67-- | Add single quotes around a `Text` and escape single quotes within it.
68-- | Add single quotes around a `Text` and escape single quotes within it.
68singleQuotedText :: Text -> ByteString
69singleQuotedText :: Text -> ByteString
69−singleQuotedText str = "'" <> T.encodeUtf8 (T.replace "'" "''" str) <> "'"
70+singleQuotedText str =
71+ "'" <> Text.encodeUtf8 (Text.replace "'" "''" str) <> "'"
70
72
71-- | Add single quotes around a `ByteString` and escape single quotes within it.
73-- | Add single quotes around a `ByteString` and escape single quotes within it.
72singleQuotedUtf8 :: ByteString -> ByteString
74singleQuotedUtf8 :: ByteString -> ByteString
73−singleQuotedUtf8 = singleQuotedText . T.decodeUtf8
75+singleQuotedUtf8 = singleQuotedText . Text.decodeUtf8
74
76
75-- | Comma separate the renderings of a heterogeneous list.
77-- | Comma separate the renderings of a heterogeneous list.
76renderCommaSeparated
78renderCommaSeparated
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+53−5
@@ -273,7 +273,13 @@ data TableConstraint
273 | PrimaryKey [Symbol]
273 | PrimaryKey [Symbol]
274 | ForeignKey [Symbol] Symbol [Symbol]
274 | ForeignKey [Symbol] Symbol [Symbol]
275
275
276−-- | A `TableConstraints` is a row of `TableConstraint`s.
276+{- | A `TableConstraints` is a row of `TableConstraint`s.
277+
278+>>> :{
279+type family UsersConstraints :: TableConstraints where
280+ UsersConstraints = '[ "pk_users" ::: 'PrimaryKey '["id"] ]
281+:}
282+-}
277type TableConstraints = [(Symbol,TableConstraint)]
283type TableConstraints = [(Symbol,TableConstraint)]
278
284
279-- | A `ForeignKey` must reference columns that either are
285-- | A `ForeignKey` must reference columns that either are
@@ -442,8 +448,12 @@ instance {-# OVERLAPPING #-} KnownSymbol alias
442instance {-# OVERLAPPABLE #-} (KnownSymbol alias, Has alias fields field)
448instance {-# OVERLAPPABLE #-} (KnownSymbol alias, Has alias fields field)
443 => Has alias (field' ': fields) field
449 => Has alias (field' ': fields) field
444
450
451+{-| @HasIn fields (alias ::: field)@ is a constraint that proves that
452+@fields@ has a field of @alias ::: field@. It is used in @UPDATE@s to
453+choose which subfields to update.
454+-}
445−class HasIn fields (x :: (Symbol, a)) where
455+class HasIn fields field where
446−instance (Has alias fields field) => HasIn fields '(alias, field) where
456+instance (Has alias fields field) => HasIn fields (alias ::: field) where
447
457
448-- | Utility class for `AllUnique` to provide nicer error messages.
458-- | Utility class for `AllUnique` to provide nicer error messages.
449class IsNotElem x isElem where
459class IsNotElem x isElem where
@@ -452,11 +462,16 @@ instance (TypeError ( 'Text "Cannot assign to "
452 ':<>: 'ShowType alias
462 ':<>: 'ShowType alias
453 ':<>: 'Text " more than once"))
463 ':<>: 'Text " more than once"))
454 => IsNotElem '(alias, a) 'True where
464 => IsNotElem '(alias, a) 'True where
465+
455− -- | No elem of @xs@ appears more than once, in the context of assignment.
466+-- | No elem of @xs@ appears more than once, in the context of assignment.
456class AllUnique (xs :: [(Symbol, a)]) where
467class AllUnique (xs :: [(Symbol, a)]) where
457instance AllUnique '[] where
468instance AllUnique '[] where
458instance (IsNotElem x (Elem x xs), AllUnique xs) => AllUnique (x ': xs) where
469instance (IsNotElem x (Elem x xs), AllUnique xs) => AllUnique (x ': xs) where
459
470
471+{- |
472+The `DefaultAliasable` class is intended to help with Scrap your Nils
473+for default inserts and updates.
474+-}
460class KnownSymbol alias
475class KnownSymbol alias
461 => DefaultAliasable alias aliased | aliased -> alias where
476 => DefaultAliasable alias aliased | aliased -> alias where
462 defaultAs :: Alias alias -> aliased
477 defaultAs :: Alias alias -> aliased
@@ -483,6 +498,21 @@ class IsQualified table column expression where
483 infixl 9 !
498 infixl 9 !
484instance IsQualified table column (Alias table, Alias column) where (!) = (,)
499instance IsQualified table column (Alias table, Alias column) where (!) = (,)
485
500
501+{-| `QualifiedAlias`es enables multi-schema support by allowing a reference
502+to a `Table`, `Typedef` or `View` to be qualified by their schemas. By default,
503+a qualifier of @public@ is provided.
504+
505+>>> :{
506+let
507+ alias1 :: QualifiedAlias "sch" "tab"
508+ alias1 = #sch ! #tab
509+ alias2 :: QualifiedAlias "public" "vw"
510+ alias2 = #vw
511+in printSQL alias1 >> printSQL alias2
512+:}
513+"sch"."tab"
514+"vw"
515+-}
486data QualifiedAlias (qualifier :: Symbol) (alias :: Symbol) = QualifiedAlias
516data QualifiedAlias (qualifier :: Symbol) (alias :: Symbol) = QualifiedAlias
487 deriving (Eq,GHC.Generic,Ord,Show,NFData)
517 deriving (Eq,GHC.Generic,Ord,Show,NFData)
488instance (q ~ q', a ~ a') => IsQualified q a (QualifiedAlias q' a') where
518instance (q ~ q', a ~ a') => IsQualified q a (QualifiedAlias q' a') where
@@ -621,7 +651,7 @@ type family Drop alias xs where
621 Drop alias (x ': xs) = x ': Drop alias xs
651 Drop alias (x ': xs) = x ': Drop alias xs
622
652
623-- | @Alter alias x xs@ replaces the type associated with an @alias@ in @xs@
653-- | @Alter alias x xs@ replaces the type associated with an @alias@ in @xs@
624−-- with the type `x` and is used in `Squeal.PostgreSQL.Definition.alterTable`
654+-- with the type @x@ and is used in `Squeal.PostgreSQL.Definition.alterTable`
625-- and `Squeal.PostgreSQL.Definition.alterColumn`.
655-- and `Squeal.PostgreSQL.Definition.alterColumn`.
626type family Alter alias x xs where
656type family Alter alias x xs where
627 Alter alias x1 (alias ::: x0 ': xs) = alias ::: x1 ': xs
657 Alter alias x1 (alias ::: x0 ': xs) = alias ::: x1 ': xs
@@ -691,8 +721,26 @@ type family Schema :: SchemaType where
691-}
721-}
692type SchemaType = [(Symbol,SchemumType)]
722type SchemaType = [(Symbol,SchemumType)]
693
723
724+{- |
725+A database contains one or more named schemas, which in turn contain tables.
726+The same object name can be used in different schemas without conflict;
727+for example, both schema1 and myschema can contain tables named mytable.
728+Unlike databases, schemas are not rigidly separated:
729+a user can access objects in any of the schemas in the database they are connected to,
730+if they have privileges to do so.
731+
732+There are several reasons why one might want to use schemas:
733+
734+ * To allow many users to use one database without interfering with each other.
735+ * To organize database objects into logical groups to make them more manageable.
736+ * Third-party applications can be put into separate schemas
737+ so they do not collide with the names of other objects.
738+-}
694type SchemasType = [(Symbol,SchemaType)]
739type SchemasType = [(Symbol,SchemaType)]
695
740
741+{-|
742+
743+-}
696type family Public (schema :: SchemaType) :: SchemasType
744type family Public (schema :: SchemaType) :: SchemasType
697 where Public schema = '["public" ::: schema]
745 where Public schema = '["public" ::: schema]
698
746