Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseMySQLError ¶
ParseMySQLError parses a MySQL error and returns a more specific error based on the error code. If the error is nil, it returns nil. If the error is a duplicate entry error (ERROR 1062), it returns the corresponding error for the entity. If the error is a foreign key constraint error (ERROR 1451), it returns the corresponding error for the entity or table. If the error is a foreign key constraint error indicating that the entity does not exist (ERROR 1452), it returns the corresponding error for the entity or table. If the error does not match any specific error code, it returns the fallback error.
Types ¶
type Entity ¶
type Entity string
func ExtractTableNameFromError1451 ¶
func ExtractTableNameFromError1451(err mysql.MySQLError) (Entity, error)
ExtractTableNameFromError1451 extracts the table name from a MySQL error with code 1451. It uses a regular expression to find the table name in the error message. If a match is found, it returns the table name. Otherwise, it returns an error.
Example error message: "Cannot delete or update a parent row: a foreign key constraint fails (`espresso-api`.`beans`, CONSTRAINT `beans_ibfk_1` FOREIGN KEY (`roaster_id`) REFERENCES `roasters` (`id`))"
func ExtractTableNameFromError1452 ¶
func ExtractTableNameFromError1452(err mysql.MySQLError) (Entity, error)
ExtractTableNameFromError1452 extracts the table name from a MySQL error with code 1452. It uses a regular expression to find the table name in the error message. If a match is found, it returns the table name. Otherwise, it returns an error.
Example error message: "Cannot add or update a child row: a foreign key constraint fails (`espresso-api`.`shots`, CONSTRAINT `shots_ibfk_1` FOREIGN KEY (`sheet_id`) REFERENCES `sheets` (`id`))"