Commit 56d3a2b3 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[DB/OPTIM] schemas with bang patterns

parent 3b345bea
...@@ -56,9 +56,9 @@ type NgramsId = Int ...@@ -56,9 +56,9 @@ type NgramsId = Int
type NgramsTerms = Text type NgramsTerms = Text
type Size = Int type Size = Int
data NgramsPoly id terms n = NgramsDb { _ngrams_id :: id data NgramsPoly id terms n = NgramsDb { _ngrams_id :: !id
, _ngrams_terms :: terms , _ngrams_terms :: !terms
, _ngrams_n :: n , _ngrams_n :: !n
} deriving (Show) } deriving (Show)
type NgramsWrite = NgramsPoly (Maybe (Column PGInt4)) type NgramsWrite = NgramsPoly (Maybe (Column PGInt4))
...@@ -107,7 +107,7 @@ ngramsTypes = [minBound..] ...@@ -107,7 +107,7 @@ ngramsTypes = [minBound..]
instance ToSchema NgramsType instance ToSchema NgramsType
{- where {- where
declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_nre_") declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_nre_")
-} --}
instance FromJSON NgramsType instance FromJSON NgramsType
instance FromJSONKey NgramsType where instance FromJSONKey NgramsType where
...@@ -136,7 +136,6 @@ instance ToParamSchema NgramsType where ...@@ -136,7 +136,6 @@ instance ToParamSchema NgramsType where
instance QueryRunnerColumnDefault (Nullable PGInt4) NgramsTypeId instance QueryRunnerColumnDefault (Nullable PGInt4) NgramsTypeId
where where
queryRunnerColumnDefault = fieldQueryRunnerColumn queryRunnerColumnDefault = fieldQueryRunnerColumn
...@@ -154,7 +153,10 @@ ngramsTypeId Sources = 3 ...@@ -154,7 +153,10 @@ ngramsTypeId Sources = 3
ngramsTypeId NgramsTerms = 4 ngramsTypeId NgramsTerms = 4
fromNgramsTypeId :: NgramsTypeId -> Maybe NgramsType fromNgramsTypeId :: NgramsTypeId -> Maybe NgramsType
fromNgramsTypeId id = lookup id $ fromList [(ngramsTypeId nt,nt) | nt <- [minBound .. maxBound] :: [NgramsType]] fromNgramsTypeId id = lookup id
$ fromList [ (ngramsTypeId nt,nt)
| nt <- [minBound .. maxBound] :: [NgramsType]
]
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | TODO put it in Gargantext.Text.Ngrams -- | TODO put it in Gargantext.Text.Ngrams
...@@ -251,4 +253,3 @@ queryInsertNgrams = [sql| ...@@ -251,4 +253,3 @@ queryInsertNgrams = [sql|
|] |]
...@@ -44,20 +44,29 @@ import Test.QuickCheck.Arbitrary ...@@ -44,20 +44,29 @@ import Test.QuickCheck.Arbitrary
------------------------------------------------------------------------ ------------------------------------------------------------------------
data NodePoly id typename userId -- Main polymorphic Node definition
parentId name date
hyperdata = Node { _node_id :: id
, _node_typename :: typename
, _node_userId :: userId data NodePoly id
, _node_parentId :: parentId typename
userId
parentId
name
date
hyperdata =
Node { _node_id :: !id
, _node_typename :: !typename
, _node_name :: name , _node_userId :: !userId
, _node_date :: date , _node_parentId :: !parentId
, _node_hyperdata :: hyperdata , _node_name :: !name
} deriving (Show, Generic) , _node_date :: !date
, _node_hyperdata :: !hyperdata
} deriving (Show, Generic)
------------------------------------------------------------------------
-- Automatic instances derivation
$(deriveJSON (unPrefix "_node_") ''NodePoly) $(deriveJSON (unPrefix "_node_") ''NodePoly)
$(makeLenses ''NodePoly) $(makeLenses ''NodePoly)
...@@ -105,7 +114,6 @@ type NodeReadNull = NodePoly (Column (Nullable PGInt4)) ...@@ -105,7 +114,6 @@ type NodeReadNull = NodePoly (Column (Nullable PGInt4))
(Column (Nullable PGText)) (Column (Nullable PGText))
(Column (Nullable PGTimestamptz)) (Column (Nullable PGTimestamptz))
(Column (Nullable PGJsonb)) (Column (Nullable PGJsonb))
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | Node(Read|Write)Search is slower than Node(Write|Read) use it -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
-- for full text search only -- for full text search only
...@@ -144,19 +152,25 @@ type NodeSearchReadNull = ...@@ -144,19 +152,25 @@ type NodeSearchReadNull =
(Column (Nullable PGTSVector) ) (Column (Nullable PGTSVector) )
data NodePolySearch id typename userId data NodePolySearch id
parentId name date typename
hyperdata search = NodeSearch { _ns_id :: id userId
, _ns_typename :: typename parentId
, _ns_userId :: userId name
-- , nodeUniqId :: shaId date
, _ns_parentId :: parentId hyperdata
, _ns_name :: name search =
, _ns_date :: date NodeSearch { _ns_id :: id
, _ns_typename :: typename
, _ns_hyperdata :: hyperdata , _ns_userId :: userId
, _ns_search :: search -- , nodeUniqId :: shaId
} deriving (Show, Generic) , _ns_parentId :: parentId
, _ns_name :: name
, _ns_date :: date
, _ns_hyperdata :: hyperdata
, _ns_search :: search
} deriving (Show, Generic)
$(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch) $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
$(makeLensesWith abbreviatedFields ''NodePolySearch) $(makeLensesWith abbreviatedFields ''NodePolySearch)
......
...@@ -46,10 +46,10 @@ import qualified Database.PostgreSQL.Simple as PGS (Query, Only(..)) ...@@ -46,10 +46,10 @@ import qualified Database.PostgreSQL.Simple as PGS (Query, Only(..))
import qualified Opaleye as O import qualified Opaleye as O
data NodeNodePoly node1_id node2_id score cat data NodeNodePoly node1_id node2_id score cat
= NodeNode { _nn_node1_id :: node1_id = NodeNode { _nn_node1_id :: !node1_id
, _nn_node2_id :: node2_id , _nn_node2_id :: !node2_id
, _nn_score :: score , _nn_score :: !score
, _nn_category :: cat , _nn_category :: !cat
} deriving (Show) } deriving (Show)
type NodeNodeWrite = NodeNodePoly (Column (PGInt4)) type NodeNodeWrite = NodeNodePoly (Column (PGInt4))
......
...@@ -9,7 +9,7 @@ Portability : POSIX ...@@ -9,7 +9,7 @@ Portability : POSIX
-} -}
{-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE Arrows #-} {-# LANGUAGE Arrows #-}
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
...@@ -33,11 +33,11 @@ import Gargantext.Database.Admin.Types.Node ...@@ -33,11 +33,11 @@ import Gargantext.Database.Admin.Types.Node
import Opaleye import Opaleye
data NodeNodeNgramsPoly n1 n2 ngrams_id ngt w data NodeNodeNgramsPoly n1 n2 ngrams_id ngt w
= NodeNodeNgrams { _nnng_node1_id :: n1 = NodeNodeNgrams { _nnng_node1_id :: !n1
, _nnng_node2_id :: n2 , _nnng_node2_id :: !n2
, _nnng_ngrams_id :: ngrams_id , _nnng_ngrams_id :: !ngrams_id
, _nnng_ngramsType :: ngt , _nnng_ngramsType :: !ngt
, _nnng_weight :: w , _nnng_weight :: !w
} deriving (Show) } deriving (Show)
type NodeNodeNgramsWrite = type NodeNodeNgramsWrite =
......
...@@ -33,9 +33,9 @@ import Opaleye ...@@ -33,9 +33,9 @@ import Opaleye
import Prelude import Prelude
data NodeNodeNgrams2Poly node_id nodengrams_id w data NodeNodeNgrams2Poly node_id nodengrams_id w
= NodeNodeNgrams2 { _nnng2_node_id :: node_id = NodeNodeNgrams2 { _nnng2_node_id :: !node_id
, _nnng2_nodengrams_id :: nodengrams_id , _nnng2_nodengrams_id :: !nodengrams_id
, _nnng2_weight :: w , _nnng2_weight :: !w
} deriving (Show) } deriving (Show)
type NodeNodeNgrams2Write = type NodeNodeNgrams2Write =
......
...@@ -46,10 +46,10 @@ import Gargantext.Prelude ...@@ -46,10 +46,10 @@ import Gargantext.Prelude
import Opaleye import Opaleye
data Node_NodeNgrams_NodeNgrams_Poly node_id nng1_id nng2_id weight = data Node_NodeNgrams_NodeNgrams_Poly node_id nng1_id nng2_id weight =
Node_NodeNgrams_NodeNgrams { _nnn_node_id :: node_id Node_NodeNgrams_NodeNgrams { _nnn_node_id :: !node_id
, _nnn_nng1_id :: nng1_id , _nnn_nng1_id :: !nng1_id
, _nnn_nng2_id :: nng2_id , _nnn_nng2_id :: !nng2_id
, _nnn_weight :: weight , _nnn_weight :: !weight
} deriving (Show) } deriving (Show)
type Node_NodeNgrams_NodeNgrams_Write = type Node_NodeNgrams_NodeNgrams_Write =
......
...@@ -41,9 +41,9 @@ import Opaleye ...@@ -41,9 +41,9 @@ import Opaleye
data RepoDbPoly version patches data RepoDbPoly version patches
= RepoDbNgrams { _rdp_version :: version = RepoDbNgrams { _rdp_version :: !version
, _rdp_patches :: patches , _rdp_patches :: !patches
} deriving (Show) } deriving (Show)
type RepoDbWrite type RepoDbWrite
= RepoDbPoly (Column PGInt4) = RepoDbPoly (Column PGInt4)
......
...@@ -37,9 +37,9 @@ import Opaleye ...@@ -37,9 +37,9 @@ import Opaleye
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------ ------------------------------------------------------------------------
data UserLight = UserLight { userLight_id :: Int data UserLight = UserLight { userLight_id :: !Int
, userLight_username :: Text , userLight_username :: !Text
, userLight_email :: Text , userLight_email :: !Text
} deriving (Show) } deriving (Show)
toUserLight :: UserDB -> UserLight toUserLight :: UserDB -> UserLight
...@@ -48,19 +48,19 @@ toUserLight (UserDB id _ _ _ u _ _ e _ _ _ ) = UserLight id u e ...@@ -48,19 +48,19 @@ toUserLight (UserDB id _ _ _ u _ _ e _ _ _ ) = UserLight id u e
data UserPoly id pass llogin suser data UserPoly id pass llogin suser
uname fname lname uname fname lname
mail staff active djoined = mail staff active djoined =
UserDB { user_id :: id UserDB { user_id :: !id
, user_password :: pass , user_password :: !pass
, user_lastLogin :: llogin , user_lastLogin :: !llogin
, user_isSuperUser :: suser , user_isSuperUser :: !suser
, user_username :: uname , user_username :: !uname
, user_firstName :: fname , user_firstName :: !fname
, user_lastName :: lname , user_lastName :: !lname
, user_email :: mail , user_email :: !mail
, user_isStaff :: staff , user_isStaff :: !staff
, user_isActive :: active , user_isActive :: !active
, user_dateJoined :: djoined , user_dateJoined :: !djoined
} deriving (Show) } deriving (Show)
type UserWrite = UserPoly (Maybe (Column PGInt4)) (Column PGText) type UserWrite = UserPoly (Maybe (Column PGInt4)) (Column PGText)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment