【问题标题】:What is the best way to set indexes in MySQL database tables with SailsJS?使用 SailsJS 在 MySQL 数据库表中设置索引的最佳方法是什么?
【发布时间】:2017-07-19 06:22:50
【问题描述】:

Waterline supports indexing out of the box,很遗憾不适用于任何适配器。

sails-mysql 适配器似乎不支持它。

例如,模型中的以下字段会出错:

user: { 
  model: 'user',
  index: true
}

错误:topic 模型上的属性 user 包含无效属性。 index 的属性不是公认的属性。

问题是,如果适配器不支持索引,那么在 SailsJS 中最好的方法是什么?

我正在使用:

{
  "sails": "^1.0.0-27",
  "sails-mysql": "^1.0.0-7",
  "waterline": "v0.13.0-rc4"
}

【问题讨论】:

标签: mysql node.js sails.js waterline


【解决方案1】:

在对sails-mysqlwaterline-schemawaterline 模块进行逆向工程后,我发现了在autoMigrations 属性中设置索引的未记录的可能性。如下:

foo: { 
  type: 'number'
  autoMigrations: { index: true }
}

【讨论】:

  • 有趣的发现,当涉及到这样的案例时,我个人只是选择更多的原生方法。因此,具有类似 createTable 方法的服务可以使用 mysql@npm 之类的方法同时创建表和索引。
猜你喜欢
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-08
  • 2012-02-28
  • 1970-01-01
  • 2012-09-23
  • 2012-01-19
相关资源
最近更新 更多