From 9be2869a10588c889d0a2fc60b610b343bd26525 Mon Sep 17 00:00:00 2001 From: WanYun Date: Thu, 17 Feb 2022 11:21:27 +0800 Subject: [PATCH] Chain closure dynamic condition implementation --- chainable_api.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/chainable_api.go b/chainable_api.go index 173479d3..80377aa5 100644 --- a/chainable_api.go +++ b/chainable_api.go @@ -150,6 +150,15 @@ func (db *DB) Where(query interface{}, args ...interface{}) (tx *DB) { return } +// When Condition established +func (db *DB) When(expr bool, query func(tx *DB)) (tx *DB) { + tx = db.getInstance() + if expr { + query(tx) + } + return +} + // Not add NOT conditions func (db *DB) Not(query interface{}, args ...interface{}) (tx *DB) { tx = db.getInstance()