最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

为什么node

运维笔记admin12浏览0评论

为什么node

为什么node

我是node.js和javascript研究的新手,我正在尝试构建一个后端以从Firebird数据库中获取信息。

我正在使用我所遵循的课程中的某些依赖项。我的项目为“表达”,“ nodemon”,“ node-firebird”。

使用以下结构:

Project structure

我的server.js文件中的代码是:

const firebird = require('node-firebird');
const express = require('express');
const app = express();
//const teste;

const options = {
  host: '127.0.0.1',
  database: 'C:/Users/alexandrefelix.GREENCANE/Desktop/Aulas/backend-firebird/src/TGA.FDB',
  user: 'SYSDBA',
  password: 'masterkey',
};


app.get('/', (req, res) => {

  // 5 = the number is count of opened sockets
  var pool = firebird.pool(5, options);

  // Get a free pool
  pool.get(function(err, db) {

    if (err)
        throw err;

    // db = DATABASE
    db.query('SELECT * FROM GEMPRESA', function(err, result) {
        // IMPORTANT: release the pool connection
        console.log(result);
        db.detach();
    });

  });

  // Destroy pool
  pool.destroy();

  return res.json({ message: 'Hello World!'});

});


app.listen(3333);

因此,当我运行代码并在浏览器中访问“ localhost:3333”时,它会显示我的测试消息(Hello World),但在控制台中,它会将varchar字段显示为缓冲区:

城市:缓冲区55 42 45 52 41 42 41

何时应该:

城市:“ UBERABA”

我的问题是为什么返回的JSON以这种方式显示VARCHAR字段,以及如何将列的结果放入变量中。

回答如下:

结果实际上是需要解析的resultSet

result.forEach( function(row) {
   console.log( row.id, ab2str(row.name)); //id and name are fields from the select *
});

function ab2str(buf) {
   return String.fromCharCode.apply(null, new Uint16Array(buf));
}

更多信息:https://github/hgourvest/node-firebird/wiki/Example-of-querying-using-Promises

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论