source: pixabay.com
GitHub repo: https://github.com/mahdiyari/dblog-backend
Commit: https://github.com/mahdiyari/dblog-backend/commit/7c59954b65ef9d3951da7203b9a480417c96d122
& https://github.com/mahdiyari/dblog-backend/commit/7309faba7e7f29d217d730351daae963b170ee12
Recently I announced a new opensource project: @mahdiyari/announcement-onsteem-a-better-interface-on-the-steem-blockchain
I started developing back-end for this project called Dblog.io (new name)!
We will have a back-end here and a front-end here
A demo will be available here: https://dev.onsteem.com (back-end and front-end connected)
Codes
Note: if you are not a developer, you can skip this part!
After some research, I found a way to manage more MySQL connections without disconnection errors!
I create a pool of MySQL connections instead of a single MySQL connection
const pool = mysql.createPool({
connectionLimit: 1000,
host: config.db.host,
user: config.db.user,
password: config.db.pw,
database: config.db.name,
charset: 'utf8mb4'
})
This pool will handle up to 1,000 live MySQL connections. Also, the pool is able to add extra connections to the queue!
Then, I coded the MySQL query() method to return a promise
const con = {}
con.query = async (query, val) => {
if (val) {
let qu = await new Promise((resolve, reject) => {
pool.query(query, val, (error, results) => {
if (error) reject(new Error(error))
resolve(results)
})
})
return qu
} else {
let qu = await new Promise((resolve, reject) => {
pool.query(query, (error, results) => {
if (error) reject(new Error(error))
resolve(results)
})
})
return qu
}
}
This function will create new MySQL connections in the pool then will return received result of query, after returning result, that connection will be released in the pool to handle another query!
Also, handling errors are easier in this function!
I edited all functions to return a promise, with this, about 100 lines of codes reduced!
Also, syncing user's data is under development, I just uploaded a file and development will be inside that file.
(Actually, I'm going to add some minor features to the Steemauto then switch back to the Dblog)
This contribution submitted to the https://utopian.io
Support this new project by your upvotes and witness votes. Thanks for your great support:)
Regards,
2018-07-11