on dev help sign in
move stuff around
f152a6cEitan Chatav
squeel-postgresql/src/Squeel/PostgreSQL/Schema.hs+4
@@ -36,6 +36,7 @@ module Squeel.PostgreSQL.Schema
36 , Rename
36 , Rename
37 , Join
37 , Join
38 , Grouping (..)
38 , Grouping (..)
39+ , TableColumn (..)
39 , module GHC.OverloadedLabels
40 , module GHC.OverloadedLabels
40 , module GHC.TypeLits
41 , module GHC.TypeLits
41 ) where
42 ) where
@@ -172,3 +173,6 @@ type family Join xs ys where
172data Grouping
173data Grouping
173 = Ungrouped
174 = Ungrouped
174 | Grouped [(Symbol,(Symbol,ColumnType))]
175 | Grouped [(Symbol,(Symbol,ColumnType))]
176+
177+class TableColumn table column expression where
178+ (&.) :: Alias table -> Alias column -> expression
squeel-postgresql/src/Squeel/PostgreSQL/Statement.hs+17−16
@@ -80,6 +80,11 @@ instance (HasColumn column columns ty, tables ~ '[table ::: columns])
80 => IsLabel column (Expression params tables 'Ungrouped ty) where
80 => IsLabel column (Expression params tables 'Ungrouped ty) where
81 fromLabel = getColumn
81 fromLabel = getColumn
82
82
83+instance (HasTable table tables columns, HasColumn column columns ty)
84+ => TableColumn table column (Expression params tables 'Ungrouped ty) where
85+ table &. column = UnsafeExpression $
86+ renderAlias table <> "." <> renderAlias column
87+
83def :: Expression params '[] grouping ('Optional (nullity ty))
88def :: Expression params '[] grouping ('Optional (nullity ty))
84def = UnsafeExpression "DEFAULT"
89def = UnsafeExpression "DEFAULT"
85
90
@@ -382,6 +387,14 @@ class (KnownSymbol table, KnownSymbol column)
382 -> Alias column
387 -> Alias column
383 -> Expression params tables ('Grouped distincts) ty
388 -> Expression params tables ('Grouped distincts) ty
384
389
390+instance
391+ ( HasTable table tables columns
392+ , HasColumn column columns ty
393+ , GroupedBy table column distincts ty
394+ ) => TableColumn table column
395+ (Expression params tables ('Grouped distincts) ty) where
396+ (&.) = getGroup
397+
385class (KnownSymbol table, KnownSymbol column)
398class (KnownSymbol table, KnownSymbol column)
386 => Aggregated table column distincts ty where
399 => Aggregated table column distincts ty where
387 getAggregate
400 getAggregate
@@ -391,22 +404,6 @@ class (KnownSymbol table, KnownSymbol column)
391 -> Aggregate ty0 ty
404 -> Aggregate ty0 ty
392 -> Expression params tables ('Grouped distincts) ty
405 -> Expression params tables ('Grouped distincts) ty
393
406
394−class TableColumn table column expression where
395− (&.) :: Alias table -> Alias column -> expression
396−instance (HasTable table tables columns, HasColumn column columns ty)
397− => TableColumn table column (Expression params tables 'Ungrouped ty) where
398− table &. column = UnsafeExpression $
399− renderAlias table <> "." <> renderAlias column
400−instance (HasTable table tables columns, HasColumn column columns ty)
401− => TableColumn table column (By tables (table ::: (column ::: ty))) where
402− (&.) = By
403−instance
404− ( HasTable table tables columns
405− , HasColumn column columns ty
406− , GroupedBy table column distincts ty
407− ) => TableColumn table column
408− (Expression params tables ('Grouped distincts) ty) where
409− (&.) = getGroup
410instance
407instance
411 ( HasTable table tables columns
408 ( HasTable table tables columns
412 , HasColumn column columns ty0
409 , HasColumn column columns ty0
@@ -517,6 +514,10 @@ data By tables tabcolty where
517 -> Alias column
514 -> Alias column
518 -> By tables (table ::: (column ::: ty))
515 -> By tables (table ::: (column ::: ty))
519
516
517+instance (HasTable table tables columns, HasColumn column columns ty)
518+ => TableColumn table column (By tables (table ::: (column ::: ty))) where
519+ (&.) = By
520+
520renderBy :: By tables tabcolty -> ByteString
521renderBy :: By tables tabcolty -> ByteString
521renderBy (By table column) = renderAlias table <> "." <> renderAlias column
522renderBy (By table column) = renderAlias table <> "." <> renderAlias column
522
523