-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathapartitiontable.xo.go
More file actions
94 lines (85 loc) · 2.53 KB
/
apartitiontable.xo.go
File metadata and controls
94 lines (85 loc) · 2.53 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
package postgres
// Code generated by xo. DO NOT EDIT.
import (
"context"
"time"
)
// APartitionTable represents a row from 'public.a_partition_table'.
type APartitionTable struct {
AKey1 int `json:"a_key1"` // a_key1
AKey2 time.Time `json:"a_key2"` // a_key2
// xo fields
_exists, _deleted bool
}
// Exists returns true when the [APartitionTable] exists in the database.
func (apt *APartitionTable) Exists() bool {
return apt._exists
}
// Deleted returns true when the [APartitionTable] has been marked for deletion
// from the database.
func (apt *APartitionTable) Deleted() bool {
return apt._deleted
}
// Insert inserts the [APartitionTable] to the database.
func (apt *APartitionTable) Insert(ctx context.Context, db DB) error {
switch {
case apt._exists: // already exists
return logerror(&ErrInsertFailed{ErrAlreadyExists})
case apt._deleted: // deleted
return logerror(&ErrInsertFailed{ErrMarkedForDeletion})
}
// insert (manual)
const sqlstr = `INSERT INTO public.a_partition_table (` +
`a_key1, a_key2` +
`) VALUES (` +
`$1, $2` +
`)`
// run
logf(sqlstr, apt.AKey1, apt.AKey2)
if _, err := db.ExecContext(ctx, sqlstr, apt.AKey1, apt.AKey2); err != nil {
return logerror(err)
}
// set exists
apt._exists = true
return nil
}
// ------ NOTE: Update statements omitted due to lack of fields other than primary key ------
// Delete deletes the [APartitionTable] from the database.
func (apt *APartitionTable) Delete(ctx context.Context, db DB) error {
switch {
case !apt._exists: // doesn't exist
return nil
case apt._deleted: // deleted
return nil
}
// delete with composite primary key
const sqlstr = `DELETE FROM public.a_partition_table ` +
`WHERE a_key1 = $1 AND a_key2 = $2`
// run
logf(sqlstr, apt.AKey1, apt.AKey2)
if _, err := db.ExecContext(ctx, sqlstr, apt.AKey1, apt.AKey2); err != nil {
return logerror(err)
}
// set deleted
apt._deleted = true
return nil
}
// APartitionTableByAKey1AKey2 retrieves a row from 'public.a_partition_table' as a [APartitionTable].
//
// Generated from index 'a_partition_table_pkey'.
func APartitionTableByAKey1AKey2(ctx context.Context, db DB, aKey1 int, aKey2 time.Time) (*APartitionTable, error) {
// query
const sqlstr = `SELECT ` +
`a_key1, a_key2 ` +
`FROM public.a_partition_table ` +
`WHERE a_key1 = $1 AND a_key2 = $2`
// run
logf(sqlstr, aKey1, aKey2)
apt := APartitionTable{
_exists: true,
}
if err := db.QueryRowContext(ctx, sqlstr, aKey1, aKey2).Scan(&apt.AKey1, &apt.AKey2); err != nil {
return nil, logerror(err)
}
return &apt, nil
}