func (le *LogInfo) importEventSQL() error { tx, err := datastore.Dbh.Begin() if err != nil { return err } typeTable := fmt.Sprintf("%ss", le.ActorType) aiBuf := bytes.NewBuffer([]byte(le.ActorInfo)) aiRC := ioutil.NopCloser(aiBuf) doer := make(map[string]interface{}) dec := json.NewDecoder(aiRC) if err = dec.Decode(&doer); err != nil { tx.Rollback() return err } actorID, err := datastore.CheckForOne(tx, typeTable, doer["name"].(string)) if err != nil { actorID = -1 } err = le.actualWriteEventSQL(tx, actorID) if err != nil { tx.Rollback() return err } tx.Commit() return nil }
func checkForEnvironmentSQL(dbhandle datastore.Dbhandle, name string) (bool, error) { _, err := datastore.CheckForOne(dbhandle, "environments", name) if err == nil { return true, nil } if err != sql.ErrNoRows { return false, err } return false, nil }
func checkForDataBagSQL(dbhandle datastore.Dbhandle, name string) (bool, error) { _, err := datastore.CheckForOne(dbhandle, "data_bags", name) if err == nil { return true, nil } if err != sql.ErrNoRows { return false, err } return false, nil }
func (le *LogInfo) writeEventSQL() error { tx, err := datastore.Dbh.Begin() if err != nil { return err } typeTable := fmt.Sprintf("%ss", le.ActorType) actorID, err := datastore.CheckForOne(tx, typeTable, le.Actor.GetName()) if err != nil { tx.Rollback() return err } err = le.actualWriteEventSQL(tx, actorID) if err != nil { tx.Rollback() return err } tx.Commit() return nil }