Standard library / database/sql

sql.Result

Describes the result of Exec: affected rows and possibly a generated ID. Either method may return an error. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
type Result interface {  LastInsertId() (int64, error)
  RowsAffected() (int64, error)}

Working Example

Example Snippetgo
package main
import (  "database/sql"  "database/sql/driver"  "fmt")
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}func main() { var r sql.Result = driver.RowsAffected(2); fmt.Println(must(r.RowsAffected())) }
Go Reference