Comments
コメント設定
設定項目
commentsの設定項目は、以下のようなオブジェクトを取ります。
const options = { comments: { table: { active: true, format: "// [table:!name] : !text", }, column: { active: true, format: "// !name : !text", }, },};module.exports = options;
テーブルについてのコメントを処理するかどうかを設定します。 下記のようなテーブルを想定してみます。
CREATE TABLE todo ( id INT PRIMARY KEY AUTO_INCREMENT comment '必ず一意になります', task VARCHAR(255) NOT NULL, description TEXT, due_date DATE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) COMMENT='タスクの一覧を管理するテーブル';
- active - コメントを処理するかどうかを設定します。trueの場合、コメントを処理します。
- format - コメントのフォーマットを設定します。
activeがtrueのときは、下記のようなコメントが出力されます。
// [table:todo_list] : タスクの一覧を管理するテーブルexport const todoListSchema = z.object({ // id : 必ず一意になります id: z.number(), task: z.string(), description: z.string().nullish(), due_date: z.date().nullish(), created_at: z.date().nullish(), updated_at: z.date().nullish(),});export type TodoList = z.infer<typeof todoListSchema>;
format
- !name - テーブル名、カラム名の代替文字です。
- !text - コメントのテキストの代替文字です。
デフォルトのformatは下記の通りです。
- table -
// [table:!name] : !text
- column -
// !name : !text
たとえばcolumnstとtableでコメントだけしたい。あるいは//
ではなく/* */
でコメントしたい場合は、下記のように設定します。
/** @type {import("./src/options/options").MysqlToZodOption} */const options = { comments: { table: { active: true, format: "/* !text */", }, column: { active: true, format: "/* !text */", }, },};module.exports = options;
以上の設定で、下記のような出力が得られます。
/* タスクの一覧を管理するテーブル */export const todoListSchema = z.object({ /* 必ず一意になります */ id: z.number(), task: z.string(), description: z.string().nullish(), due_date: z.date().nullish(), created_at: z.date().nullish(), updated_at: z.date().nullish(),});