Skip to content

Comments

Comment Setting

Setting items

The configuration of the comments takes the following object.

const options = {
comments: {
table: {
active: true,
format: "// [table:!name] : !text",
},
column: {
active: true,
format: "// !name : !text",
},
},
};
module.exports = options;

You can set whether or not to process comments about a table. Let us assume the following table.

CREATE TABLE todo (
id INT PRIMARY KEY AUTO_INCREMENT comment 'It will always be unique.',
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='Tables to manage tasks';
  • active - Sets whether comments are processed or not; if true, comments are processed.
  • format - Sets the format of the comment.

When active is true, the following comments are output.

// [table:todo_list] : Tables to manage tasks
export const todoListSchema = z.object({
// id : It will always be unique.
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 - Alternative characters for table and column names.
  • !text - Alternate text for comments.

The default format is as follows

  • table - // [table:!name] : !text
  • column - // !name : !text

For example, you want to comment only on columnst and table. Or if you want to comment with /* */ instead of //, set as follows.

const options = {
comments: {
table: {
active: true,
format: "/* !text */",
},
column: {
active: true,
format: "/* !text */",
},
},
};
module.exports = options;

With the above settings, the following output is obtained.

/* Tables to manage tasks */
export const todoListSchema = z.object({
/* It will always be unique. */
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(),
});