kristiandupont / kanel

Generate Typescript types from Postgres
https://kristiandupont.github.io/kanel/
MIT License
829 stars 57 forks source link

Implement table ignore feature #579

Open MatMercer opened 1 week ago

MatMercer commented 1 week ago

Overview

There's some tables (related to migrations) I want to ignore at my codebase. I didn't found a way to configure that.

I tried returning "null/undefined" at getMetadata but that breaks Kanel. Perhaps adding a simple if (undefined) at the next pipeline steps would be a quick way to implement ignores?

Expected Behavior

config.getMetadata = function(details, generateFor, config) {
  if (details.name === 'ignored_table') {
    return;
  }

  const metadata = defaultGetMetadata(details, generateFor, config);
  return metadata;
}

Should ignore 'ignored_table' type generation.

Current Behavior

TypeError: Cannot destructure property 'name' of 'config.getMetadata(...)' as it is undefined.
    at /redacted/node_modules/kanel/build/generators/makeCompositeGenerator.js:19:19
    at Array.map (<anonymous>)
    at  /redacted/node_modules/kanel/build/generators/makeCompositeGenerator.js:74:46
    at  /redacted/node_modules/kanel/build/processDatabase.js:56:22
    at Array.forEach (<anonymous>)
    at  /redacted/node_modules/kanel/build/processDatabase.js:55:20
    at Array.forEach (<anonymous>)
    at processDatabase ( /redacted/node_modules/kanel/build/processDatabase.js:54:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
error Command failed with exit code 1.
kristiandupont commented 1 week ago

I agree that this should be a way to ignore things as well, but what you should be able to do is apply the typeFilter configuration property. It takes a function that receives a PgType and returns a boolean. So if you want to ignore every table that starts with migration, you could do this:

{
  // ...
  typeFilter: (pgType) => !/^migration/.test(pgType.name)
}