Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Przemyslaw Kaminski
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
insertDocs
uId
cId
hs
=
do
let
docs
=
map
addUniqId
hs
newIds
<-
insertDb
uId
cId
docs
printDebug
"newIds"
newIds
let
newIds'
=
map
reId
newIds
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
instance
InsertDb
HyperdataDocument
where
insertDb'
u
p
h
=
[
toField
$
nodeTypeId
NodeDocument
insertDb'
u
p
h
=
[
toField
(
""
::
Text
)
,
toField
$
nodeTypeId
NodeDocument
,
toField
u
,
toField
p
,
toField
$
maybe
"No Title"
(
DT
.
take
255
)
(
_hd_title
h
)
...
...
@@ -124,7 +125,8 @@ instance InsertDb HyperdataDocument
instance
InsertDb
HyperdataContact
where
insertDb'
u
p
h
=
[
toField
$
nodeTypeId
NodeContact
insertDb'
u
p
h
=
[
toField
(
""
::
Text
)
,
toField
$
nodeTypeId
NodeContact
,
toField
u
,
toField
p
,
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
-- | Input Tables: types of the tables
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
queryInsert
::
Query
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 (
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
ON CONFLICT ((hyperdata ->> 'uniqIdBdd')) 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,hyperdata
ON CONFLICT (hash_id) DO NOTHING -- on unique index -- this does not return the ids
RETURNING id,hash_id
)
SELECT true AS source -- true for 'newly inserted'
, id
, h
yperdata ->> 'uniqIdBdd' as doi
, h
ash_id
FROM ins
UNION ALL
SELECT false AS source -- false for 'not inserted'
,
c
.id
, h
yperdata ->> 'uniqIdBdd' as doi
,
n
.id
, h
ash_id
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