在环回 (v3( 中,在我的 model.json 文件中定义索引时,如何指定不同类型的索引(例如 BRIN(?另外,如何指定索引条件(例如,如果要创建部分索引(?如果相关的话,我正在为数据库使用 postgres。
您可以通过type
字段配置索引类型。
{
"name": "MyModel",
"properties": {
// ...
},
"indexes": {
"myindex": {
"columns": "name, email",
"type": "BRIN",
// ...
}
}
}
恐怕环回还不支持索引条件(部分索引(。请随时在 https://github.com/strongloop/loopback-connector-postgresql/issues 中打开一个新问题。
我试图添加 Lb4。那里非常简单(我希望 lb3 也应该相同(
@model({
name: 'tablename',
settings: {
indexes: {
idx_tablename: {
columnA : '',
columnB : '',
columnC: ''
}
}
}
})
构建完成后,将创建包含 3 列的索引名称idx_tablename
在 PostgreSQL 和 Loopback 3 中,你可以像这样为多列指定一个索引。
以下环回 JSON 代码在 Postgres 中创建索引,其中字段message
和type
一起是唯一的。
{
"name": "notification",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"message": {
"type": "string",
"required": true
},
"type": {
"type": "string",
"required": true
},
"seen": {
"type": "boolean",
"required": true,
"default": false
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {},
"indexes": {
"message_type_index": {
"keys": "message, type",
"options": {"unique": true}
}
}
}