示例#1
0
func (self *PostgresStorage) Insert(ev *histri.Event) error {
	newId := 0
	jsonData, err := json.Marshal(ev.Data)
	if err != nil {
		return err
	}
	row := self.conn.QueryRow(`select insert_event($1, $2, $3, $4)`,
		ev.TimeUtc,
		ev.EventType,
		ev.ExtRef,
		string(jsonData))
	if err := row.Scan(&newId); err != nil {
		return err
	}
	//fmt.Println(newId)
	ev.Id = strconv.Itoa(newId)
	//fmt.Println(ev.Id)
	return nil
}
示例#2
0
func rowToEvent(row rowScanner, event *histri.Event) error {
	var (
		intId     int64
		dataBytes []byte
	)
	err := row.Scan(&intId,
		&event.TimeUtc,
		&event.EventType,
		&event.ExtRef,
		&dataBytes)
	if err != nil {
		return err
	}
	if err = json.Unmarshal(dataBytes, &event.Data); err != nil {
		return err
	}
	event.Id = strconv.Itoa(int(intId))
	return nil
}
示例#3
0
func (self *InMemStorage) Insert(event *histri.Event) error {
	event.Id = string(len(self.events))
	self.events = append(self.events, *event)
	return nil
}