This repository was archived by the owner on Jan 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeometry_columns.go
More file actions
514 lines (432 loc) · 15.9 KB
/
Copy pathgeometry_columns.go
File metadata and controls
514 lines (432 loc) · 15.9 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
// Code generated by SQLBoiler 4.11.0 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package models
import (
"context"
"database/sql"
"fmt"
"reflect"
"strconv"
"strings"
"sync"
"time"
"github.com/friendsofgo/errors"
"github.com/volatiletech/null/v8"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries"
"github.com/volatiletech/sqlboiler/v4/queries/qm"
"github.com/volatiletech/sqlboiler/v4/queries/qmhelper"
"github.com/volatiletech/strmangle"
)
// GeometryColumn is an object representing the database table.
type GeometryColumn struct {
FTableCatalog null.String `boil:"f_table_catalog" json:"f_table_catalog,omitempty" toml:"f_table_catalog" yaml:"f_table_catalog,omitempty"`
FTableSchema null.String `boil:"f_table_schema" json:"f_table_schema,omitempty" toml:"f_table_schema" yaml:"f_table_schema,omitempty"`
FTableName null.String `boil:"f_table_name" json:"f_table_name,omitempty" toml:"f_table_name" yaml:"f_table_name,omitempty"`
FGeometryColumn null.String `boil:"f_geometry_column" json:"f_geometry_column,omitempty" toml:"f_geometry_column" yaml:"f_geometry_column,omitempty"`
CoordDimension null.Int `boil:"coord_dimension" json:"coord_dimension,omitempty" toml:"coord_dimension" yaml:"coord_dimension,omitempty"`
Srid null.Int `boil:"srid" json:"srid,omitempty" toml:"srid" yaml:"srid,omitempty"`
Type null.String `boil:"type" json:"type,omitempty" toml:"type" yaml:"type,omitempty"`
}
var GeometryColumnColumns = struct {
FTableCatalog string
FTableSchema string
FTableName string
FGeometryColumn string
CoordDimension string
Srid string
Type string
}{
FTableCatalog: "f_table_catalog",
FTableSchema: "f_table_schema",
FTableName: "f_table_name",
FGeometryColumn: "f_geometry_column",
CoordDimension: "coord_dimension",
Srid: "srid",
Type: "type",
}
var GeometryColumnTableColumns = struct {
FTableCatalog string
FTableSchema string
FTableName string
FGeometryColumn string
CoordDimension string
Srid string
Type string
}{
FTableCatalog: "geometry_columns.f_table_catalog",
FTableSchema: "geometry_columns.f_table_schema",
FTableName: "geometry_columns.f_table_name",
FGeometryColumn: "geometry_columns.f_geometry_column",
CoordDimension: "geometry_columns.coord_dimension",
Srid: "geometry_columns.srid",
Type: "geometry_columns.type",
}
// Generated where
var GeometryColumnWhere = struct {
FTableCatalog whereHelpernull_String
FTableSchema whereHelpernull_String
FTableName whereHelpernull_String
FGeometryColumn whereHelpernull_String
CoordDimension whereHelpernull_Int
Srid whereHelpernull_Int
Type whereHelpernull_String
}{
FTableCatalog: whereHelpernull_String{field: "\"geometry_columns\".\"f_table_catalog\""},
FTableSchema: whereHelpernull_String{field: "\"geometry_columns\".\"f_table_schema\""},
FTableName: whereHelpernull_String{field: "\"geometry_columns\".\"f_table_name\""},
FGeometryColumn: whereHelpernull_String{field: "\"geometry_columns\".\"f_geometry_column\""},
CoordDimension: whereHelpernull_Int{field: "\"geometry_columns\".\"coord_dimension\""},
Srid: whereHelpernull_Int{field: "\"geometry_columns\".\"srid\""},
Type: whereHelpernull_String{field: "\"geometry_columns\".\"type\""},
}
var (
geometryColumnAllColumns = []string{"f_table_catalog", "f_table_schema", "f_table_name", "f_geometry_column", "coord_dimension", "srid", "type"}
geometryColumnColumnsWithoutDefault = []string{}
geometryColumnColumnsWithDefault = []string{"f_table_catalog", "f_table_schema", "f_table_name", "f_geometry_column", "coord_dimension", "srid", "type"}
geometryColumnPrimaryKeyColumns = []string{}
geometryColumnGeneratedColumns = []string{}
)
type (
// GeometryColumnSlice is an alias for a slice of pointers to GeometryColumn.
// This should almost always be used instead of []GeometryColumn.
GeometryColumnSlice []*GeometryColumn
// GeometryColumnHook is the signature for custom GeometryColumn hook methods
GeometryColumnHook func(context.Context, boil.ContextExecutor, *GeometryColumn) error
geometryColumnQuery struct {
*queries.Query
}
)
// Cache for insert, update and upsert
var (
geometryColumnType = reflect.TypeOf(&GeometryColumn{})
geometryColumnMapping = queries.MakeStructMapping(geometryColumnType)
geometryColumnInsertCacheMut sync.RWMutex
geometryColumnInsertCache = make(map[string]insertCache)
geometryColumnUpdateCacheMut sync.RWMutex
geometryColumnUpdateCache = make(map[string]updateCache)
geometryColumnUpsertCacheMut sync.RWMutex
geometryColumnUpsertCache = make(map[string]insertCache)
)
var (
// Force time package dependency for automated UpdatedAt/CreatedAt.
_ = time.Second
// Force qmhelper dependency for where clause generation (which doesn't
// always happen)
_ = qmhelper.Where
// These are used in some views
_ = fmt.Sprintln("")
_ = reflect.Int
_ = strings.Builder{}
_ = sync.Mutex{}
_ = strmangle.Plural("")
_ = strconv.IntSize
)
var geometryColumnAfterSelectHooks []GeometryColumnHook
var geometryColumnBeforeInsertHooks []GeometryColumnHook
var geometryColumnAfterInsertHooks []GeometryColumnHook
var geometryColumnBeforeUpsertHooks []GeometryColumnHook
var geometryColumnAfterUpsertHooks []GeometryColumnHook
// doAfterSelectHooks executes all "after Select" hooks.
func (o *GeometryColumn) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range geometryColumnAfterSelectHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeInsertHooks executes all "before insert" hooks.
func (o *GeometryColumn) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range geometryColumnBeforeInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterInsertHooks executes all "after Insert" hooks.
func (o *GeometryColumn) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range geometryColumnAfterInsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doBeforeUpsertHooks executes all "before Upsert" hooks.
func (o *GeometryColumn) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range geometryColumnBeforeUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// doAfterUpsertHooks executes all "after Upsert" hooks.
func (o *GeometryColumn) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
if boil.HooksAreSkipped(ctx) {
return nil
}
for _, hook := range geometryColumnAfterUpsertHooks {
if err := hook(ctx, exec, o); err != nil {
return err
}
}
return nil
}
// AddGeometryColumnHook registers your hook function for all future operations.
func AddGeometryColumnHook(hookPoint boil.HookPoint, geometryColumnHook GeometryColumnHook) {
switch hookPoint {
case boil.AfterSelectHook:
geometryColumnAfterSelectHooks = append(geometryColumnAfterSelectHooks, geometryColumnHook)
case boil.BeforeInsertHook:
geometryColumnBeforeInsertHooks = append(geometryColumnBeforeInsertHooks, geometryColumnHook)
case boil.AfterInsertHook:
geometryColumnAfterInsertHooks = append(geometryColumnAfterInsertHooks, geometryColumnHook)
case boil.BeforeUpsertHook:
geometryColumnBeforeUpsertHooks = append(geometryColumnBeforeUpsertHooks, geometryColumnHook)
case boil.AfterUpsertHook:
geometryColumnAfterUpsertHooks = append(geometryColumnAfterUpsertHooks, geometryColumnHook)
}
}
// One returns a single geometryColumn record from the query.
func (q geometryColumnQuery) One(ctx context.Context, exec boil.ContextExecutor) (*GeometryColumn, error) {
o := &GeometryColumn{}
queries.SetLimit(q.Query, 1)
err := q.Bind(ctx, exec, o)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, sql.ErrNoRows
}
return nil, errors.Wrap(err, "models: failed to execute a one query for geometry_columns")
}
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
return o, nil
}
// All returns all GeometryColumn records from the query.
func (q geometryColumnQuery) All(ctx context.Context, exec boil.ContextExecutor) (GeometryColumnSlice, error) {
var o []*GeometryColumn
err := q.Bind(ctx, exec, &o)
if err != nil {
return nil, errors.Wrap(err, "models: failed to assign all query results to GeometryColumn slice")
}
if len(geometryColumnAfterSelectHooks) != 0 {
for _, obj := range o {
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
return o, err
}
}
}
return o, nil
}
// Count returns the count of all GeometryColumn records in the query.
func (q geometryColumnQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
var count int64
queries.SetSelect(q.Query, nil)
queries.SetCount(q.Query)
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
if err != nil {
return 0, errors.Wrap(err, "models: failed to count geometry_columns rows")
}
return count, nil
}
// Exists checks if the row exists in the table.
func (q geometryColumnQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
var count int64
queries.SetSelect(q.Query, nil)
queries.SetCount(q.Query)
queries.SetLimit(q.Query, 1)
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
if err != nil {
return false, errors.Wrap(err, "models: failed to check if geometry_columns exists")
}
return count > 0, nil
}
// GeometryColumns retrieves all the records using an executor.
func GeometryColumns(mods ...qm.QueryMod) geometryColumnQuery {
mods = append(mods, qm.From("\"geometry_columns\""))
q := NewQuery(mods...)
if len(queries.GetSelect(q)) == 0 {
queries.SetSelect(q, []string{"\"geometry_columns\".*"})
}
return geometryColumnQuery{q}
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
func (o *GeometryColumn) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
if o == nil {
return errors.New("models: no geometry_columns provided for insertion")
}
var err error
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(geometryColumnColumnsWithDefault, o)
key := makeCacheKey(columns, nzDefaults)
geometryColumnInsertCacheMut.RLock()
cache, cached := geometryColumnInsertCache[key]
geometryColumnInsertCacheMut.RUnlock()
if !cached {
wl, returnColumns := columns.InsertColumnSet(
geometryColumnAllColumns,
geometryColumnColumnsWithDefault,
geometryColumnColumnsWithoutDefault,
nzDefaults,
)
cache.valueMapping, err = queries.BindMapping(geometryColumnType, geometryColumnMapping, wl)
if err != nil {
return err
}
cache.retMapping, err = queries.BindMapping(geometryColumnType, geometryColumnMapping, returnColumns)
if err != nil {
return err
}
if len(wl) != 0 {
cache.query = fmt.Sprintf("INSERT INTO \"geometry_columns\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
} else {
cache.query = "INSERT INTO \"geometry_columns\" %sDEFAULT VALUES%s"
}
var queryOutput, queryReturning string
if len(cache.retMapping) != 0 {
queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
}
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
}
value := reflect.Indirect(reflect.ValueOf(o))
vals := queries.ValuesFromMapping(value, cache.valueMapping)
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, cache.query)
fmt.Fprintln(writer, vals)
}
if len(cache.retMapping) != 0 {
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
} else {
_, err = exec.ExecContext(ctx, cache.query, vals...)
}
if err != nil {
return errors.Wrap(err, "models: unable to insert into geometry_columns")
}
if !cached {
geometryColumnInsertCacheMut.Lock()
geometryColumnInsertCache[key] = cache
geometryColumnInsertCacheMut.Unlock()
}
return o.doAfterInsertHooks(ctx, exec)
}
// Upsert attempts an insert using an executor, and does an update or ignore on conflict.
// See boil.Columns documentation for how to properly use updateColumns and insertColumns.
func (o *GeometryColumn) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error {
if o == nil {
return errors.New("models: no geometry_columns provided for upsert")
}
if err := o.doBeforeUpsertHooks(ctx, exec); err != nil {
return err
}
nzDefaults := queries.NonZeroDefaultSet(geometryColumnColumnsWithDefault, o)
// Build cache key in-line uglily - mysql vs psql problems
buf := strmangle.GetBuffer()
if updateOnConflict {
buf.WriteByte('t')
} else {
buf.WriteByte('f')
}
buf.WriteByte('.')
for _, c := range conflictColumns {
buf.WriteString(c)
}
buf.WriteByte('.')
buf.WriteString(strconv.Itoa(updateColumns.Kind))
for _, c := range updateColumns.Cols {
buf.WriteString(c)
}
buf.WriteByte('.')
buf.WriteString(strconv.Itoa(insertColumns.Kind))
for _, c := range insertColumns.Cols {
buf.WriteString(c)
}
buf.WriteByte('.')
for _, c := range nzDefaults {
buf.WriteString(c)
}
key := buf.String()
strmangle.PutBuffer(buf)
geometryColumnUpsertCacheMut.RLock()
cache, cached := geometryColumnUpsertCache[key]
geometryColumnUpsertCacheMut.RUnlock()
var err error
if !cached {
insert, ret := insertColumns.InsertColumnSet(
geometryColumnAllColumns,
geometryColumnColumnsWithDefault,
geometryColumnColumnsWithoutDefault,
nzDefaults,
)
update := updateColumns.UpdateColumnSet(
geometryColumnAllColumns,
geometryColumnPrimaryKeyColumns,
)
if updateOnConflict && len(update) == 0 {
return errors.New("models: unable to upsert geometry_columns, could not build update column list")
}
conflict := conflictColumns
if len(conflict) == 0 {
conflict = make([]string, len(geometryColumnPrimaryKeyColumns))
copy(conflict, geometryColumnPrimaryKeyColumns)
}
cache.query = buildUpsertQueryPostgres(dialect, "\"geometry_columns\"", updateOnConflict, ret, update, conflict, insert)
cache.valueMapping, err = queries.BindMapping(geometryColumnType, geometryColumnMapping, insert)
if err != nil {
return err
}
if len(ret) != 0 {
cache.retMapping, err = queries.BindMapping(geometryColumnType, geometryColumnMapping, ret)
if err != nil {
return err
}
}
}
value := reflect.Indirect(reflect.ValueOf(o))
vals := queries.ValuesFromMapping(value, cache.valueMapping)
var returns []interface{}
if len(cache.retMapping) != 0 {
returns = queries.PtrsFromMapping(value, cache.retMapping)
}
if boil.IsDebug(ctx) {
writer := boil.DebugWriterFrom(ctx)
fmt.Fprintln(writer, cache.query)
fmt.Fprintln(writer, vals)
}
if len(cache.retMapping) != 0 {
err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...)
if errors.Is(err, sql.ErrNoRows) {
err = nil // Postgres doesn't return anything when there's no update
}
} else {
_, err = exec.ExecContext(ctx, cache.query, vals...)
}
if err != nil {
return errors.Wrap(err, "models: unable to upsert geometry_columns")
}
if !cached {
geometryColumnUpsertCacheMut.Lock()
geometryColumnUpsertCache[key] = cache
geometryColumnUpsertCacheMut.Unlock()
}
return o.doAfterUpsertHooks(ctx, exec)
}