func (storageCassandra *StorageCassandra) saveTest(name string, updatedTime time.Time) error { session, err := cassandra.CassandraClient.GetSession() if err != nil { log.Error("Get session error %s", err) return err } if err := session.Query("INSERT INTO test (name, updated_time) VALUES (?, ?)", name, gocql.UUIDFromTime(updatedTime), ).Exec(); err != nil { log.Error("Save Test name %s updatedTime %s error: %s", name, updatedTime, err) return err } return nil }
func (r *CQLOinkRepo) Create(o model.Oink) (model.Oink, error) { r.lock.RLock() defer r.lock.RUnlock() if !r.initialized { return model.Oink{}, errors.New("Uninitialized repo") } o.ID = uuid.NewV4().String() o.CreationTime = time.Now() err := r.session.Query( "INSERT INTO oinker.oinks (kind, id, content, created_at, handle) "+ "VALUES (?, ?, ?, ?, ?)", "oink", o.ID, o.Content, gocql.UUIDFromTime(o.CreationTime), o.Handle, ).Exec() if err != nil { return model.Oink{}, fmt.Errorf("Inserting oink (%+v): %s", o, err) } return o, nil }
func (r *CQLOinkRepo) Create(o Oink) (Oink, error) { o.ID = uuid.NewV4().String() o.CreationTime = time.Now() session, err := r.cluster.CreateSession() if err != nil { return Oink{}, fmt.Errorf("Creating CQL Session: %s", err) } defer session.Close() err = session.Query( "INSERT INTO oinks (kind, id, content, created_at, handle) "+ "VALUES (?, ?, ?, ?, ?)", "oink", o.ID, o.Content, gocql.UUIDFromTime(o.CreationTime), o.Handle, ).Exec() if err != nil { return Oink{}, fmt.Errorf("inserting oink (%+v): %s", o, err) } return o, nil }
func beaconsFromIncomingBeacons(incomingBeacons *[]IncomingBeacon, tr trackRequest) (beacons []Beacon, aliases []AliasRequest) { for _, ib := range *incomingBeacons { p := ib.Properties.(map[string]interface{}) delete(p, "token") // special handling for the $create_alias event if ib.Event == "$create_alias" { a := AliasRequest{DistinctID: p["distinct_id"].(string), AliasID: p["alias"].(string)} aliases = append(aliases, a) continue } var t time.Time if f, ok := p["time"]; ok { t = time.Unix(int64(f.(float64)), 0).UTC() if tr.i != true && t.Before(time.Now().Add(time.Duration(-5)*time.Second)) { t = time.Now().UTC() } delete(p, "time") } else { t = time.Now() } rid := gocql.UUIDFromTime(t) var ip string if s, ok := p["ip"]; ok { ip = s.(string) delete(p, "ip") } else { ip = tr.ip } var did string if d, ok := p["distinct_id"]; ok && d != nil { did = d.(string) } else { // otherwise use the requestid did = rid.String() } delete(p, "distinct_id") var sid string if d, ok := p["session_id"]; ok && d != nil { sid = d.(string) } else { // otherwise use the requestid sid = rid.String() } delete(p, "session_id") properties := make(map[string]interface{}) meta := make(map[string]string) ignoreList := map[string]bool{ "mp_lib": true, "$lib_version": true, } for k, v := range p { if listed, found := ignoreList[k]; !found { properties[k] = v } else if listed { meta[k] = v.(string) } } b := Beacon{Event: ib.Event, RequestID: rid, DistinctID: did, SessionID: sid, Time: t, Properties: properties, IP: ip, Meta: meta} beacons = append(beacons, b) } return }
func (storageCassandra *StorageCassandra) saveImageRecord(imageRecord *ImageRecord) error { session, err := cassandra.CassandraClient.GetSession() if err != nil { log.Error("Get session error %s", err) return err } if err := session.Query("INSERT INTO image_record (image_information, version, path, version_info, environment, description, created_time) VALUES (?, ?, ?, ?, ?, ?, ?)", imageRecord.ImageInformation, imageRecord.Version, imageRecord.Path, imageRecord.VersionInfo, imageRecord.Environment, imageRecord.Description, gocql.UUIDFromTime(imageRecord.CreatedTime)).Exec(); err != nil { log.Error("Save ImageRecord %s error: %s", imageRecord, err) return err } return nil }