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

View file

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

View file

@ -79,6 +79,23 @@ instance Form.FromForm NewUser where
-- ** 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 =
BUser
{ _nick :: Beam.Columnar f Nick