-
Notifications
You must be signed in to change notification settings - Fork 7
/
system_parameter.go
41 lines (34 loc) · 1014 Bytes
/
system_parameter.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
package materialize
import (
"fmt"
"github.com/jmoiron/sqlx"
)
type SystemParameterBuilder struct {
ddl Builder
paramName string
paramValue string
}
func NewSystemParameterBuilder(conn *sqlx.DB, paramName, paramValue string) *SystemParameterBuilder {
return &SystemParameterBuilder{
ddl: Builder{conn, System},
paramName: paramName,
paramValue: paramValue,
}
}
func (b *SystemParameterBuilder) Set() error {
q := fmt.Sprintf(`ALTER SYSTEM SET "%s" TO '%s';`, b.paramName, b.paramValue)
return b.ddl.exec(q)
}
func (b *SystemParameterBuilder) Reset() error {
q := fmt.Sprintf(`ALTER SYSTEM RESET "%s";`, b.paramName)
return b.ddl.exec(q)
}
func ShowSystemParameter(conn *sqlx.DB, paramName string) (string, error) {
var paramValue string
query := fmt.Sprintf(`SHOW %s;`, QuoteIdentifier(paramName))
err := conn.QueryRow(query).Scan(¶mValue)
if err != nil {
return "", fmt.Errorf("error reading system parameter %s: %v", paramName, err)
}
return paramValue, nil
}