/
djangocontenttype.xo.go
181 lines (144 loc) · 3.87 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
// Package oracle contains the types for schema 'django'.
package oracle
// GENERATED BY XO. DO NOT EDIT.
import (
"database/sql"
"errors"
)
// DjangoContentType represents a row from 'django.django_content_type'.
type DjangoContentType struct {
ID float64 // id
AppLabel sql.NullString // app_label
Model sql.NullString // 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 query
const sqlstr = `INSERT INTO django.django_content_type (` +
`app_label, model` +
`) VALUES (` +
`:1, :2` +
`) RETURNING id /*lastInsertId*/ INTO :pk`
// run query
XOLog(sqlstr, dct.AppLabel, dct.Model, nil)
res, err := db.Exec(sqlstr, dct.AppLabel, dct.Model, nil)
if err != nil {
return err
}
// retrieve id
id, err := res.LastInsertId()
if err != nil {
return err
}
// set primary key and existence
dct.ID = float64(id)
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 django.django_content_type SET ` +
`app_label = :1, model = :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)
}
// 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 django.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 'django.django_content_type' as a DjangoContentType.
//
// Generated from index 'django_app_label_76bd3d3b_uniq'.
func DjangoContentTypeByAppLabelModel(db XODB, appLabel sql.NullString, model sql.NullString) (*DjangoContentType, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, app_label, model ` +
`FROM django.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 'django.django_content_type' as a DjangoContentType.
//
// Generated from index 'sys_c004955'.
func DjangoContentTypeByID(db XODB, id float64) (*DjangoContentType, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, app_label, model ` +
`FROM django.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
}