Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
195
Issues
195
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
a891c1f5
Commit
a891c1f5
authored
Sep 07, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] insert db query
parent
705f1e2d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
12 deletions
+14
-12
Flow.hs
src/Gargantext/Database/Action/Flow.hs
+1
-0
Insert.hs
src/Gargantext/Database/Query/Table/Node/Document/Insert.hs
+13
-12
No files found.
src/Gargantext/Database/Action/Flow.hs
View file @
a891c1f5
...
@@ -235,6 +235,7 @@ insertDocs :: ( FlowCmdM env err m
...
@@ -235,6 +235,7 @@ insertDocs :: ( FlowCmdM env err m
insertDocs
uId
cId
hs
=
do
insertDocs
uId
cId
hs
=
do
let
docs
=
map
addUniqId
hs
let
docs
=
map
addUniqId
hs
newIds
<-
insertDb
uId
cId
docs
newIds
<-
insertDb
uId
cId
docs
printDebug
"newIds"
newIds
let
let
newIds'
=
map
reId
newIds
newIds'
=
map
reId
newIds
documentsWithId
=
mergeData
(
toInserted
newIds
)
(
Map
.
fromList
$
map
viewUniqId'
docs
)
documentsWithId
=
mergeData
(
toInserted
newIds
)
(
Map
.
fromList
$
map
viewUniqId'
docs
)
...
...
src/Gargantext/Database/Query/Table/Node/Document/Insert.hs
View file @
a891c1f5
...
@@ -114,7 +114,8 @@ class InsertDb a
...
@@ -114,7 +114,8 @@ class InsertDb a
instance
InsertDb
HyperdataDocument
instance
InsertDb
HyperdataDocument
where
where
insertDb'
u
p
h
=
[
toField
$
nodeTypeId
NodeDocument
insertDb'
u
p
h
=
[
toField
(
""
::
Text
)
,
toField
$
nodeTypeId
NodeDocument
,
toField
u
,
toField
u
,
toField
p
,
toField
p
,
toField
$
maybe
"No Title"
(
DT
.
take
255
)
(
_hd_title
h
)
,
toField
$
maybe
"No Title"
(
DT
.
take
255
)
(
_hd_title
h
)
...
@@ -124,7 +125,8 @@ instance InsertDb HyperdataDocument
...
@@ -124,7 +125,8 @@ instance InsertDb HyperdataDocument
instance
InsertDb
HyperdataContact
instance
InsertDb
HyperdataContact
where
where
insertDb'
u
p
h
=
[
toField
$
nodeTypeId
NodeContact
insertDb'
u
p
h
=
[
toField
(
""
::
Text
)
,
toField
$
nodeTypeId
NodeContact
,
toField
u
,
toField
u
,
toField
p
,
toField
p
,
toField
$
maybe
"Contact"
(
DT
.
take
255
)
(
Just
"Name"
)
-- (_hc_name h)
,
toField
$
maybe
"Contact"
(
DT
.
take
255
)
(
Just
"Name"
)
-- (_hc_name h)
...
@@ -146,30 +148,29 @@ insertDocuments_Debug uId pId hs = formatPGSQuery queryInsert (Only $ Values fie
...
@@ -146,30 +148,29 @@ insertDocuments_Debug uId pId hs = formatPGSQuery queryInsert (Only $ Values fie
-- | Input Tables: types of the tables
-- | Input Tables: types of the tables
inputSqlTypes
::
[
Text
]
inputSqlTypes
::
[
Text
]
inputSqlTypes
=
map
DT
.
pack
[
"int4"
,
"int4"
,
"int4"
,
"text"
,
"date"
,
"jsonb"
]
inputSqlTypes
=
map
DT
.
pack
[
"
text"
,
"
int4"
,
"int4"
,
"int4"
,
"text"
,
"date"
,
"jsonb"
]
-- | SQL query to insert documents inside the database
-- | SQL query to insert documents inside the database
queryInsert
::
Query
queryInsert
::
Query
queryInsert
=
[
sql
|
queryInsert
=
[
sql
|
WITH input_rows(typename,user_id,parent_id,name,date,hyperdata) AS (?)
WITH input_rows(
hash_id,
typename,user_id,parent_id,name,date,hyperdata) AS (?)
, ins AS (
, ins AS (
INSERT INTO nodes (typename,user_id,parent_id,name,date,hyperdata)
INSERT INTO nodes (
hash_id,
typename,user_id,parent_id,name,date,hyperdata)
SELECT * FROM input_rows
SELECT * FROM input_rows
ON CONFLICT ((hyperdata ->> 'uniqIdBdd')) DO NOTHING -- on unique index -- this does not return the ids
ON CONFLICT (hash_id) DO NOTHING -- on unique index -- this does not return the ids
-- ON CONFLICT ((hyperdata ->> 'uniqIdBdd')) DO UPDATE SET user_id=EXCLUDED.user_id -- on unique index
RETURNING id,hash_id
RETURNING id,hyperdata
)
)
SELECT true AS source -- true for 'newly inserted'
SELECT true AS source -- true for 'newly inserted'
, id
, id
, h
yperdata ->> 'uniqIdBdd' as doi
, h
ash_id
FROM ins
FROM ins
UNION ALL
UNION ALL
SELECT false AS source -- false for 'not inserted'
SELECT false AS source -- false for 'not inserted'
,
c
.id
,
n
.id
, h
yperdata ->> 'uniqIdBdd' as doi
, h
ash_id
FROM input_rows
FROM input_rows
JOIN nodes
c USING (hyperdata
); -- columns of unique index
JOIN nodes
n USING (hash_id
); -- columns of unique index
|]
|]
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment