环回索引 - 如何在模型定义中指定不同的索引类型?
Loopback indexes - how to specify different index types in model definition?
在 Loopback (v3) 中,在我的 model.json 文件中定义索引时,如何指定不同类型的索引(例如 BRIN)?另外,如何指定索引条件(例如是否要创建部分索引)?如果相关的话,我正在为数据库使用 postgres。
您可以通过type
字段配置索引类型。
{
"name": "MyModel",
"properties": {
// ...
},
"indexes": {
"myindex": {
"columns": "name, email",
"type": "BRIN",
// ...
}
}
}
恐怕LoopBack还不支持索引条件(部分索引)。欢迎在 https://github.com/strongloop/loopback-connector-postgresql/issues.
中打开一个新问题
在 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}
}
}
}
我正在尝试添加 Lb4。它在那里非常简单(我希望 lb3 也应该相同)
@model({
name: 'tablename',
settings: {
indexes: {
idx_tablename: {
columnA : '',
columnB : '',
columnC: ''
}
}
}
})
构建完成后,将创建包含 3 列的索引名称 idx_tablename
在 Loopback (v3) 中,在我的 model.json 文件中定义索引时,如何指定不同类型的索引(例如 BRIN)?另外,如何指定索引条件(例如是否要创建部分索引)?如果相关的话,我正在为数据库使用 postgres。
您可以通过type
字段配置索引类型。
{
"name": "MyModel",
"properties": {
// ...
},
"indexes": {
"myindex": {
"columns": "name, email",
"type": "BRIN",
// ...
}
}
}
恐怕LoopBack还不支持索引条件(部分索引)。欢迎在 https://github.com/strongloop/loopback-connector-postgresql/issues.
中打开一个新问题在 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}
}
}
}
我正在尝试添加 Lb4。它在那里非常简单(我希望 lb3 也应该相同)
@model({
name: 'tablename',
settings: {
indexes: {
idx_tablename: {
columnA : '',
columnB : '',
columnC: ''
}
}
}
})
构建完成后,将创建包含 3 列的索引名称 idx_tablename