A mysql client tools for nodejs and want to look for a girlfriend...
$ npm i ai-mysql-client
import createMySQLClient from 'ai-mysql-client'
// https://www.npmjs.com/package/@blued-core/qconf
qconf.flag: isLocalPro ? 'production' : '',
const mysqlClient = key => {
return createMySQLClient({
key,
option: qconf,
connections: 20,
time: 60,
})()
// or
return createMySQLClient({
master: ['127.0.0.1:3306'],
slave: ['127.0.0.1:3306', '127.0.0.1:3306', '127.0.0.1:3306'],
username: 'root',
password: 'your@123',
database: 'test',
time: 60,
connections: 20,
}, key)()
}
async function getTest() {
const defaultMySQL = mysqlClient('default')
const sql = 'SELECT * FROM test_user LIMIT 0,10'
const res = await defaultMySQL.query(sql).catch(err => {
console.error(err, { tips: 'query error' })
})
console.log(res)
return res
}
// options
interface Config {
key?: string
option: any
connections?: number
time?: number
}
// or
interface MySQL {
master: Array<string>
slave: Array<string>
username: string
password: string
database: string
connections?: number
time?: number
}