當前位置: 首頁>>代碼示例>>Golang>>正文


Golang api.NewDatabaseError函數代碼示例

本文整理匯總了Golang中zenithar/org/go/common/dao/api.NewDatabaseError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewDatabaseError函數的具體用法?Golang NewDatabaseError怎麽用?Golang NewDatabaseError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewDatabaseError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: WhereAndFetchOne

// WhereAndFetchOne returns one document that match the filter
func (d *Default) WhereAndFetchOne(filter interface{}, result interface{}) error {
	cursor, err := r.Table(d.table).Filter(filter).Run(d.session)
	if err != nil {
		return api.NewDatabaseError(d, err, "")
	}

	if err := cursor.One(result); err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:16,代碼來源:default_crud.go

示例2: WhereAndFetchLimit

// WhereAndFetchLimit returns paginated list of document
func (d *Default) WhereAndFetchLimit(filter interface{}, paginator *api.Pagination, results interface{}) error {
	cursor, err := r.Table(d.table).Filter(filter).Run(d.session)
	if err != nil {
		return api.NewDatabaseError(d, err, "")
	}

	if err := cursor.All(results); err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:16,代碼來源:default_crud.go

示例3: Find

// Find a document match given id
func (d *Default) Find(id interface{}, value interface{}) error {
	cursor, err := r.Table(d.table).Get(id).Run(d.session)
	if err != nil {
		return api.NewDatabaseError(d, err, "")
	}

	if err := cursor.One(value); err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:16,代碼來源:default_crud.go

示例4: FindOneBy

// FindOneBy a couple (k = v) in the database
func (d *Default) FindOneBy(key string, value interface{}, result interface{}) error {

	cursor, err := r.Table(d.table).GetAllByIndex(key, value).Run(d.session)
	if err != nil {
		return api.NewDatabaseError(d, err, "")
	}

	if err := cursor.One(result); err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:17,代碼來源:default_crud.go

示例5: FindBy

// FindBy all couples (k = v) in the database
func (d *Default) FindBy(key string, value interface{}, results interface{}) error {
	cursor, err := r.Table(d.table).Filter(func(row r.Term) r.Term {
		return row.Field(key).Eq(value)
	}).Run(d.session)
	if err != nil {
		return api.NewDatabaseError(d, err, "")
	}

	if err := cursor.All(results); err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:18,代碼來源:default_crud.go

示例6: Search

// Search all entities in the database
func (d *Default) Search(results interface{}, filter interface{}, sortParams *api.SortParameters, pagination *api.Pagination) error {
	term := r.Table(d.table)

	// Filter
	if filter != nil {
		term = term.Filter(filter)
	}

	// Get total
	if pagination != nil {
		total, err := d.WhereCount(filter)
		if err != nil {
			return api.NewDatabaseError(d, err, "")
		}
		pagination.SetTotal(uint(total))
	}

	// Sort
	if sortParams != nil {
		term = term.OrderBy(ConvertSortParameters(*sortParams)...)
	}

	// Slice result
	if pagination != nil {
		term = term.Slice(pagination.Offset(), pagination.Offset()+pagination.PerPage)
	}

	// Run the query
	cursor, err := term.Run(d.session)
	if err != nil {
		return api.NewDatabaseError(d, err, "")
	}

	// Fetch cursor
	err = cursor.All(results)
	if err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return err
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:45,代碼來源:default_crud.go

示例7: InsertOrUpdate

// InsertOrUpdate a document occording to ID presence in database
func (d *Default) InsertOrUpdate(id interface{}, data interface{}) error {
	_, err := r.Table(d.table).Insert(data, r.InsertOpts{Conflict: "update"}).RunWrite(d.session)
	if err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:12,代碼來源:default_crud.go

示例8: Insert

// Insert inserts a document into the database
func (d *Default) Insert(data interface{}) error {
	_, err := r.Table(d.table).Insert(data).RunWrite(d.session)
	if err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:12,代碼來源:default_crud.go

示例9: Delete

// Delete a document from the database
func (d *Default) Delete(id interface{}) error {
	_, err := r.Table(d.table).Get(id).Delete().RunWrite(d.session)
	if err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:12,代碼來源:default_crud.go

示例10: Update

// Update a document that match the selector
func (d *Default) Update(selector interface{}, data interface{}) error {
	_, err := r.Table(d.table).Filter(selector).Update(data).RunWrite(d.session)
	if err != nil {
		if err == r.ErrEmptyResult {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:12,代碼來源:default_crud.go

示例11: UpdateID

// UpdateID performs an update on an existing resource with ID that equals the id argument
func (d *Default) UpdateID(id interface{}, data interface{}) error {
	session := d.session.Clone()
	defer session.Close()

	err := session.DB(d.GetDBName()).C(d.GetTableName()).UpdateId(id.(string), data)
	if err != nil {
		if err == mgo.ErrNotFound {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:15,代碼來源:default_crud.go

示例12: WhereCount

// WhereCount allows counting with multiple fields
func (d *Default) WhereCount(filter interface{}) (int, error) {
	session := d.session.Clone()
	defer session.Close()

	count, err := session.DB(d.GetDBName()).C(d.GetTableName()).Find(filter).Count()
	if err != nil {
		if err == mgo.ErrNotFound {
			return 0, api.ErrNoResult
		}
		return 0, api.NewDatabaseError(d, err, "")
	}

	return count, nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:15,代碼來源:default_crud.go

示例13: FindFetchOne

// FindFetchOne searches for a resource and then unmarshals the first row into value
func (d *Default) FindFetchOne(id string, value interface{}) error {
	session := d.session.Clone()
	defer session.Close()

	err := session.DB(d.GetDBName()).C(d.GetTableName()).Find(bson.M{"_id": id}).One(value)
	if err != nil {
		if err == mgo.ErrNotFound {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:15,代碼來源:default_crud.go

示例14: DeleteAll

// DeleteAll deletes resources that match the passed filter
func (d *Default) DeleteAll(pred interface{}) error {
	session := d.session.Clone()
	defer session.Close()

	_, err := session.DB(d.GetDBName()).C(d.GetTableName()).RemoveAll(pred)
	if err != nil {
		if err == mgo.ErrNotFound {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:15,代碼來源:default_crud.go

示例15: FindByAndFetch

// FindByAndFetch retrieves a value by key and then fills results with the result.
func (d *Default) FindByAndFetch(key string, value interface{}, results interface{}) error {
	filterMap := bson.M{
		key: value,
	}
	session := d.session.Clone()
	defer session.Close()

	err := session.DB(d.GetDBName()).C(d.GetTableName()).Find(filterMap).All(results)
	if err != nil {
		if err == mgo.ErrNotFound {
			return api.ErrNoResult
		}
		return api.NewDatabaseError(d, err, "")
	}

	return nil
}
開發者ID:Zenithar,項目名稱:golang-common,代碼行數:18,代碼來源:default_crud.go


注:本文中的zenithar/org/go/common/dao/api.NewDatabaseError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。