Skip to content

Type

type Setting

Configuration file

const options = {
type: {
declared: "type",
format: "pascal",
prefix: "",
suffix: "",
replacements: [],
},
};
module.exports = options;

declared

  • none - No type declarations
  • type - Type declaration with type (default)

If only zodSchema is needed, use none.

format

Specifies the format of the Type name.

  • camel - camel case
  • pascal - pascal case (default)
  • snake - snake case
  • original - Use the original table name as it is

prefix

A string to be prepended to the type name. (Default is an empty string)

suffix

A string to be given after the type name. (Default is an empty string)

replacements

Performs type name substitution. Specify the string before and after the substitution in string[][] format. (Multiple specifications are allowed.) (Default is an empty array.)

Conversion Procedure

The tableName is converted by the following procedure.

  1. replacements
  2. format
  3. prefix
  4. suffix

example setting

const typeOption: TypeOption = {
declared: "type",
format: "snake",
prefix: "aaa",
suffix: "bbb",
replacements: [
["to", "task"],
["do", "Name"],
],
};
CREATE TABLE `todo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

If the above settings are used, the following conversions will occur.

export type aaatask_namebbb = z.infer<typeof todoSchema>;
  1. replacements convert to to task.
  2. replacements convert do to Name.
  3. format convert taskName to task_name.
  4. prefix and suffix generate aaatask_namebbb.