Skip to content

Global 'server' variable becomes undefined? #191

@radiolondra

Description

@radiolondra

I'm using a function to open the database and try to use the assigned server variable in other functions:

var server;

function OpenDB() {
  db.open({
      .....
  }).then(function(s) {
    server = s;
  });
}

function DoSomethingInDB() {
  console.log("Server var:", server); <<<< undefined
  server.mytable.count().then(function(ct) {  <<<error: Cannot read properties of undefined (reading 'mytable')
    ...
  });
}

....

OpenDB();
DoSomethingInDB();

My database is successfully created in OpenDB().
Unfortunately, it seems that the global server var becomes undefined outside the OpenDB function.
From documentation:

A connection is intended to be persisted, and you can perform multiple operations while it's kept open

But I didn't close it. Bah?
For sure I'm doing something wrong. Can you help me?
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions