Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 21, 2022 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/42af861dbd9b7a352c43bdb6924afde7 to your computer and use it in GitHub Desktop.
Save parzibyte/42af861dbd9b7a352c43bdb6924afde7 to your computer and use it in GitHub Desktop.
// https://parzibyte.me/blog
bd, err:= sql.Open("sqlite3", "mibd.bd") // Puede ser cualquier motor
if err != nil {
panic(err)// Manejar error como tú prefieras
}
defer bd.Close()
// Puede ser cualquier consulta
resultado, err := bd.Exec(`INSERT INTO personas(nombre)
VALUES
(?)`, "Luis")
if err != nil {
panic(err)// Manejar error como tú prefieras
}
ultimoId,err := resultado.LastInsertId()
if err != nil{
panic(err)// Manejar error como tú prefieras
}
// Aquí ya tenemos a ultimoId, haz lo que quieras con él
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment