From 5d55ca19be9d71dc83a4b470dd222c94b2d3b579 Mon Sep 17 00:00:00 2001 From: slene Date: Sat, 12 Oct 2013 06:57:14 +0800 Subject: [PATCH] orm add Exist func --- orm/orm_queryset.go | 5 +++++ orm/types.go | 1 + 2 files changed, 6 insertions(+) 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)