forked from xo/xo
/
aforeignkeycomposite.xo.go
53 lines (48 loc) · 1.59 KB
/
aforeignkeycomposite.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
package mysql
// Code generated by xo. DO NOT EDIT.
import (
"context"
"database/sql"
)
// AForeignKeyComposite represents a row from 'a_bit_of_everything.a_foreign_key_composite'.
type AForeignKeyComposite struct {
AKey1 sql.NullInt64 `json:"a_key1"` // a_key1
AKey2 sql.NullInt64 `json:"a_key2"` // a_key2
}
// AForeignKeyCompositeByAKey1AKey2 retrieves a row from 'a_bit_of_everything.a_foreign_key_composite' as a AForeignKeyComposite.
//
// Generated from index 'a_key1'.
func AForeignKeyCompositeByAKey1AKey2(ctx context.Context, db DB, aKey1, aKey2 sql.NullInt64) ([]*AForeignKeyComposite, error) {
// query
const sqlstr = `SELECT ` +
`a_key1, a_key2 ` +
`FROM a_bit_of_everything.a_foreign_key_composite ` +
`WHERE a_key1 = ? AND a_key2 = ?`
// run
logf(sqlstr, aKey1, aKey2)
rows, err := db.QueryContext(ctx, sqlstr, aKey1, aKey2)
if err != nil {
return nil, logerror(err)
}
defer rows.Close()
// process
var res []*AForeignKeyComposite
for rows.Next() {
afkc := AForeignKeyComposite{}
// scan
if err := rows.Scan(&afkc.AKey1, &afkc.AKey2); err != nil {
return nil, logerror(err)
}
res = append(res, &afkc)
}
if err := rows.Err(); err != nil {
return nil, logerror(err)
}
return res, nil
}
// APrimaryComposite returns the APrimaryComposite associated with the AForeignKeyComposite's (AKey1, AKey2).
//
// Generated from foreign key 'a_foreign_key_composite_ibfk_1'.
func (afkc *AForeignKeyComposite) APrimaryComposite(ctx context.Context, db DB) (*APrimaryComposite, error) {
return APrimaryCompositeByAKey1AKey2(ctx, db, int(afkc.AKey1.Int64), int(afkc.AKey2.Int64))
}