我的对象在JavaScript中未定义

时间:2019-09-04 09:56:04

标签: javascript

我是JavaScript的初学者,这似乎是一个完全的菜鸟问题,但我遇到的问题是对象未定义。

const createTodoTable = new M(
  "table", // name
  "schema", // schema
  "table.sql" // SQL file
)

const mS = [{
  migrations: [createTodoTable],
  sequenceName: "init"
}]

console.log(mS);

当我调用console.log时,我得到正确的输出,即[ { migrations: [ [Migration] ], sequenceName: 'init' } ]

massive(dbConfig).then((db) => {
 console.log(mS);
})

但是当我在这里打电话时,我得到undefined.

这是什么原因?

编辑

const { BaseActionWatcher } = require("demux")
const { MongoActionReader } = require("demux-eos")
const { MassiveActionHandler } = require("demux-postgres")
const { M } = require("demux-postgres")
const massive = require("massive")

const handlerVersions = [
      {
        versionName: 'v1',
        deferUntilIrreversible: true,
      },
  ]

const createTodoTable = new M(
  "table", // name
  "schema", // schema
  "table.sql" // SQL file
)

const mS = [{
  migrations: [createTodoTable],
  sequenceName: "init"
}]

console.log(mS);


const dbConfig = {
  host: '127.0.0.1',
  port: 5432,
  database: 'db',
  user: 'user',
  password: 'pass'
}

massive(dbConfig).then((db) => {
    console.log(mS);
        const actionHandler = new MassiveActionHandler(
    handlerVersions,
    db,
    dbConfig.schema,
    mS
  )
  const actionReader = new MongoActionReader({
    startAtBlock: 1234,              // startAtBlock: the first block relevant to our application
    onlyIrreversible: false,         
    dbName: "db2",                   // name of the database
    mongoEndpoint: "uri",
  })
  const actionWatcher = new BaseActionWatcher(actionReader, actionHandler, 500)
  actionReader.initialize().then(()=>
  actionWatcher.watch())
})

0 个答案:

没有答案