Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql adapter models get reset after reconnection #191

Open
raffaele-clevermind opened this issue Jun 26, 2018 · 0 comments
Open

Mysql adapter models get reset after reconnection #191

raffaele-clevermind opened this issue Jun 26, 2018 · 0 comments

Comments

@raffaele-clevermind
Copy link

when the client has the option "autoReconnect" set to true, the method "handleDisconnect" creates a new connection as shown in the code below:

function handleDisconnect(client) {
        schema.client.on('error', function (error) {
            if (error.code !== 'PROTOCOL_CONNECTION_LOST') throw error;
            console.log('> Re-connecting lost MySQL connection: ' + error.stack);
            if (s.pool) {
                schema.client = mysql.createPool(conSettings);
                schema.client.getConnection(function (err, connection) {
                    if (err) {
                        throw new Error(err);
                    }
                });
                schema.adapter = new MySQL(schema.client, conSettings);
                schema.adapter.schema = schema;
                schema.client.once('connection', function (connection) {
                    startAdapter(schema, dbName, callback);
                });
                handleDisconnect(schema.client);
            } else {
                schema.client = mysql.createConnection(conSettings);
                schema.adapter = new MySQL(schema.client, conSettings);
                schema.adapter.schema = schema;
                startAdapter(schema, dbName, callback);
                handleDisconnect(schema.client);
            }
        });
    }

When the adapter creates a new istance of the MySQL prototype it will reset the models structure:

function MySQL(client, conSettings) {
    'use strict';
    this.name = 'mysql';
    this._models = {};
    this.log = console.log;
    this.client = client;
    this.settings = conSettings;
}

This means the client won't be usable anymore unless you re-initialize all the models again manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant