当前位置: 首页>>代码示例>>Golang>>正文


Golang DB.RecordNotFound方法代码示例

本文整理汇总了Golang中github.com/jinzhu/gorm.DB.RecordNotFound方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.RecordNotFound方法的具体用法?Golang DB.RecordNotFound怎么用?Golang DB.RecordNotFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jinzhu/gorm.DB的用法示例。


在下文中一共展示了DB.RecordNotFound方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: isReadErr

func isReadErr(q *gorm.DB, row TUFFile) error {
	if q.RecordNotFound() {
		return ErrNotFound{}
	} else if q.Error != nil {
		return q.Error
	}
	return nil
}
开发者ID:jfrazelle,项目名称:notary,代码行数:8,代码来源:sqldb.go

示例2: returnRead

func returnRead(q *gorm.DB, row TUFFile) ([]byte, error) {
	if q.RecordNotFound() {
		return nil, ErrNotFound{}
	} else if q.Error != nil {
		return nil, q.Error
	}
	return row.Data, nil
}
开发者ID:NathanMcCauley,项目名称:notary,代码行数:8,代码来源:database.go

示例3: UpdateMany

// UpdateMany atomically updates many TUF records in a single transaction
func (db *SQLStorage) UpdateMany(gun string, updates []MetaUpdate) error {
	tx, rb, err := db.getTransaction()
	if err != nil {
		return err
	}
	var (
		query *gorm.DB
		added = make(map[uint]bool)
	)
	if err := func() error {
		for _, update := range updates {
			// This looks like the same logic as UpdateCurrent, but if we just
			// called, version ordering in the updates list must be enforced
			// (you cannot insert the version 2 before version 1).  And we do
			// not care about monotonic ordering in the updates.
			query = db.Where("gun = ? and role = ? and version >= ?",
				gun, update.Role, update.Version).First(&TUFFile{})

			if !query.RecordNotFound() {
				return ErrOldVersion{}
			}

			var row TUFFile
			checksum := sha256.Sum256(update.Data)
			hexChecksum := hex.EncodeToString(checksum[:])
			query = tx.Where(map[string]interface{}{
				"gun":     gun,
				"role":    update.Role,
				"version": update.Version,
			}).Attrs("data", update.Data).Attrs("sha256", hexChecksum).FirstOrCreate(&row)

			if query.Error != nil {
				return translateOldVersionError(query.Error)
			}
			// it's previously been added, which means it's a duplicate entry
			// in the same transaction
			if _, ok := added[row.ID]; ok {
				return ErrOldVersion{}
			}
			if update.Role == data.CanonicalTimestampRole {
				if err := db.writeChangefeed(tx, gun, update.Version, hexChecksum); err != nil {
					return err
				}
			}
			added[row.ID] = true
		}
		return nil
	}(); err != nil {
		return rb(err)
	}
	return tx.Commit().Error
}
开发者ID:jfrazelle,项目名称:notary,代码行数:53,代码来源:sqldb.go

示例4: UpdateMany

// UpdateMany atomically updates many TUF records in a single transaction
func (db *SQLStorage) UpdateMany(gun string, updates []MetaUpdate) error {
	tx := db.Begin()
	if tx.Error != nil {
		return tx.Error
	}

	rollback := func(err error) error {
		if rxErr := tx.Rollback().Error; rxErr != nil {
			logrus.Error("Failed on Tx rollback with error: ", rxErr.Error())
			return rxErr
		}
		return err
	}

	var (
		query *gorm.DB
		added = make(map[uint]bool)
	)
	for _, update := range updates {
		// This looks like the same logic as UpdateCurrent, but if we just
		// called, version ordering in the updates list must be enforced
		// (you cannot insert the version 2 before version 1).  And we do
		// not care about monotonic ordering in the updates.
		query = db.Where("gun = ? and role = ? and version >= ?",
			gun, update.Role, update.Version).First(&TUFFile{})

		if !query.RecordNotFound() {
			return rollback(&ErrOldVersion{})
		}

		var row TUFFile
		checksum := sha256.Sum256(update.Data)
		hexChecksum := hex.EncodeToString(checksum[:])
		query = tx.Where(map[string]interface{}{
			"gun":     gun,
			"role":    update.Role,
			"version": update.Version,
		}).Attrs("data", update.Data).Attrs("sha256", hexChecksum).FirstOrCreate(&row)

		if query.Error != nil {
			return rollback(translateOldVersionError(query.Error))
		}
		// it's previously been added, which means it's a duplicate entry
		// in the same transaction
		if _, ok := added[row.ID]; ok {
			return rollback(&ErrOldVersion{})
		}
		added[row.ID] = true
	}
	return tx.Commit().Error
}
开发者ID:mbentley,项目名称:notary,代码行数:52,代码来源:database.go

示例5: UpdateFullName

// UpdateFullName updates the cached full name of the tag
func (u *Tag) UpdateFullName(db *gorm.DB) (err error) {
	var (
		repo     = &Repo{}
		org      = &Org{}
		registry = &Registry{}
		handle   *gorm.DB
	)

	if handle = db.First(repo, u.RepoID); handle.RecordNotFound() {
		return fmt.Errorf("Failed to find parent repo")
	}

	if handle = db.First(org, repo.OrgID); handle.RecordNotFound() {
		return fmt.Errorf("Failed to find parent org")
	}

	if handle = db.First(registry, org.RegistryID); handle.RecordNotFound() {
		return fmt.Errorf("Failed to find parent registry")
	}

	u.FullName = fmt.Sprintf(
		"%s/%s/%s:%s",
		registry.PlainHost,
		org.Name,
		repo.Name,
		u.Name,
	)

	return nil
}
开发者ID:umschlag,项目名称:umschlag-api,代码行数:31,代码来源:tag.go


注:本文中的github.com/jinzhu/gorm.DB.RecordNotFound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。