javascript - 无法读取未定义的属性 'createManager'

标签 javascript sails.js

我需要 sails.js 动态创建新的数据存储适配器和连接 URL,我遇到了这个解决方案 https://sailsjs.com/documentation/reference/waterline-orm/datastores/driver ,其中指出我可以使用无状态驱动程序来完成此操作。

但不知何故我最终遇到了这个错误

TypeError: Cannot read property 'createManager' of undefined

这是我的示例代码:

let Driver = sails.getDatastore().driver;

let connectionUrl = `postgresql://postgres:postgres@localhost/test-db`;

let manager = (
    await Driver.createManager({ connectionString: connectionUrl })
).manager;

顺便说一句,我的 sails 版本是 1.2.1

最佳答案

This property is not guaranteed to exist for all database adapters. If the datastore's underlying adapter does not support the standardized driver interface, then driver will not exist

正如文档中明确指出的,您的数据源的底层适配器不支持标准化驱动程序接口(interface),因此驱动程序未定义,这就是您得到的原因,

TypeError: Cannot read property 'createManager' of undefined

关于javascript - 无法读取未定义的属性 'createManager',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56896701/

相关文章:

javascript - 仅当数字少于两位小数时才添加 .00 (toFixed)

javascript - 我不应该在 ES6 中使用 var 吗?

javascript - 如何在 Canvas 上绘制大量点(具有规则图案)?

node.js - 尝试从 Sails.js 应用程序执行 MongoDB 查询时出现奇怪的 "timeouts"

node.js - 在 Sails 中实现自定义 i18n 片段

javascript - 如何在 Node.js 上使用 co 模块捕获异常?

javascript - javascript 中的 GET 请求到 NodeJS

javascript - 下载 Angular 2 insideHTML 绑定(bind)内的脚本

ruby-on-rails - 如何在 sails js 中创建模型的新实例?

node.js - sails lift 导致错误 ENOENT(没有此类文件或目录)