-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabaseParser.js
53 lines (48 loc) · 1.39 KB
/
databaseParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const queryBuilder = require('knex')({
client: 'mysql',
connection: {
host: "localhost",
user: "root",
password: "",
database: "gazelle_old"
}
});
const terms = 'wp_terms';
const title = 'post_title';
const name = 'name'
const taxonomy = 'wp_term_taxonomy';
const termId = 'term_id';
const taxonomyId = 'term_taxonomy_id';
const relationships = 'wp_term_relationships';
const posts = 'wp_posts';
const objectId = 'object_id';
const postId = "ID";
const tax = "taxonomy"
function postToWordpressTermQuery(wpTerm, maxRows) {
return queryBuilder
.select(title, name)
.from(terms)
.innerJoin(taxonomy, terms+'.'+termId, '=', taxonomy+'.'+taxonomyId)
.innerJoin(relationships, terms+'.'+termId, '=', relationships+'.'+taxonomyId)
.innerJoin(posts, posts+'.'+postId, '=', relationships+'.'+objectId)
.where(taxonomy+'.'+tax, '=', wpTerm)
.then((rows) => {
console.log(wpTerm + " is coming");
console.log(rows.slice(0, maxRows));
return;
})
.catch((err) => {
throw err;
});
}
function disconnect() {
queryBuilder.destroy();
}
postToWordpressTermQuery('category', 4)
.then(postToWordpressTermQuery('author', 4))
.then(postToWordpressTermQuery('issue', 4))
.then(postToWordpressTermQuery('nav_menu', 4))
.then(postToWordpressTermQuery('post_format', 4))
.then(postToWordpressTermQuery('post_tag', 4))
.then(disconnect());