PhilWaldmann / openrecord

Make ORMs great again!
https://openrecord.js.org
MIT License
486 stars 38 forks source link

mysql socketPath #98

Closed nowrap closed 4 years ago

nowrap commented 5 years ago

Hello, i am missing the socketPath option for mysql connections: https://openrecord.js.org/#/setup https://github.com/mysqljs/mysql#connection-options

I tried to use a connection object directly. but than autoLoad and autoConnect didn't work properly anymore:

// init
let config = me.app.getLocals().getConfig().openrecord;
// TODO: host based configs

/*let config = {};
config.connection = mysql.createConnection(openrecord);
config.autoLoad = openrecord.autoLoad;
config.autoConnect = openrecord.autoConnect;*/
config.plugins = [require('openrecord/lib/base/dynamic_loading')];
config.models = path.join(__dirname, '/models/*.js');

me.debug('initStore', {config: config});

me.store = new Store(config);

node_modules/openrecord/lib/stores/mysql/connection.js:

  this.connection = Knex({
      client: 'mysql',
      version: this.config.version || '5.7',
      connection: this.config.connection || {
        host: this.config.host || this.config.hostname,
        port: this.config.port,
        user: this.config.user || this.config.username,
        password: this.config.password,
        database: this.config.database,
        charset: this.config.charset
      }
    })

Does someone have an advise?

Regards nowrap

nowrap commented 5 years ago

This way it worked:

    // 2019-08-08 added manual socketPath support
    // https://github.com/PhilWaldmann/openrecord/issues/98
    let config = {};
    if (openrecord.socketPath) {
        config.connection = {
                socketPath: openrecord.socketPath,
                user: openrecord.user,
                password: openrecord.password,
                database: openrecord.database
        };
    } else {
        config.connection = {
                host: openrecord.host,
                user: openrecord.user,
                password: openrecord.password,
                database: openrecord.database
        };
    }
    config.type = openrecord.type;
    config.autoLoad = openrecord.autoLoad;
    config.autoConnect = openrecord.autoConnect;
    config.plugins = [require('openrecord/lib/base/dynamic_loading')];
    config.models = path.join(__dirname, '/models/*.js');