我需要 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/