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

connection exception #38

Closed
wonmank opened this issue Apr 26, 2018 · 2 comments
Closed

connection exception #38

wonmank opened this issue Apr 26, 2018 · 2 comments
Labels

Comments

@wonmank
Copy link

wonmank commented Apr 26, 2018

Hi there,

function nanoTest() {
nSQL('users') // "users" is our table name.
.model([ // Declare data model
{key:'id',type:'int'},
{key:'name',type:'string'},
{key:'age', type:'int'}
])
.connect() // Init the data store for usage. (only need to do this once)
.then(function(result) {
return nSQL().query('upsert', [
{id:1, name:"bill", age: 20},
{id:2, name:"tom", age: 30},
{id:3, name:"john", age: 33}
]).exec();
});

nSQL('users2') //  "users" is our table name.
.model([ // Declare data model
         {key:'id',type:'int'}, 
         {key:'tel',type:'string'},
         {key:'cell', type:'string'}
     ])
.connect() // Init the data store for usage. (only need to do this once)
.then(function(result2) {
	return nSQL().query('upsert', [
       {id:1, tel:"02-111-1111", cell: '010-1111-1111'},
       {id:2, tel:"02-345-3456", cell: '010-1111-1112'},
       {id:3, tel:"02-123-3456", cell: '010-1111-1112'}
    ]).exec();
});

// 데이터 조인
nSQL("users")
.query("select",["users2.id", "users.name","users.age","users2.tel","users2.cell"])
.where(["users.id",">",0])
.join({
    type:"inner", // Supported join types are left, inner, right, cross and outer.
    table: "users2",
    where: ["users.id", "=", "users2.id"] // any valid WHERE statement works here
}).exec().then(function(rows) {console.log(rows);

});
}

But I saw a exception.
uncaught exception: nSQL: Database not connected, can't do a query!

I tested on firefox.

@only-cliches
Copy link
Owner

The problem is towards the bottom, this bit of code:

// 데이터 조인
nSQL("users")
.query("select",["users2.id", "users.name","users.age","users2.tel","users2.cell"])
.where(["users.id",">",0])
.join({
    type:"inner", // Supported join types are left, inner, right, cross and outer.
    table: "users2",
    where: ["users.id", "=", "users2.id"] // any valid WHERE statement works here
}).exec().then(function(rows) {console.log(rows);

You can't call a query until you connect the database, the best option is just adding an onConnect callback around it.

nSQL().onConnected(() => {
    // 데이터 조인
    nSQL("users")
    .query("select",["users2.id", "users.name","users.age","users2.tel","users2.cell"])
    .where(["users.id",">",0])
    .join({
        type:"inner", // Supported join types are left, inner, right, cross and outer.
        table: "users2",
        where: ["users.id", "=", "users2.id"] // any valid WHERE statement works here
    }).exec().then(function(rows) {console.log(rows);
});

@only-cliches
Copy link
Owner

Marking this resolved, feel free to reopen it if you run into the issue again.

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

No branches or pull requests

2 participants