Skip to content

Instantly share code, notes, and snippets.

@zhangli2946 zhangli2946/cmd.go
Last active Jan 14, 2020

Embed
What would you like to do?
package cmd
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"log"
)
var (
backend *sql.DB
dsn string
)
type Closer interface {
Close() error
}
func Init() Closer {
var err error
backend, err = sql.Open("mysql", dsn)
if err != nil {
panic(fmt.Errorf("open error : %s", err))
}
return backend
}
func Upsert(values ...interface{}) (err error) {
var result sql.Result
result, err = backend.Exec(
"INSERT IGNORE INTO `node` VALUE (?,?,?,?)",
values...
)
if err != nil {
panic(fmt.Errorf("sql exec error : %s", err))
return
}
log.Println(result.RowsAffected())
log.Println(result.LastInsertId())
return nil
}
// TODO delete node_hash = spec
// TODO
type Node struct {
NodeHash [64]byte
AncestorHash [64]byte
AncestorName string
Depth int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.