node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

double find will return wrong data

Open wp3xpp opened this issue 10 years ago • 8 comments

such as this: models.users.find().only("email", "name", "admin", "created_at").run(function(err, users){ if(err){ throw err; } console.log(JSON.stringify(users)); res.json(users); }); when i run this function twice, except first run, Behind results will only have the last data.

wp3xpp avatar Aug 03 '15 07:08 wp3xpp

such that

models.users.find().only("email", "name", "admin", "created_at").run(function(err, users){
            if(err){
                throw err;
            }
            console.log(JSON.stringify(users));
});

models.users.find().only("email", "name", "admin", "created_at").run(function(err, users){
            if(err){
                throw err;
            }
            console.log(JSON.stringify(users));
});

models.users.find().only("email", "name", "admin", "created_at").run(function(err, users){
            if(err){
                throw err;
            }
            console.log(JSON.stringify(users));
});

it will return [{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null,"created_at":1438508370808,"id":null},{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null,"c reated_at":1438508516420,"id":null},{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null,"created_at":1438572358034,"id":null}] [{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null,"created_at":1438572358034,"id":null},{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null ,"created_at":1438572358034,"id":null},{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null,"created_at":1438572358034,"id":null}] [{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null,"created_at":1438572358034,"id":null},{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null ,"created_at":1438572358034,"id":null},{"email":"[email protected]","passwd":null,"admin":true,"name":"ddd","image":null,"created_at":1438572358034,"id":null}]

wp3xpp avatar Aug 03 '15 09:08 wp3xpp

models.users.find(function(err, users){
            if(err){
                throw err;
            }
            console.log(JSON.stringify(users));
});

if i use this code it will return true result chain has a bug?

wp3xpp avatar Aug 03 '15 09:08 wp3xpp

一看这英语不用猜就知道肯定是中国人。。

hacke2 avatar Aug 28 '15 06:08 hacke2

Can you set 'debug: true' in the connection settings and paste the SQL here?

This seems rather odd.

dxg avatar Aug 28 '15 07:08 dxg

yes, I set it like:

var opts = {
    database: "inspiration",
    protocol: "mysql",
    host: "127.0.0.1",
    port: 3306,
    username: "root",
    password: "root",
    query: {
        debug : false,
        pool: true
    }
};

it can print many detail info,contain query sql, but It's hard to find。

i can only user this command to mysql now:

SHOW VARIABLES LIKE "general_log%"; 
SET GLOBAL general_log = 'ON'; 

hacke2 avatar Aug 28 '15 07:08 hacke2

Can you change it to: query: { debug2: true } and then change this line to if (this.opts.debug2) {

I suspect the newer versions of mysql driver also use the debug flag and it causes a lot of noise. It works fine with postgres and sqlite.

dxg avatar Aug 28 '15 07:08 dxg

:ok:

hacke2 avatar Aug 28 '15 07:08 hacke2

Hey, I fixed the noisy mysql debug output and released version v2.1.27 Please update rather than using the hack above.

dxg avatar Aug 28 '15 07:08 dxg