diff --git a/orm/orm_queryset.go b/orm/orm_queryset.go index c1788f5b..b25d0542 100644 --- a/orm/orm_queryset.go +++ b/orm/orm_queryset.go @@ -114,6 +114,11 @@ func (o *querySet) Count() (int64, error) { return o.orm.alias.DbBaser.Count(o.orm.db, o, o.mi, o.cond, o.orm.alias.TZ) } +func (o *querySet) Exist() bool { + cnt, _ := o.orm.alias.DbBaser.Count(o.orm.db, o, o.mi, o.cond, o.orm.alias.TZ) + return cnt > 0 +} + func (o *querySet) Update(values Params) (int64, error) { return o.orm.alias.DbBaser.UpdateBatch(o.orm.db, o, o.mi, o.cond, values, o.orm.alias.TZ) } diff --git a/orm/types.go b/orm/types.go index 7ed5e3a6..bf18e2c2 100644 --- a/orm/types.go +++ b/orm/types.go @@ -50,6 +50,7 @@ type QuerySeter interface { OrderBy(...string) QuerySeter RelatedSel(...interface{}) QuerySeter Count() (int64, error) + Exist() bool Update(Params) (int64, error) Delete() (int64, error) PrepareInsert() (Inserter, error)