[GORM FAQs] GORM FAQs
Gorm FAQs
Gorm is the fantastic ORM library for Golang aims to be developer friendly.
unsupported data type: &[]
Use pq.StringArray
instead of []string
to tore string array.
Error:
1 | type User struct { |
Good:
1 | type User struct { |
cannot convert x to Text
1 | x may be 0, 1, 2... |
This is caused by the combination of pgx internally using prepared statements and PostgreSQL not being able to determine the type of the placeholders. The simplest solution is to include type information with your placeholders. e.g. $1::int.
Alternatively, you could configure pgx to use the simple protocol instead of prepared statements.
1 | // https://github.com/go-gorm/postgres |
invalid value, should be pointer to struct or slice
Error:
1 | var object *Object |
Good:
1 | var object Object |
panic: reflect: reflect.Value.Set using unaddressable value
1 |
|
References
[2] GORM - The fantastic ORM library for Golang, aims to be developer friendly. - https://gorm.io/
[3] GitHub - jackc/pgx: PostgreSQL driver and toolkit for Go - https://github.com/jackc/pgx
[4] pgx · pkg.go.dev - https://pkg.go.dev/github.com/jackc/pgx/v4