Postgresql 环回索引-如何在模型定义中指定不同的索引类型?

Postgresql 环回索引-如何在模型定义中指定不同的索引类型?,postgresql,loopbackjs,Postgresql,Loopbackjs,在Loopback(v3)中,在model.json文件中定义索引时,如何指定不同类型的索引(如BRIN)?另外,如何指定索引条件(例如,如果要创建部分索引)?如果相关的话,我正在为数据库使用postgres。您可以通过type字段配置索引类型 { "name": "MyModel", "properties": { // ... }, "indexes": { "myindex": { "columns": "name, email",

在Loopback(v3)中,在model.json文件中定义索引时,如何指定不同类型的索引(如BRIN)?另外,如何指定索引条件(例如,如果要创建部分索引)?如果相关的话,我正在为数据库使用postgres。

您可以通过
type
字段配置索引类型

{
  "name": "MyModel",
  "properties": {
    // ...
  },
  "indexes": {
    "myindex": {
      "columns": "name, email",
      "type": "BRIN",
      // ...
    }
  }
} 

恐怕循环还不支持索引条件(部分索引)。欢迎在中打开新版本。

在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也是如此)

构建完成后,将创建包含3列的索引名idx_tablename

@model({ 
name: 'tablename', 
settings: {
 indexes: {
  idx_tablename: {
    columnA : '',
    columnB : '',
    columnC: ''
    }
   }
 } 
})