aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorikoamu <ikoamu@gmail.com>2024-01-28 23:11:32 +0900
committerikoamu <ikoamu@gmail.com>2024-01-28 23:11:32 +0900
commitc67e917a9522515db26bc35276a02a10c4a5d5eb (patch)
tree05f1609118431e46beca897b7ce291581a85085d
parentf34d96b8c7caf8821477ec269c911d8a7d1bc73d (diff)
Refactor generate_json.js to handle multiple tags per node
-rw-r--r--generate_json.js23
1 files changed, 14 insertions, 9 deletions
diff --git a/generate_json.js b/generate_json.js
index d1e2701..fd20ae4 100644
--- a/generate_json.js
+++ b/generate_json.js
@@ -46,7 +46,7 @@ function getFilename(path) {
const queryNodes = `
SELECT
- tags.tag as tags,
+ GROUP_CONCAT(tags.tag) AS tags,
nodes.properties,
nodes.olp,
nodes.pos,
@@ -75,9 +75,11 @@ WHERE
const queryTags = `
SELECT
- *
+ tags.tag
FROM
tags
+GROUP BY
+ tags.tag
`;
const graphdata = {
@@ -87,14 +89,17 @@ const graphdata = {
db.all(queryNodes, (_, nodes) =>
db.all(queryLinks, (_, links) =>
db.all(queryTags, (_, tags) => {
- graphdata.data.nodes = nodes.map(node => ({
- ...node,
- tags: node.tags ?? [null],
- file: getFilename(node.file),
- properties: parseProperties(node.properties),
- }));
+ graphdata.data.nodes = nodes.map(node => {
+ const splitTags = node.tags?.split(',') ?? [null];
+ return{
+ ...node,
+ tags: splitTags,
+ file: getFilename(node.file),
+ properties: parseProperties(node.properties),
+ };
+ });
graphdata.data.links = links;
- graphdata.data.tags = tags.length ? tags : null;
+ graphdata.data.tags = tags.length ? tags.map(t => t.tag) : null;
fs.writeFile('graphdata.json', JSON.stringify(removeQuotesFromObject(graphdata)), (err) => {
if (err) throw err;