Search code examples
postgresqlloopbackjs

Loopback indexes - how to specify different index types in model definition?


In Loopback (v3), when defining indexes in my model.json files, how do I specify different types of indexes (such as a BRIN)? Also, how do I specify index conditions (such as if I want to create a partial index)? I'm using postgres for the database, if that's relevant.


Solution

  • You can configure the index type via type field.

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

    I am afraid LoopBack does not support index conditions (partial indexes) yet. Feel free to open a new issue in https://github.com/strongloop/loopback-connector-postgresql/issues.