node.js - How i can define index for a table in node.js (adonis)
问题描述
Actually i have this table:
ClassBookHistoric
-----------------
Id (Primary Key),
Class_Id (Unique key, foreign key of table Class),
BookUnit_Id (Unique key, foreign key of table BookUnits)
Book_Id
Status
I need to make queries to search data like this: SELECT WHERE Class_Id = (parameter), Book_Id = (parameter) and Status = 1 (active)
I'm studying about indexes and i'm thinking it is necessary to create a index using the columns that i will use to search data (Class_Id, Book_Id and Status
) to increase the performance. There's a way to create a index to a group of columns: (Class_Id, Book_Id, Status
)? If it's possible, how i can create a group of index in node.js/adonis?
解决方案
Adonis.js 用于knex.js
定义列类型和其他修饰符,您可以从docs中看到。
因此,作为基于您的架构的示例(仅用于演示):
'use strict'
const Schema = use('Schema')
class ClassBookHistoric extends Schema {
up () {
this.create('class_books', (table) => {
table.increments()
table.integer('class_id').notNullable().unique()
table.integer('book_unit_Id').notNullable().unique()
table.index(['class_id','book_unit_Id'], 'class_book_index');
table.timestamps()
})
}
down () {
this.drop('class_books')
}
}
module.exports = UsersSchema
推荐阅读
- python - 检查输入时出错:预期 input_1 有 4 个维度,但得到了形状为 (224, 224, 3) 的数组
- java - Adobe PDFBox 对加载和保存产生意外更改
- python - 为什么我无法在 Pycharm 中创建 jupyter notebook 并正确打开 ipynb?
- tensorflow - 具有解析梯度/质量矩阵的快速哈密顿蒙特卡罗采样器
- c# - 如何将两个连接的套接字组合成一个对话?
- python - 如何在网页上制作pandas操作的进度条
- javascript - 有条件的问题,因为结果总是 else if
- python - 即使在使用类别权重进行训练后,二元分类神经网络也只能预测未见数据的一个值
- java - Apache POI - 加密大于 2GB 的 XLSX 文件失败
- delphi - 在 Fastreport 编辑器中获取选定的组件?