-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to infer field type for MySQL ENUM
field
#12
Comments
Hi @muniter, you are perhaps the first person to use the codegen utility with mysql. I'll update the regex patterns for the primitive types like char, decimal etc. however for composite types like enum or json you will need to define a type adapter and pass it to the generator. The tool we rely on to dump the schema (tbls) does not provide us with enough info to infer the enum completely. I had opened an issue with them sometime back. |
Hi, The generator, by default, only map types that clear, unambiguous and safe type in JS/TS, for the other types you will need to map the corresponding type using a field mapping in a similar way the default ones are defined. Example: const options: GeneratorOpts = {
schemaPath: './db/schema.yaml',
connectionSourcePath: './src/db.connection.ts',
outputDirPath: './src/db',
fieldMappings: [
{
columnType: /^numeric$/,
generatedField: { type: { dbType: { name: "stringDouble" } } }
}
],
export: {
tableInstances: true,
rowTypes: true,
extractedColumns: true
}
}
const generator = new Generator(options);
await generator.generate(); For more complex types you will need more complex rules, where there are not a generic type representation, like ENUM, JSON, etc. you will need to follow the ones described here |
Hello, thank you very much for the project, I hope the multiple issues wasn't taken as noise! Thanks for the quick response! @juanluispaz Noted, makes perfect sense. Will close the issues on the complex types. |
Trying to generate classes from a table with a ENUM field in MySQL throws an error.
The text was updated successfully, but these errors were encountered: