0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

kysely-codegen の `singularize` が効かない?`model_caches` → `ModelCache` にするための正しい書き方と内部の仕組み

Last updated at Posted at 2025-08-08

TL;DR

  • kysely-codegensingularize は、正規化後のテーブル名に対して適用されます。
  • model_cachesmodelcaches に正規化されてからルールが当たるため、
    例外指定は "modelcaches": "model_cache" のように書く必要があります。
  • 広く当てたいなら正規表現 /caches$/ → cache、ピンポイントなら /^modelcaches$/ → model_cache

事象

PostgreSQL テーブル名は model_caches
kysely-codegencamelCase: true, --singularize(または設定ファイルの singularize)を使うと、
生成される型が Modelcache 抜け問題)になってしまう。

// 例:生成結果
export interface Modelcach {  // ← e が落ちている
  // ...
}

そこで singularize をこう書いたが効かない:

singularize: {
  "model_caches": "model_cache" // 効かない
}

解決策

// .kysely-codegenrc.ts / .json
export default {
  camelCase: true,
  singularize: {
    "modelcaches": "model_cache",      // ← これが刺さる
  },
};

原因

よくわからず、、
ソースコードを読んでみたがわからず。
ChatGPTに聞いてもそれらしい回答がなかった。
いろんなパターンを試していたらこれでマッチしたので、とりあえず解決した。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?