Skip to content

Commit 6a08d5e

Browse files
Mysql DB
1 parent 544d2e7 commit 6a08d5e

File tree

11 files changed

+120
-170
lines changed

11 files changed

+120
-170
lines changed

.env

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
1+
#source database config
22
MYSQL_HOST="localhost"
33
MYSQL_PORT="3306"
44
MYSQL_USER="root"
5-
MYSQL_PASSWORD="rootPwd@2022"
5+
MYSQL_PASSWORD="rootPwd@2022"
6+
7+
#sink data config
8+
MONGO_DB_URL="mongodb://localhost:27017"
9+
MONGO_DB_COLLECTION_NAME="nise"

Producer/Producer.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

Source-Connector/mysql-source.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const mysqlDBSinker = require('./source-connector/mysqlSourceConnector');
2+
mysqlDBSinker.then(() => console.log('Waiting for database vents...'))
3+
.catch(console.error);

common/common.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
EVENT_TYPE_INSERT: "INSERT",
3+
EVENT_TYPE_UPDATE: "UPDATE",
4+
EVENT_TYPE_DELETE: "DELETE",
5+
};

common/event-config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
/**
3+
* Default: false
4+
* Pass true to only emit binlog events that occur after ZongJi's instantiation.
5+
* Must be used in start() method for effect.
6+
*/
7+
startAtEnd: true,
8+
/**
9+
* Databases and tables to include (Only for row events).
10+
* Use database names as the key and pass an array of table names or true (for the entire database)
11+
* Example: { 'my_database': ['allow_table', 'another_table'], 'another_db': true }
12+
*/
13+
includeSchema: {},
14+
/**
15+
* Object describing which databases and tables to exclude (Same format as includeSchema)
16+
* Example: { 'other_db': ['disallowed_table'], 'ex_db': true }
17+
*/
18+
excludeSchema: {
19+
mysql: true
20+
}
21+
}

consumer/mongoDb.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

consumer/sink-connector.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
{
2-
"name": "CDC",
2+
"name": "cdc",
33
"version": "1.0.1",
4-
"description": "Change data chapture",
4+
"description": "Change data capture",
55
"main": "server.js",
66
"repository": "https://github.com/tasmidur/cdc.git",
77
"author": "Md Tasmidur Rahman",
88
"license": "MIT",
99
"private": false,
1010
"scripts": {
11-
"start": "node Source-Connector/mysql-source.js",
12-
"source": "node Source-Connector/mysql-source.js",
13-
"sink": "node consumer/sink-connector.js",
14-
"serve": "vue-cli-service serve",
15-
"build": "vue-cli-service build",
16-
"lint": "vue-cli-service lint",
17-
"test:unit": "vue-cli-service test:unit --watch"
11+
"start": "node app.js"
1812
},
1913
"dependencies": {
2014
"@rodrigogs/mysql-events": "^0.6.0",

sink-connector/mongoDb.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const {MongoClient} = require("mongodb");
2+
require('dotenv').config();
3+
4+
const uri = process.env.MONGO_DB_URL;
5+
const collectionName=process.env.MONGO_DB_COLLECTION_NAME
6+
const client = new MongoClient(uri);
7+
8+
const updateOrCreate = async (documentName, payload) => {
9+
try {
10+
await client.connect();
11+
const db = client.db(collectionName);
12+
const collection = db.collection(documentName);
13+
const query = {id: payload.id};
14+
const update = {$set: payload};
15+
const options = {upsert: true};
16+
const result = await collection.updateOne(query, update, options);
17+
console.log(result);
18+
} catch (error) {
19+
console.log("error: ", error)
20+
}
21+
};
22+
23+
const deleteDoc = async (documentName, payload) => {
24+
try {
25+
await client.connect();
26+
const db = client.db(collectionName);
27+
const query = {id: payload.id};
28+
const collection = db.collection(documentName);
29+
const result = await collection.deleteOne(query);
30+
console.log(result);
31+
} catch (error) {
32+
console.log("error: ", error)
33+
}
34+
}
35+
36+
module.exports = {
37+
updateOrCreate,
38+
deleteDoc
39+
}

0 commit comments

Comments
 (0)