This repository was archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.go
More file actions
78 lines (67 loc) · 2.85 KB
/
Query.go
File metadata and controls
78 lines (67 loc) · 2.85 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package jServCore
import (
"encoding/json"
toml "github.com/pelletier/go-toml/v2"
msg "github.com/vmihailenco/msgpack/v5"
yaml "gopkg.in/yaml.v3"
)
// Represents a series of expressions that fetch documents meeting its conditions from the jServ database
type Query struct {
Collection []string `json:"collection,omitempty" msgpack:"collection,omitempty" csv:"collection,omitempty" toml:"collection,omitempty" yaml:"collection,omitempty,flow"`
Has []string `json:"has,omitempty" msgpack:"has,omitempty" csv:"has,omitempty" toml:"has,omitempty" yaml:"has,omitempty,flow"`
Equals map[string]interface{} `json:"equals,omitempty" msgpack:"equals,omitempty" csv:"equals,omitempty" toml:"equals,omitempty" yaml:"equals,omitempty,flow"`
NotEquals map[string]interface{} `json:"not-equals,omitempty" msgpack:"not-equals,omitempty" csv:"not-equals,omitempty" toml:"not-equals,omitempty" yaml:"not-equals,omitempty,flow"`
LessThan map[string]interface{} `json:"lt,omitempty" msgpack:"lt,omitempty" csv:"lt,omitempty" toml:"lt,omitempty" yaml:"lt,omitempty,flow"`
LessThanEqualTo map[string]interface{} `json:"lte,omitempty" msgpack:"lte,omitempty" csv:"lte,omitempty" toml:"lte,omitempty" yaml:"lt,omitempty,flowe"`
GreaterThanEqualTo map[string]interface{} `json:"gte,omitempty" msgpack:"gte,omitempty" csv:"gte,omitempty" toml:"gte,omitempty" yaml:"gte,omitempty,flow"`
GreaterThan map[string]interface{} `json:"gt,omitempty" msgpack:"gt,omitempty" csv:"gt,omitempty" toml:"gt,omitempty" yaml:"gt,omitempty,flow"`
Between map[string]interface{} `json:"between,omitempty" msgpack:"between,omitempty" csv:"between,omitempty" toml:"between,omitempty" yaml:"between,omitempty,flow"`
}
// Converts the Query into JSON
func (q Query) ToJson() string {
js, _ := json.Marshal(q)
return string(js)
}
// Converts the Query into MsgPack
func (q Query) ToMsgPack() string {
m, _ := msg.Marshal(q)
return string(m)
}
// Converts the Query into TOML
func (q Query) ToToml() string {
t, _ := toml.Marshal(q)
return string(t)
}
// Converts the Query into YAML
func (q Query) ToYaml() string {
y, _ := yaml.Marshal(q)
return string(y)
}
// JSON Constructor
// Creates the Query object from JSON
func (q *Query) FromJson(s string) {
if err := json.Unmarshal([]byte(s), q); err != nil {
panic(err)
}
}
// MsgPack Constructor
// Creates the Query object from MsgPack
func (q *Query) FromMsgPack(s string) {
if err := msg.Unmarshal([]byte(s), q); err != nil {
panic(err)
}
}
// TOML Constructor
// Creates the Query object from TOML
func (q *Query) FromToml(s string) {
if err := toml.Unmarshal([]byte(s), q); err != nil {
panic(err)
}
}
// YAML Constructor
// Creates the Query object from YAML
func (q *Query) FromYaml(s string) {
if err := yaml.Unmarshal([]byte(s), q); err != nil {
panic(err)
}
}