第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何移動(dòng)代碼以從我的文件中設(shè)置 ut DB 和集合并只需要它?

如何移動(dòng)代碼以從我的文件中設(shè)置 ut DB 和集合并只需要它?

慕絲7291255 2023-02-24 15:31:17
所以,假設(shè)我有這段完美運(yùn)行的代碼。const {  Database} = require("arangojs");var db = new Database({  url: "http://localhost:8529"});const database_name = "cool_database";db.useBasicAuth("username", "password123");db.listDatabases()  .then(names => {    if (names.indexOf(database_name) > -1) {      db.useDatabase(database_name);      db.get();    } else {      db.createDatabase(database_name)        .then(() => {          db.useDatabase(database_name);          db.collection("my-collection").create();        });    }  });const collection = db.collection("my-collection");const getJobFromQueue = () => {  return db.query({      query: "FOR el IN @@collection FILTER DATE_TIMESTAMP(el.email.sendAfter) < DATE_NOW() AND el.status != 'processed' AND el.status != 'failed' SORT el.email.sendAfter LIMIT 1 RETURN el",      bindVars: {        "@collection": "my-collection"      }    })    .then(cursor => cursor.all());}但是我想將最上面的代碼移到另一個(gè)文件中,只需要 db 和 collection,我該怎么做呢?一直在努力讓它工作太久了。const {  db,  collection} = require("./db");const getJobFromQueue = () => {  return db.query({      query: "FOR el IN @@collection FILTER DATE_TIMESTAMP(el.email.sendAfter) < DATE_NOW() AND el.status != 'processed' AND el.status != 'failed' SORT el.email.sendAfter LIMIT 1 RETURN el",      bindVars: {        "@collection": "my-collection"      }    })    .then(cursor => cursor.all());}
查看完整描述

1 回答

?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

完全按照你的建議去做。將代碼的上半部分移動(dòng)到db.js并公開(kāi)db和collection使用exports:


數(shù)據(jù)庫(kù).js:


const {

    Database

} = require("arangojs");

  

var db = new Database({

    url: "http://localhost:8529"

});


const database_name = "cool_database";  

db.useBasicAuth("username", "password123");

db.listDatabases()

  .then(names => {

    if (names.indexOf(database_name) > -1) {

      db.useDatabase(database_name);

      db.get();

    } else {

      db.createDatabase(database_name)

        .then(() => {

          db.useDatabase(database_name);

          db.collection("my-collection").create();

        });

    }

  });


exports.collection = db.collection("my-collection");

exports.db = db;

索引.js:


const {

  db,

  collection

} = require("./db");


const getJobFromQueue = () => {

  return db.query({

      query: "FOR el IN @@collection FILTER DATE_TIMESTAMP(el.email.sendAfter) < DATE_NOW() AND el.status != 'processed' AND el.status != 'failed' SORT el.email.sendAfter LIMIT 1 RETURN el",

      bindVars: {

        "@collection": "my-collection"

      }

    })

    .then(cursor => cursor.all());

}

警告:


請(qǐng)記住,您的代碼中存在潛在的競(jìng)爭(zhēng)條件。在它們被初始化之前,您可能最終會(huì)使用dband 。collection


查看完整回答
反對(duì) 回復(fù) 2023-02-24
  • 1 回答
  • 0 關(guān)注
  • 152 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)