/
djangocontenttype.xo.go
210 lines (168 loc) · 4.54 KB
/
djangocontenttype.xo.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Package postgres contains the types for schema 'public'.
package postgres
// GENERATED BY XO. DO NOT EDIT.
import (
"errors"
)
// DjangoContentType represents a row from 'public.django_content_type'.
type DjangoContentType struct {
ID int `json:"id"` // id
AppLabel string `json:"app_label"` // app_label
Model string `json:"model"` // model
// xo fields
_exists, _deleted bool
}
// Exists determines if the DjangoContentType exists in the database.
func (dct *DjangoContentType) Exists() bool {
return dct._exists
}
// Deleted provides information if the DjangoContentType has been deleted from the database.
func (dct *DjangoContentType) Deleted() bool {
return dct._deleted
}
// Insert inserts the DjangoContentType to the database.
func (dct *DjangoContentType) Insert(db XODB) error {
var err error
// if already exist, bail
if dct._exists {
return errors.New("insert failed: already exists")
}
// sql insert query, primary key provided by sequence
const sqlstr = `INSERT INTO public.django_content_type (` +
`app_label, model` +
`) VALUES (` +
`$1, $2` +
`) RETURNING id`
// run query
XOLog(sqlstr, dct.AppLabel, dct.Model)
err = db.QueryRow(sqlstr, dct.AppLabel, dct.Model).Scan(&dct.ID)
if err != nil {
return err
}
// set existence
dct._exists = true
return nil
}
// Update updates the DjangoContentType in the database.
func (dct *DjangoContentType) Update(db XODB) error {
var err error
// if doesn't exist, bail
if !dct._exists {
return errors.New("update failed: does not exist")
}
// if deleted, bail
if dct._deleted {
return errors.New("update failed: marked for deletion")
}
// sql query
const sqlstr = `UPDATE public.django_content_type SET (` +
`app_label, model` +
`) = ( ` +
`$1, $2` +
`) WHERE id = $3`
// run query
XOLog(sqlstr, dct.AppLabel, dct.Model, dct.ID)
_, err = db.Exec(sqlstr, dct.AppLabel, dct.Model, dct.ID)
return err
}
// Save saves the DjangoContentType to the database.
func (dct *DjangoContentType) Save(db XODB) error {
if dct.Exists() {
return dct.Update(db)
}
return dct.Insert(db)
}
// Upsert performs an upsert for DjangoContentType.
//
// NOTE: PostgreSQL 9.5+ only
func (dct *DjangoContentType) Upsert(db XODB) error {
var err error
// if already exist, bail
if dct._exists {
return errors.New("insert failed: already exists")
}
// sql query
const sqlstr = `INSERT INTO public.django_content_type (` +
`id, app_label, model` +
`) VALUES (` +
`$1, $2, $3` +
`) ON CONFLICT (id) DO UPDATE SET (` +
`id, app_label, model` +
`) = (` +
`EXCLUDED.id, EXCLUDED.app_label, EXCLUDED.model` +
`)`
// run query
XOLog(sqlstr, dct.ID, dct.AppLabel, dct.Model)
_, err = db.Exec(sqlstr, dct.ID, dct.AppLabel, dct.Model)
if err != nil {
return err
}
// set existence
dct._exists = true
return nil
}
// Delete deletes the DjangoContentType from the database.
func (dct *DjangoContentType) Delete(db XODB) error {
var err error
// if doesn't exist, bail
if !dct._exists {
return nil
}
// if deleted, bail
if dct._deleted {
return nil
}
// sql query
const sqlstr = `DELETE FROM public.django_content_type WHERE id = $1`
// run query
XOLog(sqlstr, dct.ID)
_, err = db.Exec(sqlstr, dct.ID)
if err != nil {
return err
}
// set deleted
dct._deleted = true
return nil
}
// DjangoContentTypeByAppLabelModel retrieves a row from 'public.django_content_type' as a DjangoContentType.
//
// Generated from index 'django_content_type_app_label_76bd3d3b_uniq'.
func DjangoContentTypeByAppLabelModel(db XODB, appLabel string, model string) (*DjangoContentType, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, app_label, model ` +
`FROM public.django_content_type ` +
`WHERE app_label = $1 AND model = $2`
// run query
XOLog(sqlstr, appLabel, model)
dct := DjangoContentType{
_exists: true,
}
err = db.QueryRow(sqlstr, appLabel, model).Scan(&dct.ID, &dct.AppLabel, &dct.Model)
if err != nil {
return nil, err
}
return &dct, nil
}
// DjangoContentTypeByID retrieves a row from 'public.django_content_type' as a DjangoContentType.
//
// Generated from index 'django_content_type_pkey'.
func DjangoContentTypeByID(db XODB, id int) (*DjangoContentType, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, app_label, model ` +
`FROM public.django_content_type ` +
`WHERE id = $1`
// run query
XOLog(sqlstr, id)
dct := DjangoContentType{
_exists: true,
}
err = db.QueryRow(sqlstr, id).Scan(&dct.ID, &dct.AppLabel, &dct.Model)
if err != nil {
return nil, err
}
return &dct, nil
}