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

nSQL: Database not connected, can't do a query! #37

Closed
kavaro opened this issue Apr 24, 2018 · 2 comments
Closed

nSQL: Database not connected, can't do a query! #37

kavaro opened this issue Apr 24, 2018 · 2 comments
Labels

Comments

@kavaro
Copy link

@kavaro kavaro commented Apr 24, 2018

When I enable history my app errors with "nSQL: Database not connected, can't do a query!"
When disabling history, the app works as expected.

I extracted a small example to demonstrate the issue...

I am using version 1.5.1

import {nSQL} from "nano-sql";

nSQL('users')
    .model([
        {key:'id',type:'int',props:['pk','ai']},
        {key:'name',type:'string'}
    ])
    .actions([
        {
            name: 'createUser',
            args: ['name:string'],
            call: async (opts, db) => await db.query('upsert', {name: opts.name}).exec()
        }
    ])
    .views([
        {
            name: 'allUsers',
            args: [],
            call: async (opts, db) => await db.query('select').exec()
        }
    ]);

async function test(history) {
    await nSQL()
        .config({
            history
        })
        .connect();
    const users = nSQL('users');
    await users.doAction('createUser', {name: 'bill'});
    await users.doAction('createUser', {name: 'bob'});
    await users.doAction('createUser', {name: 'jeb'});
    console.log(await users.getView('allUsers'));
}

// when ENABLE_HISTORY === true -> nSQL: Database not connected, can't do a query!
// when ENABLE_HISTORY === false -> everything works as expected
const ENABLE_HISTORY = true; 

test(ENABLE_HISTORY).catch(err => console.error(err));
@only-cliches
Copy link
Owner

@only-cliches only-cliches commented Apr 24, 2018

Just pushed v1.5.2, issue should be resolved.

Thanks for the heads up!

@kavaro
Copy link
Author

@kavaro kavaro commented Apr 25, 2018

Thanks for the fix, it is working

@kavaro kavaro closed this Apr 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants