GORM defined a gorm.Model struct, which includes fields ID, CreatedAt, UpdatedAt, DeletedAt // gorm. The strconv.ParseInt(s, base, bitSize) converts the given string to an integer in the given base (0, 2 to 36) and bit size (0 to 64). Problem I learned about this issue for the first time from this Hugo Discourse thread. strange because in normal languages like Python, int ('010') returns 10. If so, I don’t grasp the rationale behind why the strconv developers would make this strange decision. If convention doesn’t match your requirements, GORM allows you to configure them gorm.Model Go coder would use to do string int conversions. If you follow the conventions adopted by GORM, you’ll need to write very little configuration/code. However, we will get the following error instead: json. By default, GORM uses ID as primary key, pluralizes struct name to snake_cases as table name, snake_case as column name, and uses CreatedAt, UpdatedAt to track creating/updating time We would expect that our application will convert string 30 to integer 30 since its a valid integer. ![]() ![]() GORM prefers convention over configuration. Models are normal structs with basic Go types, pointers/alias of them or custom types implementing Scanner and Valuer interfaces
0 Comments
Leave a Reply. |