Node.js 上 SQL Server 的 ORM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15512673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:56:09  来源:igfitidea点击:

ORM for SQL Server on Node.js

sql-servernode.jsorm

提问by L N

I'm on the look for an ORM mapper for SQL Server on Node.js. Long story short, we have a SQL Server running and now we want to use node.js to build web services pulling data from the database.

我正在为 Node.js 上的 SQL Server 寻找 ORM 映射器。长话短说,我们有一个 SQL Server 正在运行,现在我们想使用 node.js 来构建从数据库中提取数据的 Web 服务。

Do you know any ORM that supports SQL Server on Node.js?

你知道在 Node.js 上支持 SQL Server 的任何 ORM 吗?

I know that there is this tediouswhich can help connect to SQL Server but it does not have ORM.

我知道有一个乏味的东西可以帮助连接到 SQL Server,但它没有 ORM。

Thanks

谢谢

采纳答案by Jonathan Lonowski

SQL Server so far hasn't gotten a great deal of support yet in the Node.js community. And, since most of the Node.js ecosystem is community-driven, your options will likely be rather limited.

到目前为止,SQL Server 还没有在 Node.js 社区中获得大量支持。而且,由于大多数 Node.js 生态系统都是社区驱动的,因此您的选择可能相当有限。

That's not to say there aren't plans to add support for it; just that not many have achieved it yet. Example: The author of sequelizehas stated intent to add support eventually.

这并不是说没有计划增加对它的支持;只是还没有多少人做到了。示例: 的作者sequelize已表示最终打算添加支持

For now, if it's enough to get plain Objects with columns as keys, Microsoft's own msnodesqlcan be a good option with its query()method:

现在,如果这是足以让普通的Object有作为键列S,微软自己msnodesql可以与一个不错的选择它的query()方法

sql.query(conn_str, "SELECT 1 as X, 'ABC', 0x0123456789abcdef ", function (err, results) {

    assert.ifError(err);

    var buffer = new Buffer('0123456789abcdef', 'hex');
    var expected = [{ 'X': 1, 'Column1': 'ABC', 'Column2': buffer}];

    assert.deepEqual(results, expected, "Results don't match");

    done();
});

回答by alesscor

According to sequelize's documentation, ormsupport for sql-serveris available in version 2.0 (released on Feb. 10, 2015, previously added on Dec. 22, 2014's release candidate).

根据sequelize文档ormsql-server 的支持在 2.0 版中可用(于20152 月 10 日发布,之前在201412 月 22 日的候选发布版本中添加)。

回答by Niall Paterson

I like Node-odbc, I think some kind of ODBC abstraction is probably best all RDBMS' with NodeJS

我喜欢Node-odbc,我认为某种 ODBC 抽象可能是 NodeJS 中所有 RDBMS 的最佳选择

回答by Tim Macfarlane

Have a look at mssql-orm. It supports writing large object graphs to SQL Server, but has a very lightweight API:

看看mssql-orm。它支持将大型对象图写入 SQL Server,但有一个非常轻量级的 API:

var person = db.model({table: 'people'});

var bob = person({
  name: 'bob'
});

bob.save();

回答by bgerth

I am using BookshelfORM, it has built-in support for MS SQL Server via its dependency on Knex.js, though it's not explicitly listed on the Bookshelf website.

我正在使用BookshelfORM,它通过对Knex.js 的依赖内置了对 MS SQL Server 的支持,尽管 Bookshelf 网站上没有明确列出。

Specify client: 'mssql'on initialization of Bookshelf.

client: 'mssql'在书架初始化时指定。