sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Create a model based on conditions OR crash on unhandled column type

Open pelord opened this issue 3 years ago • 0 comments

Issue

It's a question/feature request => To understand how to create model based on conditions.

It's an issue, based on the fact that an unhandled collumn type crash on model creation, ex: tsvector on sqlite

Versions

  • sequelize: 6.21.3
  • sequelize-typescript: 2.1.3
  • typescript: 4.7.4

Issue type

  • [x] bug report
  • [x] feature request

Actual behavior

I try to create a model (https://github.com/sequelize/sequelize-typescript#model-definition) by model definition. Based on a config for my dialect (postgres | sqlite), for the same model, I want to create differents column, and hooks

In this specific case, I create a tsvector on a postgres database.. but if i create a sqlite, the model creation crash.

Expected behavior

Is it possible to set a condition to create a column/hook based on a specific dialect..

OK.

Do not crash on unhandled column types...

image

if (dialect === 'postgres') {
     @Column({ 
     type: DataType.TSVECTOR }) // only for postgresql
     searchableColumn: { [key: string]: any };
} else { 
     // do nothing
}

Steps to reproduce

... Create a model based on conditions.

Related code

....currently in dev.

pelord avatar Oct 12 '22 15:10 pelord