MCPcopy
hub / github.com/dosco/graphjin / setLocalUserID

Method setLocalUserID

core/gstate.go:954–978  ·  view source on GitHub ↗
(c context.Context, conn *sql.Conn)

Source from the content-addressed store, hash-verified

952}
953
954func (s *gstate) setLocalUserID(c context.Context, conn *sql.Conn) (err error) {
955 if v := c.Value(UserIDKey); v == nil {
956 return nil
957 } else {
958 var val string
959 switch v1 := v.(type) {
960 case string:
961 val = v1
962 case int:
963 val = strconv.Itoa(v1)
964 }
965
966 q := s.getTargetPsqlCompiler().RenderSetSessionVar("user.id", val)
967 if q == "" {
968 return nil
969 }
970
971 if tx := s.tx(); tx != nil {
972 _, err = tx.ExecContext(c, q)
973 } else {
974 _, err = conn.ExecContext(c, q)
975 }
976 }
977 return
978}
979
980var errValidationFailed = errors.New("validation failed")
981

Callers 1

compileAndExecuteMethod · 0.95

Calls 5

getTargetPsqlCompilerMethod · 0.95
txMethod · 0.95
ValueMethod · 0.65
RenderSetSessionVarMethod · 0.65
ExecContextMethod · 0.65

Tested by

no test coverage detected