on dev help sign in
text operations
ee58d6aEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+51−16
@@ -77,6 +77,11 @@ module Squeal.PostgreSQL.Expression
77 , currentTimestamp
77 , currentTimestamp
78 , localTime
78 , localTime
79 , localTimestamp
79 , localTimestamp
80+ -- ** Text
81+ , lower
82+ , upper
83+ , charLength
84+ , like
80 -- ** Aggregation
85 -- ** Aggregation
81 , unsafeAggregate
86 , unsafeAggregate
82 , unsafeAggregateDistinct
87 , unsafeAggregateDistinct
@@ -496,22 +501,6 @@ ceiling_
496 -> Expression tables grouping params ('Required (nullity frac))
501 -> Expression tables grouping params ('Required (nullity frac))
497ceiling_ = unsafeFunction "ceiling"
502ceiling_ = unsafeFunction "ceiling"
498
503
499−instance IsString
500− (Expression tables grouping params ('Required (nullity 'PGtext))) where
501− fromString str = UnsafeExpression $
502− "E\'" <> fromString (escape =<< str) <> "\'"
503− where
504− escape = \case
505− '\NUL' -> "\\0"
506− '\'' -> "''"
507− '"' -> "\\\""
508− '\b' -> "\\b"
509− '\n' -> "\\n"
510− '\r' -> "\\r"
511− '\t' -> "\\t"
512− '\\' -> "\\\\"
513− c -> [c]
514−
515type Condition tables grouping params =
504type Condition tables grouping params =
516 Expression tables grouping params ('Required ('NotNull 'PGbool))
505 Expression tables grouping params ('Required ('NotNull 'PGbool))
517
506
@@ -626,6 +615,52 @@ localTimestamp
626 :: Expression tables grouping params ('Required (nullity 'PGtimestamp))
615 :: Expression tables grouping params ('Required (nullity 'PGtimestamp))
627localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
616localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
628
617
618+{-----------------------------------------
619+text
620+-----------------------------------------}
621+
622+instance IsString
623+ (Expression tables grouping params ('Required (nullity 'PGtext))) where
624+ fromString str = UnsafeExpression $
625+ "E\'" <> fromString (escape =<< str) <> "\'"
626+ where
627+ escape = \case
628+ '\NUL' -> "\\0"
629+ '\'' -> "''"
630+ '"' -> "\\\""
631+ '\b' -> "\\b"
632+ '\n' -> "\\n"
633+ '\r' -> "\\r"
634+ '\t' -> "\\t"
635+ '\\' -> "\\\\"
636+ c -> [c]
637+
638+instance Monoid
639+ (Expression tables grouping params ('Required (nullity 'PGtext))) where
640+ mempty = fromString ""
641+ mappend = unsafeBinaryOp "||"
642+
643+lower
644+ :: Expression tables grouping params ('Required (nullity 'PGtext))
645+ -> Expression tables grouping params ('Required (nullity 'PGtext))
646+lower = unsafeFunction "lower"
647+
648+upper
649+ :: Expression tables grouping params ('Required (nullity 'PGtext))
650+ -> Expression tables grouping params ('Required (nullity 'PGtext))
651+upper = unsafeFunction "upper"
652+
653+charLength
654+ :: Expression tables grouping params ('Required (nullity 'PGtext))
655+ -> Expression tables grouping params ('Required (nullity 'PGint4))
656+charLength = unsafeFunction "char_length"
657+
658+like
659+ :: Expression tables grouping params ('Required (nullity 'PGtext))
660+ -> Expression tables grouping params ('Required (nullity 'PGtext))
661+ -> Expression tables grouping params ('Required (nullity 'PGbool))
662+like = unsafeBinaryOp "LIKE"
663+
629{-----------------------------------------
664{-----------------------------------------
630aggregation
665aggregation
631-----------------------------------------}
666-----------------------------------------}