github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/patcher/utils.go (about)

     1  package main
     2  
     3  import "database/sql"
     4  import "github.com/Azareal/Gosora/query_gen"
     5  
     6  func execStmt(stmt *sql.Stmt, err error) error {
     7  	if err != nil {
     8  		return err
     9  	}
    10  	_, err = stmt.Exec()
    11  	return err
    12  }
    13  
    14  /*func eachUserQuick(handle func(int)) error {
    15  	stmt, err := qgen.Builder.Select("users").Orderby("uid desc").Limit(1).Prepare()
    16  	if err != nil {
    17  		return err
    18  	}
    19  
    20  	var topID int
    21  	err := stmt.QueryRow(topID)
    22  	if err != nil {
    23  		return err
    24  	}
    25  
    26  	for i := 1; i <= topID; i++ {
    27  		err = handle(i)
    28  		if err != nil {
    29  			return err
    30  		}
    31  	}
    32  }*/
    33  
    34  func eachUser(handle func(int) error) error {
    35  	err := qgen.NewAcc().Select("users").Cols("uid").Each(func(rows *sql.Rows) error {
    36  		var uid int
    37  		err := rows.Scan(&uid)
    38  		if err != nil {
    39  			return err
    40  		}
    41  		return handle(uid)
    42  	})
    43  	return err
    44  }