Registers the contexts and methods of the module mySQL in microTasks.
Context item list registered in microTasks.
Name | Type | Default | Description |
---|---|---|---|
mysql.connection.database | string |
Connection data base name | |
mysql.connection.debug | boolean |
false |
Connection debug mode |
mysql.connection.host | string |
Connection host | |
mysql.connection.password | string |
Connection password | |
mysql.connection.port | number |
3306 |
Connection port |
mysql.connection.user | string |
Connection user |
Executes a mysql query and returns the response.
Name | Type | Default | Description |
---|---|---|---|
data | object |
{} |
query configuration |
data.query | string |
mySQL query | |
[data.connection] | object |
{} |
Connection configuration. This object extends from context.mysql.connection |
[data.handler] | string |
"rows" |
Response handler, it can be column (array of values), field (value), row (object) or rows (array of objects) |
Example
microTasks.taskRun([{
method: 'mysql.query',
params: {
connection: {
host: '127.0.0.1',
user: 'db_user',
password: 'db_pass'
},
query: 'SELECT email FROM db_name.users WHERE id=123 LIMIT 1',
handler: 'field' // returns user email as a value
}
}])