These are chat archives for jinzhu/gorm

Jun 2017
Jun 01 2017 02:34
@kuma-guy not necessary, you could use set its data type with tag
Bertram Truong
Jun 01 2017 03:32
Hi all, does anyone know how I would go about mocking errors in my app that uses gorm?
For example, I have code like:
func (r userRepository) FindById(id int) (*models.User, error) {
    var user models.User

    if err := r.db.First(&user, id).Error; err != nil {
        if err == gorm.ErrRecordNotFound {
            return nil, ErrUserNotFound
        return nil, err
    return &user, nil
Specifically, I want to test the return nil, err line
Shingo Kumagai
Jun 01 2017 03:37



Time      string `sql:"type:time"`

like this?

Jun 01 2017 09:22
@kuma-guy yes
@bt Pass a db to userRepository that will generate incorrect SQL?
Jun 01 2017 21:50
@jinzhu hey there!
When we do a query with a placeholder value like the following
db.Where("name = ?", "jinzhu").First(&user)
does gorm take into account the different database drivers and escape it properly for even something like postgres? (Which has parameters like this $1 , $2 i believe)