-
Notifications
You must be signed in to change notification settings - Fork 1
/
query.go
52 lines (43 loc) · 1.19 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package owl
import (
"fmt"
"time"
"github.com/fwtpe/owl-backend/common/db"
"github.com/fwtpe/owl-backend/common/json"
"github.com/satori/go.uuid"
)
// Represents the query object
type Query struct {
Uuid db.DbUuid `db:"qr_uuid"`
NamedId string `db:"qr_named_id"`
Content []byte `db:"qr_content"`
Md5Content db.Bytes16 `db:"qr_md5_content"`
CreationTime time.Time `db:"qr_time_creation"`
AccessTime time.Time `db:"qr_time_access"`
}
// Generate UUID v4 for this object
func (q *Query) NewUuid() {
q.Uuid = db.DbUuid(uuid.NewV4())
}
func (q *Query) String() string {
return fmt.Sprintf(
"Named Id: [%s]. Uuid: [%s]. Md5 Content: [%x]",
q.NamedId, uuid.UUID(q.Uuid).String(),
q.Md5Content,
)
}
func (q *Query) ToJson() map[string]interface{} {
return map[string]interface{}{
"uuid": json.Uuid(q.Uuid),
"feature_name": q.NamedId,
"content": json.VarBytes(q.Content),
"md5_content": json.Bytes16(q.Md5Content),
"creation_time": json.JsonTime(q.CreationTime),
"access_time": json.JsonTime(q.AccessTime),
}
}
func (q *Query) ToJsonOfQueryId() map[string]interface{} {
return map[string]interface{}{
"query_id": uuid.UUID(q.Uuid).String(),
}
}