本文整理汇总了Golang中zenithar/org/go/common/dao/api.NewDatabaseError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDatabaseError函数的具体用法?Golang NewDatabaseError怎么用?Golang NewDatabaseError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDatabaseError函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: FindByAndCount
// FindByAndCount returns the number of elements that match the filter
func (d *Default) FindByAndCount(key string, value interface{}) (int, error) {
filterMap := bson.M{
key: value,
}
session := d.session.Clone()
defer session.Close()
n, err := session.DB(d.GetDBName()).C(d.GetTableName()).Find(filterMap).Count()
if err != nil {
if err == mgo.ErrNotFound {
return 0, api.ErrNoResult
}
return 0, api.NewDatabaseError(d, err, "")
}
return n, nil
}
开发者ID:Zenithar,项目名称:golang-common,代码行数:18,代码来源:default_crud.go
注:本文中的zenithar/org/go/common/dao/api.NewDatabaseError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论