/** * Yats - yats * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Paolo Lulli * @copyright Paolo Lulli 2024 */ package db import ( "fmt" "time" ) func SaveEvent(idClient string, eventName string) { q := fmt.Sprintf("insert into event ( id_client, etime, name) values ('%s',toTimestamp(now()),'%s');", idClient, eventName) fmt.Printf("q=%s", q) Session.Query(q).Exec() } func SaveEventAt(idClient string, tstamp time.Time, eventName string) { timeAsBytes, _ := tstamp.UTC().MarshalText() q := fmt.Sprintf("insert into event ( id_client, etime, name) values ('%s','%s','%s');", idClient, string(timeAsBytes), eventName) Session.Query(q).Exec() } func CanReadSourceEvent(idClient string, sourceApp string) bool { m := map[string]interface{}{} q := fmt.Sprintf(" SELECT name,app,type from sources where id_client='%s' and app='%s' and type='event';", idClient, sourceApp) fmt.Println(q) iter := Session.Query(q).Iter() for iter.MapScan(m) { return true } return false }