-
-
Notifications
You must be signed in to change notification settings - Fork 165
/
nodes.mapper.go
44 lines (34 loc) · 914 Bytes
/
nodes.mapper.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
//go:build linux && cgo && !agent
package cluster
// The code below was generated by incus-generate - DO NOT EDIT!
import (
"context"
"database/sql"
"errors"
"fmt"
"net/http"
"github.com/lxc/incus/shared/api"
)
var _ = api.ServerEnvironment{}
var nodeID = RegisterStmt(`
SELECT nodes.id FROM nodes
WHERE nodes.name = ?
`)
// GetNodeID return the ID of the node with the given key.
// generator: node ID
func GetNodeID(ctx context.Context, tx *sql.Tx, name string) (int64, error) {
stmt, err := Stmt(tx, nodeID)
if err != nil {
return -1, fmt.Errorf("Failed to get \"nodeID\" prepared statement: %w", err)
}
row := stmt.QueryRowContext(ctx, name)
var id int64
err = row.Scan(&id)
if errors.Is(err, sql.ErrNoRows) {
return -1, api.StatusErrorf(http.StatusNotFound, "Node not found")
}
if err != nil {
return -1, fmt.Errorf("Failed to get \"nodes\" ID: %w", err)
}
return id, nil
}