3

I am starting a new loopback project with a postgresql backend. I know that I will need to embed JSON objects into records and plan to use the native JSON and JSONB column types available in postgres. I noticed in the online docs that there is no reference to these 2 column types (here: http://docs.strongloop.com/display/public/LB/PostgreSQL+connector).

Is it possible to create to use the column types? if so, how would I do that?

thanks, Mark

1 Answer 1

2

I'm curious and haven't tried this. Have you tried using an Object type with the json postgres data type?

"properties": {
  "dataProp": {
    "type": "Object",
    "required": false,
    "precision": null,
    "scale": null,
    "postgresql": {
      "columnName": "dataProp",
      "dataType": "json"
    }
  }
}

It seems to be supported here: https://github.com/strongloop/loopback-connector-postgresql/blob/79d4fa03bb0922301a22e5d2a85444eadd621ab0/lib/postgresql.js#L480

Sign up to request clarification or add additional context in comments.

4 Comments

I haven't tried it yet, but will. Seems that it might handle the JSON type but not the JSONB type.
it works both, thank you Bryan! One thing JSON/JSONB doesn't have length attribute it behaves as text on a PostgreSQL level, here is a discussion about stackoverflow.com/questions/12632871/…
Great! I'll update the answer to remove the length attribute so others aren't confused.
I still cannot find JSONB in github.com/strongloop/loopback-connector-postgresql/blob/master/…, I am not sure if this is supported in the moment, especially GIN indexes. There is nothing referring in source code to JSONB or GIN, so this advanced stuff is not yet supported as per my understanding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.