Merge pull request #166 from charukiewicz/master

Add several common SQL string functions
This commit is contained in:
Matt Parsons 2019-12-12 15:35:15 -08:00 committed by GitHub
commit c0dd6c70ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

View File

@ -1,3 +1,9 @@
3.3.0
========
- @charukiewicz, @belevy, @joemalin95
- [#166](https://github.com/bitemyapp/esqueleto/pull/166): Add several common SQL string functions: `upper_`, `trim_`, `ltrim_`, `rtrim_`, `length_`, `left_`, `right_`
3.2.3
========

View File

@ -1,7 +1,7 @@
cabal-version: 1.12
name: esqueleto
version: 3.2.3
version: 3.3.0
synopsis: Type-safe EDSL for SQL queries on persistent backends.
description: @esqueleto@ is a bare bones, type-safe EDSL for SQL queries that works with unmodified @persistent@ SQL backends. Its language closely resembles SQL, so you don't have to learn new concepts, just new syntax, and it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked @esqueleto@ queries that fail at runtime.
.

View File

@ -681,6 +681,41 @@ coalesceDefault exprs = unsafeSqlFunctionParens "COALESCE" . (exprs ++) . return
lower_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
lower_ = unsafeSqlFunction "LOWER"
-- | @UPPER@ function.
-- /Since: 3.3.0/
upper_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
upper_ = unsafeSqlFunction "UPPER"
-- | @TRIM@ function.
-- /Since: 3.3.0/
trim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
trim_ = unsafeSqlFunction "TRIM"
-- | @RTRIM@ function.
-- /Since: 3.3.0/
rtrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
rtrim_ = unsafeSqlFunction "RTRIM"
-- | @LTRIM@ function.
-- /Since: 3.3.0/
ltrim_ :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s)
ltrim_ = unsafeSqlFunction "LTRIM"
-- | @LENGTH@ function.
-- /Since: 3.3.0/
length_ :: (SqlString s, Num a) => SqlExpr (Value s) -> SqlExpr (Value a)
length_ = unsafeSqlFunction "LENGTH"
-- | @LEFT@ function.
-- /Since: 3.3.0/
left_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
left_ = unsafeSqlFunction "LEFT"
-- | @RIGHT@ function.
-- /Since: 3.3.0/
right_ :: (SqlString s, Num a) => (SqlExpr (Value s), SqlExpr (Value a)) -> SqlExpr (Value s)
right_ = unsafeSqlFunction "RIGHT"
-- | @LIKE@ operator.
like :: SqlString s => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value Bool)
like = unsafeSqlBinOp " LIKE "