This repository has been 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
/
Copy pathAdd.go
72 lines (61 loc) · 1.83 KB
/
Add.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package jServCore
import (
"encoding/json"
toml "github.com/pelletier/go-toml/v2"
msg "github.com/vmihailenco/msgpack/v5"
yaml "gopkg.in/yaml.v3"
)
// Represents an addition of a whole document, or a value within an existing document, to the jServ database
type Add struct {
Collection string `json:"collection" msgpack:"collection" csv:"collection" toml:"collection" yaml:"collection"`
Documents []Document `json:"documents,omitempty" msgpack:"documents,omitempty" csv:"documents,omitempty" toml:"documents,omitempty" yaml:"documents,omitempty,flow"`
Values map[string]interface{} `json:"values,omitempty" msgpack:"values,omitempty" csv:"values,omitempty" toml:"values,omitempty" yaml:"values,omitempty,flow"`
}
// Converts the Query into JSON
func (a Add) ToJson() string {
js, _ := json.Marshal(a)
return string(js)
}
// Converts the Query into MsgPack
func (a Add) ToMsgPack() string {
m, _ := msg.Marshal(a)
return string(m)
}
// Converts the Query into TOML
func (a Add) ToToml() string {
t, _ := toml.Marshal(a)
return string(t)
}
// Converts the Query into YAML
func (a Add) ToYaml() string {
y, _ := yaml.Marshal(a)
return string(y)
}
// JSON Constructor
// Creates the Query object from JSON
func (a *Add) FromJson(s string) {
if err := json.Unmarshal([]byte(s), a); err != nil {
panic(err)
}
}
// MsgPack Constructor
// Creates the Query object from MsgPack
func (a *Add) FromMsgPack(s string) {
if err := msg.Unmarshal([]byte(s), a); err != nil {
panic(err)
}
}
// TOML Constructor
// Creates the Query object from JSON
func (a *Add) FromToml(s string) {
if err := toml.Unmarshal([]byte(s), a); err != nil {
panic(err)
}
}
// YAML Constructor
// Creates the Query object from YAML
func (a *Add) FromYaml(s string) {
if err := yaml.Unmarshal([]byte(s), a); err != nil {
panic(err)
}
}