Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle https://xorm.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
690 B

  1. // Copyright 2017 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package xorm
  5. // Exist returns true if the record exist otherwise return false
  6. func (session *Session) Exist(bean ...interface{}) (bool, error) {
  7. if session.isAutoClose {
  8. defer session.Close()
  9. }
  10. if session.statement.LastError != nil {
  11. return false, session.statement.LastError
  12. }
  13. sqlStr, args, err := session.statement.GenExistSQL(bean...)
  14. if err != nil {
  15. return false, err
  16. }
  17. rows, err := session.queryRows(sqlStr, args...)
  18. if err != nil {
  19. return false, err
  20. }
  21. defer rows.Close()
  22. return rows.Next(), nil
  23. }