{-# LANGUAGE OverloadedStrings #-}
module Database.Beam.Sqlite.SqliteSpecific
(
sqliteGroupConcat
, sqliteGroupConcatOver
)
where
import Database.Beam
import Database.Beam.Backend.SQL
import Database.Beam.Query.Internal
import Database.Beam.Sqlite.Connection
import Database.Beam.Sqlite.Syntax
#if !MIN_VERSION_base(4, 11, 0)
import Data.Semigroup
#endif
sqliteGroupConcat
:: ( BeamSqlBackendCanSerialize Sqlite a
, BeamSqlBackendIsString Sqlite str
, BeamSqlBackendIsString Sqlite str2 )
=> QExpr Sqlite s a
-> QExpr Sqlite s str
-> QAgg Sqlite s (Maybe str2)
sqliteGroupConcat v delim = _sqliteGroupConcatOver allInGroup_ v (Just delim)
sqliteGroupConcatOver
:: ( BeamSqlBackendCanSerialize Sqlite a
, BeamSqlBackendIsString Sqlite str )
=> Maybe SqliteAggregationSetQuantifierSyntax
-> QExpr Sqlite s a
-> QAgg Sqlite s (Maybe str)
sqliteGroupConcatOver quantifier v = _sqliteGroupConcatOver quantifier v Nothing
_sqliteGroupConcatOver
:: ( BeamSqlBackendCanSerialize Sqlite a
, BeamSqlBackendIsString Sqlite str )
=> Maybe SqliteAggregationSetQuantifierSyntax
-> QExpr Sqlite s a
-> Maybe (QExpr Sqlite s str2)
-> QAgg Sqlite s (Maybe str)
_sqliteGroupConcatOver quantifier (QExpr v) delim =
QExpr $ \tbl -> SqliteExpressionSyntax $
emit "group_concat" <>
parens ( maybe mempty (\q -> fromSqliteAggregationSetQuantifier q <> emit " ") quantifier <>
fromSqliteExpression (v tbl) <>
maybe mempty (\(QExpr d) -> emit ", " <> fromSqliteExpression (d tbl)) delim)