User Tools

Site Tools


This is an old revision of the document!



The mySQL SIB Caller is a specific mySQL caller that performs operations on a mySQL database. The caller simply performs the [msg.sql] operation on the database and returns the result. It is recommended to generate the [msg.sql] field in the inputFormat, overwriting whatever value was received from the MQTT transport, for safety reasons. The [msg.sql] field can then be deleted in the outpuFormat method if needed.

If the [msg.sql] contains ? placeholders the [msg.placeholder] must contain the array of values to substitute the placeholders with.




  • Subscribe: .custom.topic
    • on message:
      • custom.inputFormat
        • if msg.result is set
          • Respond with result from inputFormat
        • else
          • Perform operation on database
          • custom.outputFormat
          • Publish message on responseTopic with the result from the database operation

Custom configuration

var mySQLCallerCustom = {
	_id: "mySQLSample:1",
	_name: "MySQLCallerSample",
	inputFormat: (topic, msg, cb, mysqlConnection)=>{
		msg.sql = "INSERT INTO test (test, num) VALUES ('a',1), ('b',2)";
	loggerCfg: {
		dest: {
			file: false,
			console: true,
			mqtt: true
	mysql: {
		host: "localhost",
		user: "sibtest",
		password: "sibtest",
		database: "sibtest"
	outputFormat: (topic, msg, cb, mysqlConnection)=>{
		delete( msg.sql );
	mqtt: "mqtt://localhost",
	topic: "SIB/test/mySQLCaller"
module.exports = mySQLCallerCustom;
  • _id: The unique ID of this service
  • _name: A plaintext description of this service
  • inputFormat(topic, msg, callback, mysqlConnection): The method that is run on service activation. The original message is passed as the argument and the input value to the callback must be a JSON formatted message conforming to the SIB message standard. As of version 1.3.2 the mySQLCallers mysql connection is passed to the inputFormat. If msg.result is set in the returned message no further database actions will be taken by the caller.
  • loggerCfg: A JSON Object defining what logger actions should be active for this service (see Logger Configuration
  • mysql: Database configuration. The below fields are required but everything that can be passed to mysql.connect can be set here
    • host: The host of the database server
    • user: The user to log in as
    • password: The password for the user
    • database: The database to connect to
  • outputFormat(topic, msg, callback, mysqlConnection): This message is run on the response data before publishing to the response topic. The response message is passed as the argument and the input to the callback must be a JSON formatted message conforming to the SIB message standard.
  • mqtt: The MQTT connection string for the internal MQTT transport
  • topic: The MQTT topic to subscribe to on the internal MQTT transport
sib/callers/mysqlcaller.1557747576.txt.gz · Last modified: 2019/05/13 11:39 by hubbe