Jovo MySQL connection config not found


#1

Hello,

We’ve got another problem when saving user-data to a MySQL-database. We followed the tutorial on https://www.jovo.tech/docs/databases/mysql resulting in the following code:

config.ts

// ------------------------------------------------------------------
// APP CONFIGURATION
// ------------------------------------------------------------------

const config = {
   logging: true,

   intentMap: {
      'AMAZON.StopIntent': 'END',
   },

    db: {
        MySQL: {
            tableName: '*some_name*',
            connection: {
                host:'*some_address*',
                port:'3306',
                user:'some_user',
                password:'some_password',
                database:'some_database',
            },
        },
    },
};

export = config;

app.ts

*other imports*

import {MySQL} from 'jovo-db-mysql';
// ------------------------------------------------------------------
// STATES
// ------------------------------------------------------------------

const app = new App();

app.use(
    new Alexa(),
    new GoogleAssistant(),
    new JovoDebugger(),
    new MySQL(),
);

app.setHandler(
*app logic*
);

export {app};

When starting jovo by using tsc followed by jovo run the following error occurs:

 Error -----------------------------------------------------------------
  
  Code:
  ERR_PLUGIN
  
  Message:
  A connection config is needed.
  
  Stack:
  Error: A connection config is needed.
  at MySQL.install (/Users/christoph/Documents/apothekennotdienst-skill/node_modules/jovo-db-mysql/src/MySQL.ts:32:19)
  ....

What are we doing wrong?


#2

Oops, yeah… there’s a bug :slight_smile:

You have two workarounds until the fix.

app.use(
    new GoogleAssistant(),
    new Alexa(),
    new JovoDebugger(),
    new MySQL((app.$config.db as any).MySQL),
);
app.use(
    new GoogleAssistant(),
    new Alexa(),
    new JovoDebugger(),
    new MySQL({
        tableName: '*some_name*',
        connection: {
            host:'*some_address*',
            port:3306,
            user:'some_user',
            password:'some_password',
            database:'some_database',
        },
    }),
);

#3

Great, thank you! Works like expected now.


#4

facing the same issue
using >
const { MySQL } = require(‘jovo-db-mysql’);
then inside the app.use write
new MySQL() and also try with new MySQL((app.$config.db as any).MySQL),
both are causing error

Code:
ERR_PLUGIN

Message:
connect ECONNREFUSED 127.0.0.1:3306

please help to resolve this issue


#5

Is the MySQL DB running on localhost?