-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextensions.go
103 lines (82 loc) · 1.89 KB
/
extensions.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package database
import (
// "database/sql/driver"
// "encoding/json"
// "database/sql"
"encoding/json"
"github.com/jackc/pgx/v5"
)
func (q Queries) GetSqlDB() *pgx.Conn {
return q.db.(*pgx.Conn)
}
type FullInvoice struct {
Invoice
Items any `json:"items"`
Clients any `json:"client"`
}
func removeNilValues(input []interface{}) []interface{} {
var result = make([]interface{}, 0)
for _, value := range input {
if value != nil {
result = append(result, value)
}
}
return result
}
func (i *FindInvoicesWhereRow) ToFullInvoice() (*FullInvoice, error) {
var client []any
err := json.Unmarshal(i.Client, &client)
if err != nil {
return nil, err
}
var jsonItems []any
err = json.Unmarshal(i.Items, &jsonItems)
if err != nil {
return nil, err
}
return &FullInvoice{
Invoice: i.Invoice,
Items: removeNilValues(jsonItems),
Clients: client[0],
}, nil
}
type FullUserProfile struct {
GetUserProfileWhereRow
Business any `json:"business"`
}
func (i *GetUserProfileWhereRow) ToFullUser() (*FullUserProfile, error) {
var business []any
err := json.Unmarshal(i.Business, &business)
if err != nil {
return nil, err
}
return &FullUserProfile{
GetUserProfileWhereRow: *i,
Business: business[0],
}, nil
}
// func (h *InvoiceItemList) Value() (driver.Value, error) {
// println("value")
// if h != nil {
// return json.Marshal(h)
// }
// return nil, nil
// }
// func (h *InvoiceItemList) Scan(value interface{}) error {
// return json.Unmarshal(value.([]byte), h)
// }
// func (h *GetUserProfileWhereRow) MarshalJSON() ([]byte, error) {
// type Alias GetUserProfileWhereRow
// return json.Marshal(&struct {
// *Alias
// Items interface{} `json:"items"`
// }{
// Alias: (*Alias)(h),
// })
// }
// func (h *GetUserProfileWhereRow) UnmarshalJSON(data []byte) error {
// if err := json.Unmarshal(data, h); err != nil {
// return err
// }
// return nil
// }