danprinz
danprinz

Reputation: 235

Sequelize js postgresql user defined types

One of the best feature of Postgres (as I see it) is the user-defined data types which let me define my data model in more readable and maintainable way.

Does anyone knows/have some advice how to use it with SequelizeJs ORM?

I can use associations, but then it will not be user-defined types and it will drag me back to old school sub-tables, which I want to avoid.

Upvotes: 3

Views: 1327

Answers (1)

Jan Aagaard Meier
Jan Aagaard Meier

Reputation: 28798

You can provide any type you want to the sequelize model definition by passing a string:

sequelize.define('name', {
  attr: 'SOME TYPE'
});

Sequelize does not support creating the custom type though (CREATE TYPE), so you'll have to write a custom query for that, and execute it directly on the db or using sequelize.query

Upvotes: 3

Related Questions