postgresql - 如何将索引添加到 postgres 表?
问题描述
我正在尝试使用 Vapor 向 PostgreSQL 表添加列索引。我找到了几个这样做的教程,但这些代码片段都不适用于当前版本。
解决方案
据我所知,用 Fluent 创建索引是不可能的。在我的 Vapor3 项目中,我使用自己的小扩展和原始查询 https://gist.github.com/MihaelIsaev/f6442bf3698572cd9170114f236c47c2
你可以像这样使用它
extension CarBrand: Migration {
public static func prepare(on connection: Database.Connection) -> Future<Void> {
return Database.create(self, on: connection) { builder in
try addProperties(to: builder)
}.flatMap { _ in
return connection.addIndexes(\CarBrand.addedByUser, \CarBrand.createdAt)
}
}
}
希望能帮助到你 :)
推荐阅读
- javascript - Javascript onload 未在 IE11 中触发
- c# - 实体框架播种不创建数据
- rest - 定义通知端点的最佳方法是什么?
- node.js - ldap 套接字选项 - ldapjs
- wordpress - 当我在谷歌页面速度上检查我的网站时,它会向我显示 WordPress 中某些字体的预加载错误
- python - 将数据框中所有值的科学记数法中的“D”替换为“E”
- css - 如何使用 css 更改表格的样式?
- python - Scrapy 自定义链接提取器以限制跟随的链接数量
- node.js - 未找到 npm 模块
- optimization - 决策树的 CART 算法中的基尼指数如何最小化?