Skip to content

Commit 0553ae9

Browse files
committed
Add Any function
1 parent 8d80aad commit 0553ae9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sql_util.go

+11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ func GetFieldByJson(modelType reflect.Type, jsonName string) (int, string, strin
7676
}
7777
return -1, jsonName, jsonName
7878
}
79+
func Any(ctx context.Context, db Executor, sql string, values ...interface{}) (bool, error) {
80+
rows, err := db.QueryContext(ctx, sql, values...)
81+
if err != nil {
82+
return false, err
83+
}
84+
defer rows.Close()
85+
for rows.Next() {
86+
return true, nil
87+
}
88+
return false, nil
89+
}
7990
func Count(ctx context.Context, db Executor, sql string, values ...interface{}) (int64, error) {
8091
var total int64
8192
row := db.QueryRowContext(ctx, sql, values...)

0 commit comments

Comments
 (0)