如何在书架上批量“插入”?

我需要从一个CSV文件(大约20K行)将数据导入到我的数据库。 有些行可能已经存在于数据库中,因此只需要更新它们,但是必须插入新的行。 如果任何操作失败,交易必须取消。 我怎样才能做到这一点? 这是我正在使用的代码: var vehicle = { id: row.id, lastUpdate: moment(row.lastUpdate, 'DD/MM/YYYY – HH:mm').toDate(), version: row.version, color: row.color, location: row.location, status: row.status }; Vehicle.forge({ id: row.id }) .save(vehicle, { transacting: t, patch: true }) .then(model => { console.log('*************' + vehicle.id); }) .catch(Vehicle.NoRowsUpdatedError, err => { // There are no rows for this chassis, […]

Firebase工具:以服务帐号login

我无法find如何代表服务帐户部署Firebase项目(function)的方式。 在文档页面上都没有说什么,也没有发现他们的错误跟踪器没有任何关系。 如上所述,我运行firebase login:ci命令,但后来我需要login自己 – 我想login为服务帐户。 这种function可以使用gcloud工具,但正如文档中所述 , 使用Firebase SDK for Cloud函数编写的云function无法使用gcloud命令行工具进行部署,反之亦然。

成功sendToDevice后,Firebase云消息传递不起作用

我使用Firebase云端function通过云端消息向iOS设备发送通知。 sendToDevice方法工作良好,并返回成功承诺,在Firebase函数日志中没有任何错误或警告,但在iOS上,不显示通知。 如果我通过Firebase通知信息中心发送通知,该通知很有用,并且会在设备上显示通知。 我不知道我在哪里可以有bug。 有可能是iOS应用程序端的错误,即使它像我说的那样工作? Firebaseconfiguration: var functions = require('firebase-functions'); var admin = require('firebase-admin'); var config = functions.config(); admin.initializeApp(functions.config().firebase); 部分云function: APP.services.firebase.admin.database().ref('tokens/' + userId).once('value', function(snapshot) { var userDevicesTokens = []; snapshot.forEach(function(childSnapshot) { userDevicesTokens.push(childSnapshot.key) }); if (userDevicesTokens.length === 0) { console.warn('No tokens for user'); return; } var payload = { data: { title: options.title, text: options.text, type: […]

URL不是一个函数node.js

我一直在尝试使用这里描述的节点js的url模块: https : //nodejs.org/api/url.html#url_url ,但我似乎无法得到简单的例子工作。 我想能够build立一个url,但与下面的代码, const URL = require('url'); const apiUrl = new URL('myapi.com/'); apiUrl.searchParams.set('tickers', tickers); console.log(apiUrl.href); 我遇到了错误,该URL不是一个函数。 我已经尝试了与网站build议初始化URL的其他方式,如 const { URL } = require('url'); 但是,这会导致第一个打开的括号中的语法错误。 我如何使用url模块来实际操作url? 编辑: 根据MinusFour的build议,我现在到了这里: const URL = require('url').Url; const apiUrl = new URL('myapi.com/'); console.log(apiUrl); apiUrl.search = 'tickers=[\'msft\']'; console.log(apiUrl.href); 这确实编译和运行,而不会引发错误,但日志 Url { protocol: null, slashes: null, auth: null, host: null, […]

无法为具有babel-node的节点启动VSCodedebugging器

当我键入npm run debug到控制台时,我得到: "Debugger listening on ws://127.0.0.1:3090/d17dfe56-4fa4-4686-a62e-d07cff78c834" 。 当我在chrome中访问这个地址时,我所看到的唯一情况就是"WebSockets request was expected" 。 我应该调整哪些部分的configuration来使debugging器工作? 我正在使用最新版本的nodejs。 package.json脚本 "scripts": { "prod": "webpack -p –env.production –progress", "start": "babel-node –presets es2015 server/server.js", "watch": "nodemon –exec npm run start", "debug": "babel-node –presets es2015 server/server.js –inspect –debug-brk=3090" } launch.json: { "version": "0.2.0", "configurations": [ { "name": "Launch via NPM", "type": "node", […]

状态没有正确设置 – 反应原生

我从我的代码中得到的东西很困惑。 我有下面这应该注销data.points然后将this.state.points设置为data.points ,然后注销this.state.points ,但是当它们注销它们不相等。 这是我正在使用的确切代码,所以我确信它是输出的。 我可能忽略了一些东西,但是我花了一个小时来阅读和注销这些代码,但是我仍然无法弄清楚。 这是我运行的代码: console.log(data.points); if (!this.state.hasPressed) { this.setState({points: data.points}) console.log('in not hasPressed if'); } console.log(this.state.points); 然而在chrome远程debugging器中,我得到了这个: ["114556548393525038426"] in not hasPressed if []

NodeJS / Express + HTTPS:如何将密钥和证书部署到AWS EC2节点?

Node.js&Express.js是我用来编写Web API服务的新手。 要启用HTTPS,服务使用以下代码: const server = https .createServer({ key: fs.readFileSync('./cert/myservice.key'), cert: fs.readFileSync('./cert/myservice.crt') }) .listen(serverConfig.server.port, () => logger.info(`MyService is up and running`)); 很容易看出,这段代码假设.key和.crt文件在服务应用程序位置本地可用。 如果我想将服务部署到单个AWS EC2主机(为了简单起见),这些文件将不得不在那里,这似乎不是一个安全的解决scheme。 我正在考虑使用AWS IAM来保护这些秘密。 问题在于无法直接从IAM“部署”/将密码提供给EC2节点。 我不得不使用IAM的API来获取秘密,但问题是如何使EC2上的AWS凭证可用。 问题:是否有build议的安全方式将密钥(包括证书和密钥)部署到AWS EC2节点?

JS Promise waitFor刷新令牌

情况很简单: 我有一个nodejs服务器(称为API-A)使用蓝鸟作为承诺处理程序。 我有一个客户端(浏览器),通过从另一个API(API-B)获取数据的API-A询问数据。 API-B可以是来自示例的气象服务,然后API-A将数据与其他数据聚合并将其发送回客户端。 情况是下一个:API-B需要一个具有1800秒的TTL的令牌。 因此,对于客户端的每个请求,我检查我的令牌是否过期。 我有这样的代码: function getActivities() { return this.requestAuthorisation() .then(()=>{ // some other code that is not interesting }) } 一切工作都很好,承诺的荣耀。 requestAuthorisation()检查令牌是否有效(下一个!!!),如果没有(我做一个请求API-B刷新令牌)问题在于:在这个时间之间,令牌已经过期以及获得的时间一个新鲜的,有时会发生。 如果1000个客户端同时询问这些,我将有1000个令牌对API-B的请求,这不是很酷。 我怎样才能避免呢? 我尽量避免使用cron-way,避免不必要的调用,问题是一样的。 我尝试创build一个跟踪令牌刷新状态的全局variables(boolean),但不可能find一种Promise.WaitFor(variables更改)的Promise.all无法使用,因为我处于不同的事件范围。 有没有办法排队,直到令牌刷新? 请帮忙 !

在knex中迁移表:存储媒体,图像或blob

我正在尝试将关系迁移到我的postgres数据库。 问题是我不知道图像使用什么值types。 exports.up = function (knex, Promise) => { return knex.schema.createTable('observations', (table) => { table.increments(); table.integer('user_id').notNullable(); table.blob('image').notNullable(); //??? table.string('category').notNullable(); table.string('description').notNullable(); table.boolean('approved').notNullable().defaultTo(false); table.float('latitude').notNullable(); table.float('longitude').notNullable(); table.timestamp('created_at').defaultTo(knex.fn.now()); }); }; 我以为会有一个“blob”文件types,但在文档中似乎没有迁移任何媒体的迹象。 请帮帮我。

我可以在REST API中为不同的方法编写相同的path名吗?

我正在使用Swagger API编写REST API。 现在,我想以下面的方式编写插入,更新和删除的方法(我已经看到许多API在线上的这样的path): POST (插入) /学生们 PUT (用于更新) /学生/ {} studentId 删除 (删除) /学生/ {} studentId 现在,1是好的,但2和3是相同的path(但有不同的方法)。 Swagger API给我错误,当我这样写。 那么这真的不被允许? 如果不允许,那么定义不同path的最好方法是什么,而不要让它们变长,仍然看起来很酷?