【问题标题】:Node.js Oriento driver example with error handling带有错误处理的 Node.js Oriento 驱动程序示例
【发布时间】:2023-03-19 05:01:01
【问题描述】:

我是 node.js 的新手,正在尝试使用 orientdb 作为数据存储来自学 node。我使用oriento 作为驱动程序。

我希望能够处理我的代码中的任何连接错误,但在初始连接到 orientdb 服务器和连接到我的数据库期间找不到任何示例:

var express = require('express');
var oriento = require('oriento');

var server = oriento({
    host: "localhost",
    port: 2424,
    username: "root",
    password: "test"
});

如果服务器出现连接错误,我该如何捕捉? 稍后当我想使用服务器中的特定数据库时:

var db = server.use({
    name: 'blog',
    username: 'admin',
    password: 'admin'
});

如果在“使用”这个数据库时出现错误,我该如何发现?

我可以从 oriento 文档中弄清楚如何在查询等期间处理错误,但在这些初始步骤中卡住了。

【问题讨论】:

    标签: node.js orientdb oriento


    【解决方案1】:

    这里是如何。基本上,它会在第一个请求时自动连接到服务器。对于连接错误,每个请求都需要catch

    var Oriento = require('oriento');
    
    var server = Oriento({
        host: 'localhost',
        port: 2424,
        username: 'root',
        password: 'BDFE8AC356595663AF66ADF08E703DE30DF5755F99DE9D329EFF75A5CB8A9CE8'
    });
    
    server
        .list()
        .then(function (dbs) {
            console.log('There are ' + dbs.length + ' databases on the server.');
    
            var firstDB = dbs[0];
    
            var orientDB = server.use({
                name: firstDB.name,
                username: firstDB.username,
                password: firstDB.password
            });
    
            console.log('Using database: ' + orientDB.name);
        })
        .catch(function (err) {
            console.log(err);
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      • 2017-01-26
      • 1970-01-01
      相关资源
      最近更新 更多