on dev help sign in
text operations
commitee58d6a1352eebebc69570c65d1928fa9a65d698 authorEitan Chatav <eitan.chatav@gmail.com> dateSat 19 Aug 2017, 12:53 (9 years ago) parent872e605
1 file changed+51−16
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+51−16
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+51−16
@@ -77,6 +77,11 @@ module Squeal.PostgreSQL.Expression
7777 , currentTimestamp
7878 , localTime
7979 , localTimestamp
80+ -- ** Text
81+ , lower
82+ , upper
83+ , charLength
84+ , like
8085 -- ** Aggregation
8186 , unsafeAggregate
8287 , unsafeAggregateDistinct
@@ -496,22 +501,6 @@ ceiling_
496501 -> Expression tables grouping params ('Required (nullity frac))
497502ceiling_ = unsafeFunction "ceiling"
498503
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−
515504type Condition tables grouping params =
516505 Expression tables grouping params ('Required ('NotNull 'PGbool))
517506
@@ -626,6 +615,52 @@ localTimestamp
626615 :: Expression tables grouping params ('Required (nullity 'PGtimestamp))
627616localTimestamp = UnsafeExpression "LOCALTIMESTAMP"
628617
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+
629664{-----------------------------------------
630665aggregation
631666-----------------------------------------}