github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/core/rawdata/sqljson.go (about) 1 package rawdata 2 3 import ( 4 "database/sql/driver" 5 "encoding/json" 6 "errors" 7 8 _ "github.com/lib/pq" // SQL driver registration 9 ) 10 11 func loadJSON(out interface{}, src interface{}) error { 12 if src == nil { 13 return nil //zero value out 14 } 15 bs, ok := src.([]byte) 16 if !ok { 17 return errors.New("not a []byte") 18 } 19 return json.Unmarshal(bs, out) 20 } 21 22 func dumpJSON(s interface{}) (driver.Value, error) { 23 b, err := json.Marshal(s) 24 if err != nil { 25 return nil, err 26 } 27 return driver.Value(b), nil 28 } 29 30 func (s *Exemplaires) Scan(src interface{}) error { 31 return loadJSON(s, src) 32 } 33 34 func (s Exemplaires) Value() (driver.Value, error) { 35 return dumpJSON(s) 36 } 37 38 func (s *OptionsCamp) Scan(src interface{}) error { 39 return loadJSON(s, src) 40 } 41 42 func (s OptionsCamp) Value() (driver.Value, error) { 43 return dumpJSON(s) 44 } 45 46 func (s *Envois) Scan(src interface{}) error { 47 return loadJSON(s, src) 48 } 49 50 func (s Envois) Value() (driver.Value, error) { 51 return dumpJSON(s) 52 } 53 54 func (m *Modules) Scan(src interface{}) error { 55 return loadJSON(m, src) 56 } 57 58 func (m Modules) Value() (driver.Value, error) { 59 return dumpJSON(m) 60 } 61 62 func (s *DestinatairesOptionnels) Scan(src interface{}) error { 63 return loadJSON(s, src) 64 } 65 66 func (s DestinatairesOptionnels) Value() (driver.Value, error) { 67 return dumpJSON(s) 68 } 69 70 func (s *EtatNegociation) Scan(src interface{}) error { 71 return loadJSON(s, src) 72 } 73 74 func (s EtatNegociation) Value() (driver.Value, error) { 75 return dumpJSON(s) 76 } 77 78 func (s *OptionsParticipant) Scan(src interface{}) error { 79 return loadJSON(s, src) 80 } 81 82 func (s OptionsParticipant) Value() (driver.Value, error) { 83 return dumpJSON(s) 84 } 85 86 func (s *OptionPrixParticipant) Scan(src interface{}) error { 87 return loadJSON(s, src) 88 } 89 90 func (s OptionPrixParticipant) Value() (driver.Value, error) { 91 return dumpJSON(s) 92 } 93 94 func (s *Remises) Scan(src interface{}) error { 95 return loadJSON(s, src) 96 } 97 98 func (s Remises) Value() (driver.Value, error) { 99 return dumpJSON(s) 100 } 101 102 func (s *FicheSanitaire) Scan(src interface{}) error { 103 return loadJSON(s, src) 104 } 105 106 func (s FicheSanitaire) Value() (driver.Value, error) { 107 return dumpJSON(s) 108 } 109 110 func (s *OptionPrixCamp) Scan(src interface{}) error { 111 return loadJSON(s, src) 112 } 113 114 func (s OptionPrixCamp) Value() (driver.Value, error) { 115 return dumpJSON(s) 116 } 117 118 func (s *ListeVetements) Scan(src interface{}) error { 119 return loadJSON(s, src) 120 } 121 122 func (s ListeVetements) Value() (driver.Value, error) { 123 return dumpJSON(s) 124 } 125 126 func (s *IdentificationId) Scan(src interface{}) error { 127 return loadJSON(s, src) 128 } 129 130 func (s IdentificationId) Value() (driver.Value, error) { 131 return dumpJSON(s) 132 } 133 134 func (s *OptionnalPlage) Scan(src interface{}) error { 135 return loadJSON(s, src) 136 } 137 138 func (s OptionnalPlage) Value() (driver.Value, error) { 139 return dumpJSON(s) 140 } 141 142 func (s *InfoDon) Scan(src interface{}) error { 143 return loadJSON(s, src) 144 } 145 146 func (s InfoDon) Value() (driver.Value, error) { 147 return dumpJSON(s) 148 } 149 150 func (s *ListeAttente) Scan(src interface{}) error { 151 return loadJSON(s, src) 152 } 153 154 func (s ListeAttente) Value() (driver.Value, error) { 155 return dumpJSON(s) 156 } 157 158 func (s *Plage) Scan(src interface{}) error { 159 return loadJSON(s, src) 160 } 161 162 func (s Plage) Value() (driver.Value, error) { 163 return dumpJSON(s) 164 } 165 166 func (s *ParticipantInscriptions) Scan(src interface{}) error { 167 return loadJSON(s, src) 168 } 169 170 func (s ParticipantInscriptions) Value() (driver.Value, error) { 171 return dumpJSON(s) 172 } 173 174 func (s *ResponsableLegal) Scan(src interface{}) error { 175 return loadJSON(s, src) 176 } 177 178 func (s ResponsableLegal) Value() (driver.Value, error) { 179 return dumpJSON(s) 180 } 181 182 func (s *Coordonnees) Scan(src interface{}) error { 183 return loadJSON(s, src) 184 } 185 186 func (s Coordonnees) Value() (driver.Value, error) { 187 return dumpJSON(s) 188 }