try to fix leftjoin

This commit is contained in:
Yann Esposito (Yogsototh) 2019-06-05 00:38:31 +02:00
parent 32bc497c9f
commit 73bc5b3e49
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
3 changed files with 28 additions and 18 deletions

View file

@ -50,12 +50,12 @@ import qualified Aggreact.Users as User
import Data.Time.Format () import Data.Time.Format ()
import Database.SQLite.Simple (Only (..), query, query_) import Database.SQLite.Simple (Only (..), query, query_)
import Database.Store (DefaultMetas (..), Id (..),
Store (..))
import Database.Beam ((&&.),references_,(==?.))
import qualified Database.Beam as Beam import qualified Database.Beam as Beam
import qualified Database.Beam.Sqlite as BeamSqlite import qualified Database.Beam.Sqlite as BeamSqlite
import Database.Store (DefaultMetas (..), Id (..),
Store (..))
import Database.Store.Backend.SQLite as SQL import Database.Store.Backend.SQLite as SQL
import qualified Database.Store.CRUD as CRUD import qualified Database.Store.CRUD as CRUD
import qualified Database.Store.Search as Search import qualified Database.Store.Search as Search
@ -114,18 +114,11 @@ commentsView' conn db sl =
comment <- Beam.all_ (_aggreactComments db) comment <- Beam.all_ (_aggreactComments db)
user <- Beam.leftJoin_ user <- Beam.leftJoin_
(Beam.all_ (_aggreactUsers db)) (Beam.all_ (_aggreactUsers db))
(\u ->_userid comment `Beam.references_` u) (\u -> (Beam.maybe_
pure $ CommentView (bCommentToComment comment) (bUserToUser user) (pure False)
-- let queryTxt = "SELECT * FROM " (\uc -> uc `references_` u)
-- <> stTablename commentStore <> " c" (_userid comment)))
-- <> " INNER JOIN " pure $ CommentView (bCommentToCommentNoUser comment) (bUserToUser user)
-- <> stTablename userStore <> " u"
-- <> " ON c.userid = u.id"
-- <> " WHERE "
-- <> " slug = ? "
-- <> " ORDER BY created"
-- <> " DESC LIMIT 1000"
-- liftIO $ query (conn commentStore) (conv queryTxt) (Only sl)
-- | A comment handler, handle all impure operations needed to Comments -- | A comment handler, handle all impure operations needed to Comments
data CommentHandler = CommentHandler data CommentHandler = CommentHandler

View file

@ -136,15 +136,15 @@ data NewComment =
} deriving (Generic,Typeable,Data,Eq,Ord,Show) } deriving (Generic,Typeable,Data,Eq,Ord,Show)
-- ** Beam -- ** Beam
bCommentToComment :: BComment -> Comment bCommentToCommentNoUser :: BComment -> Comment
bCommentToComment bc = bCommentToCommentNoUser bc =
Entity Entity
(_id bc) (_id bc)
(NewComment (NewComment
{ parent = _parent bc { parent = _parent bc
, slug = _slug bc , slug = _slug bc
, content = _content bc , content = _content bc
, userid = _userid bc , userid = MUserId Nothing
}) })
(DefaultMetas (DefaultMetas
{ updated = _updated bc { updated = _updated bc

View file

@ -79,6 +79,23 @@ instance Form.FromForm NewUser where
-- ** Beam -- ** Beam
bUserToUser :: BUser -> User
bUserToUser bc =
Entity
(_id bc)
NewUser
{ nick = _nick bc
, email = _email bc
, password = _password bc
, role = _role bc
, trust = _trust bc
}
DefaultMetas
{ updated = _updated bc
, created = _created bc }
data BUserT f = data BUserT f =
BUser BUser
{ _nick :: Beam.Columnar f Nick { _nick :: Beam.Columnar f Nick