id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
160,300 | ginuerzh/gost | client.go | Handshake | func Handshake(conn net.Conn, options ...HandshakeOption) (net.Conn, error) {
return DefaultClient.Handshake(conn, options...)
} | go | func Handshake(conn net.Conn, options ...HandshakeOption) (net.Conn, error) {
return DefaultClient.Handshake(conn, options...)
} | [
"func",
"Handshake",
"(",
"conn",
"net",
".",
"Conn",
",",
"options",
"...",
"HandshakeOption",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"return",
"DefaultClient",
".",
"Handshake",
"(",
"conn",
",",
"options",
"...",
")",
"\n",
"}"
] | // Handshake performs a handshake via the DefaultClient. | [
"Handshake",
"performs",
"a",
"handshake",
"via",
"the",
"DefaultClient",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L45-L47 |
160,301 | ginuerzh/gost | client.go | Connect | func Connect(conn net.Conn, addr string) (net.Conn, error) {
return DefaultClient.Connect(conn, addr)
} | go | func Connect(conn net.Conn, addr string) (net.Conn, error) {
return DefaultClient.Connect(conn, addr)
} | [
"func",
"Connect",
"(",
"conn",
"net",
".",
"Conn",
",",
"addr",
"string",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"return",
"DefaultClient",
".",
"Connect",
"(",
"conn",
",",
"addr",
")",
"\n",
"}"
] | // Connect connects to the address addr via the DefaultClient. | [
"Connect",
"connects",
"to",
"the",
"address",
"addr",
"via",
"the",
"DefaultClient",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L50-L52 |
160,302 | ginuerzh/gost | client.go | TimeoutDialOption | func TimeoutDialOption(timeout time.Duration) DialOption {
return func(opts *DialOptions) {
opts.Timeout = timeout
}
} | go | func TimeoutDialOption(timeout time.Duration) DialOption {
return func(opts *DialOptions) {
opts.Timeout = timeout
}
} | [
"func",
"TimeoutDialOption",
"(",
"timeout",
"time",
".",
"Duration",
")",
"DialOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"DialOptions",
")",
"{",
"opts",
".",
"Timeout",
"=",
"timeout",
"\n",
"}",
"\n",
"}"
] | // TimeoutDialOption specifies the timeout used by Transporter.Dial | [
"TimeoutDialOption",
"specifies",
"the",
"timeout",
"used",
"by",
"Transporter",
".",
"Dial"
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L139-L143 |
160,303 | ginuerzh/gost | client.go | UserHandshakeOption | func UserHandshakeOption(user *url.Userinfo) HandshakeOption {
return func(opts *HandshakeOptions) {
opts.User = user
}
} | go | func UserHandshakeOption(user *url.Userinfo) HandshakeOption {
return func(opts *HandshakeOptions) {
opts.User = user
}
} | [
"func",
"UserHandshakeOption",
"(",
"user",
"*",
"url",
".",
"Userinfo",
")",
"HandshakeOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"HandshakeOptions",
")",
"{",
"opts",
".",
"User",
"=",
"user",
"\n",
"}",
"\n",
"}"
] | // UserHandshakeOption specifies the user used by Transporter.Handshake | [
"UserHandshakeOption",
"specifies",
"the",
"user",
"used",
"by",
"Transporter",
".",
"Handshake"
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L184-L188 |
160,304 | ginuerzh/gost | client.go | TimeoutHandshakeOption | func TimeoutHandshakeOption(timeout time.Duration) HandshakeOption {
return func(opts *HandshakeOptions) {
opts.Timeout = timeout
}
} | go | func TimeoutHandshakeOption(timeout time.Duration) HandshakeOption {
return func(opts *HandshakeOptions) {
opts.Timeout = timeout
}
} | [
"func",
"TimeoutHandshakeOption",
"(",
"timeout",
"time",
".",
"Duration",
")",
"HandshakeOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"HandshakeOptions",
")",
"{",
"opts",
".",
"Timeout",
"=",
"timeout",
"\n",
"}",
"\n",
"}"
] | // TimeoutHandshakeOption specifies the timeout used by Transporter.Handshake | [
"TimeoutHandshakeOption",
"specifies",
"the",
"timeout",
"used",
"by",
"Transporter",
".",
"Handshake"
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L191-L195 |
160,305 | ginuerzh/gost | client.go | IntervalHandshakeOption | func IntervalHandshakeOption(interval time.Duration) HandshakeOption {
return func(opts *HandshakeOptions) {
opts.Interval = interval
}
} | go | func IntervalHandshakeOption(interval time.Duration) HandshakeOption {
return func(opts *HandshakeOptions) {
opts.Interval = interval
}
} | [
"func",
"IntervalHandshakeOption",
"(",
"interval",
"time",
".",
"Duration",
")",
"HandshakeOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"HandshakeOptions",
")",
"{",
"opts",
".",
"Interval",
"=",
"interval",
"\n",
"}",
"\n",
"}"
] | // IntervalHandshakeOption specifies the interval time used by Transporter.Handshake | [
"IntervalHandshakeOption",
"specifies",
"the",
"interval",
"time",
"used",
"by",
"Transporter",
".",
"Handshake"
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L198-L202 |
160,306 | ginuerzh/gost | client.go | TLSConfigHandshakeOption | func TLSConfigHandshakeOption(config *tls.Config) HandshakeOption {
return func(opts *HandshakeOptions) {
opts.TLSConfig = config
}
} | go | func TLSConfigHandshakeOption(config *tls.Config) HandshakeOption {
return func(opts *HandshakeOptions) {
opts.TLSConfig = config
}
} | [
"func",
"TLSConfigHandshakeOption",
"(",
"config",
"*",
"tls",
".",
"Config",
")",
"HandshakeOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"HandshakeOptions",
")",
"{",
"opts",
".",
"TLSConfig",
"=",
"config",
"\n",
"}",
"\n",
"}"
] | // TLSConfigHandshakeOption specifies the TLS config used by Transporter.Handshake | [
"TLSConfigHandshakeOption",
"specifies",
"the",
"TLS",
"config",
"used",
"by",
"Transporter",
".",
"Handshake"
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L212-L216 |
160,307 | ginuerzh/gost | client.go | TimeoutConnectOption | func TimeoutConnectOption(timeout time.Duration) ConnectOption {
return func(opts *ConnectOptions) {
opts.Timeout = timeout
}
} | go | func TimeoutConnectOption(timeout time.Duration) ConnectOption {
return func(opts *ConnectOptions) {
opts.Timeout = timeout
}
} | [
"func",
"TimeoutConnectOption",
"(",
"timeout",
"time",
".",
"Duration",
")",
"ConnectOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"ConnectOptions",
")",
"{",
"opts",
".",
"Timeout",
"=",
"timeout",
"\n",
"}",
"\n",
"}"
] | // TimeoutConnectOption specifies the timeout for connecting to target. | [
"TimeoutConnectOption",
"specifies",
"the",
"timeout",
"for",
"connecting",
"to",
"target",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L258-L262 |
160,308 | ginuerzh/gost | client.go | UserConnectOption | func UserConnectOption(user *url.Userinfo) ConnectOption {
return func(opts *ConnectOptions) {
opts.User = user
}
} | go | func UserConnectOption(user *url.Userinfo) ConnectOption {
return func(opts *ConnectOptions) {
opts.User = user
}
} | [
"func",
"UserConnectOption",
"(",
"user",
"*",
"url",
".",
"Userinfo",
")",
"ConnectOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"ConnectOptions",
")",
"{",
"opts",
".",
"User",
"=",
"user",
"\n",
"}",
"\n",
"}"
] | // UserConnectOption specifies the user info for authentication. | [
"UserConnectOption",
"specifies",
"the",
"user",
"info",
"for",
"authentication",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L265-L269 |
160,309 | ginuerzh/gost | client.go | SelectorConnectOption | func SelectorConnectOption(s gosocks5.Selector) ConnectOption {
return func(opts *ConnectOptions) {
opts.Selector = s
}
} | go | func SelectorConnectOption(s gosocks5.Selector) ConnectOption {
return func(opts *ConnectOptions) {
opts.Selector = s
}
} | [
"func",
"SelectorConnectOption",
"(",
"s",
"gosocks5",
".",
"Selector",
")",
"ConnectOption",
"{",
"return",
"func",
"(",
"opts",
"*",
"ConnectOptions",
")",
"{",
"opts",
".",
"Selector",
"=",
"s",
"\n",
"}",
"\n",
"}"
] | // SelectorConnectOption specifies the SOCKS5 client selector. | [
"SelectorConnectOption",
"specifies",
"the",
"SOCKS5",
"client",
"selector",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/client.go#L272-L276 |
160,310 | ginuerzh/gost | permissions.go | Contains | func (ir *PortRange) Contains(value int) bool {
return value >= ir.Min && value <= ir.Max
} | go | func (ir *PortRange) Contains(value int) bool {
return value >= ir.Min && value <= ir.Max
} | [
"func",
"(",
"ir",
"*",
"PortRange",
")",
"Contains",
"(",
"value",
"int",
")",
"bool",
"{",
"return",
"value",
">=",
"ir",
".",
"Min",
"&&",
"value",
"<=",
"ir",
".",
"Max",
"\n",
"}"
] | // Contains checks whether the value is within this range. | [
"Contains",
"checks",
"whether",
"the",
"value",
"is",
"within",
"this",
"range",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/permissions.go#L63-L65 |
160,311 | ginuerzh/gost | permissions.go | ParsePortSet | func ParsePortSet(s string) (*PortSet, error) {
ps := &PortSet{}
if s == "" {
return nil, errors.New("must specify at least one port")
}
ranges := strings.Split(s, ",")
for _, r := range ranges {
portRange, err := ParsePortRange(r)
if err != nil {
return nil, err
}
*ps = append(*ps, *portRange)
}
return ps, nil
} | go | func ParsePortSet(s string) (*PortSet, error) {
ps := &PortSet{}
if s == "" {
return nil, errors.New("must specify at least one port")
}
ranges := strings.Split(s, ",")
for _, r := range ranges {
portRange, err := ParsePortRange(r)
if err != nil {
return nil, err
}
*ps = append(*ps, *portRange)
}
return ps, nil
} | [
"func",
"ParsePortSet",
"(",
"s",
"string",
")",
"(",
"*",
"PortSet",
",",
"error",
")",
"{",
"ps",
":=",
"&",
"PortSet",
"{",
"}",
"\n\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ranges",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n\n",
"for",
"_",
",",
"r",
":=",
"range",
"ranges",
"{",
"portRange",
",",
"err",
":=",
"ParsePortRange",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"*",
"ps",
"=",
"append",
"(",
"*",
"ps",
",",
"*",
"portRange",
")",
"\n",
"}",
"\n\n",
"return",
"ps",
",",
"nil",
"\n",
"}"
] | // ParsePortSet parses the s to a PortSet.
// The s shoud be a comma separated string. | [
"ParsePortSet",
"parses",
"the",
"s",
"to",
"a",
"PortSet",
".",
"The",
"s",
"shoud",
"be",
"a",
"comma",
"separated",
"string",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/permissions.go#L72-L92 |
160,312 | ginuerzh/gost | permissions.go | Contains | func (ps *PortSet) Contains(value int) bool {
for _, portRange := range *ps {
if portRange.Contains(value) {
return true
}
}
return false
} | go | func (ps *PortSet) Contains(value int) bool {
for _, portRange := range *ps {
if portRange.Contains(value) {
return true
}
}
return false
} | [
"func",
"(",
"ps",
"*",
"PortSet",
")",
"Contains",
"(",
"value",
"int",
")",
"bool",
"{",
"for",
"_",
",",
"portRange",
":=",
"range",
"*",
"ps",
"{",
"if",
"portRange",
".",
"Contains",
"(",
"value",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Contains checks whether the value is within this port set. | [
"Contains",
"checks",
"whether",
"the",
"value",
"is",
"within",
"this",
"port",
"set",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/permissions.go#L95-L103 |
160,313 | ginuerzh/gost | permissions.go | ParseStringSet | func ParseStringSet(s string) (*StringSet, error) {
ss := &StringSet{}
if s == "" {
return nil, errors.New("cannot be empty")
}
*ss = strings.Split(s, ",")
return ss, nil
} | go | func ParseStringSet(s string) (*StringSet, error) {
ss := &StringSet{}
if s == "" {
return nil, errors.New("cannot be empty")
}
*ss = strings.Split(s, ",")
return ss, nil
} | [
"func",
"ParseStringSet",
"(",
"s",
"string",
")",
"(",
"*",
"StringSet",
",",
"error",
")",
"{",
"ss",
":=",
"&",
"StringSet",
"{",
"}",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"*",
"ss",
"=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"ss",
",",
"nil",
"\n",
"}"
] | // ParseStringSet parses the s to a StringSet.
// The s shoud be a comma separated string. | [
"ParseStringSet",
"parses",
"the",
"s",
"to",
"a",
"StringSet",
".",
"The",
"s",
"shoud",
"be",
"a",
"comma",
"separated",
"string",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/permissions.go#L110-L119 |
160,314 | ginuerzh/gost | permissions.go | Contains | func (ss *StringSet) Contains(subj string) bool {
for _, s := range *ss {
if glob.Glob(s, subj) {
return true
}
}
return false
} | go | func (ss *StringSet) Contains(subj string) bool {
for _, s := range *ss {
if glob.Glob(s, subj) {
return true
}
}
return false
} | [
"func",
"(",
"ss",
"*",
"StringSet",
")",
"Contains",
"(",
"subj",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"*",
"ss",
"{",
"if",
"glob",
".",
"Glob",
"(",
"s",
",",
"subj",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Contains checks whether the string subj within this StringSet. | [
"Contains",
"checks",
"whether",
"the",
"string",
"subj",
"within",
"this",
"StringSet",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/permissions.go#L122-L130 |
160,315 | ginuerzh/gost | permissions.go | ParsePermissions | func ParsePermissions(s string) (*Permissions, error) {
ps := &Permissions{}
if s == "" {
return &Permissions{}, nil
}
perms := strings.Split(s, " ")
for _, perm := range perms {
parts := strings.Split(perm, ":")
switch len(parts) {
case 3:
actions, err := ParseStringSet(parts[0])
if err != nil {
return nil, fmt.Errorf("action list must look like connect,bind given: %s", parts[0])
}
hosts, err := ParseStringSet(parts[1])
if err != nil {
return nil, fmt.Errorf("hosts list must look like google.pl,*.google.com given: %s", parts[1])
}
ports, err := ParsePortSet(parts[2])
if err != nil {
return nil, fmt.Errorf("ports list must look like 80,8000-9000, given: %s", parts[2])
}
permission := Permission{Actions: *actions, Hosts: *hosts, Ports: *ports}
*ps = append(*ps, permission)
default:
return nil, fmt.Errorf("permission must have format [actions]:[hosts]:[ports] given: %s", perm)
}
}
return ps, nil
} | go | func ParsePermissions(s string) (*Permissions, error) {
ps := &Permissions{}
if s == "" {
return &Permissions{}, nil
}
perms := strings.Split(s, " ")
for _, perm := range perms {
parts := strings.Split(perm, ":")
switch len(parts) {
case 3:
actions, err := ParseStringSet(parts[0])
if err != nil {
return nil, fmt.Errorf("action list must look like connect,bind given: %s", parts[0])
}
hosts, err := ParseStringSet(parts[1])
if err != nil {
return nil, fmt.Errorf("hosts list must look like google.pl,*.google.com given: %s", parts[1])
}
ports, err := ParsePortSet(parts[2])
if err != nil {
return nil, fmt.Errorf("ports list must look like 80,8000-9000, given: %s", parts[2])
}
permission := Permission{Actions: *actions, Hosts: *hosts, Ports: *ports}
*ps = append(*ps, permission)
default:
return nil, fmt.Errorf("permission must have format [actions]:[hosts]:[ports] given: %s", perm)
}
}
return ps, nil
} | [
"func",
"ParsePermissions",
"(",
"s",
"string",
")",
"(",
"*",
"Permissions",
",",
"error",
")",
"{",
"ps",
":=",
"&",
"Permissions",
"{",
"}",
"\n\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"&",
"Permissions",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"perms",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n\n",
"for",
"_",
",",
"perm",
":=",
"range",
"perms",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"perm",
",",
"\"",
"\"",
")",
"\n\n",
"switch",
"len",
"(",
"parts",
")",
"{",
"case",
"3",
":",
"actions",
",",
"err",
":=",
"ParseStringSet",
"(",
"parts",
"[",
"0",
"]",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"parts",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"hosts",
",",
"err",
":=",
"ParseStringSet",
"(",
"parts",
"[",
"1",
"]",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"parts",
"[",
"1",
"]",
")",
"\n",
"}",
"\n\n",
"ports",
",",
"err",
":=",
"ParsePortSet",
"(",
"parts",
"[",
"2",
"]",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"parts",
"[",
"2",
"]",
")",
"\n",
"}",
"\n\n",
"permission",
":=",
"Permission",
"{",
"Actions",
":",
"*",
"actions",
",",
"Hosts",
":",
"*",
"hosts",
",",
"Ports",
":",
"*",
"ports",
"}",
"\n\n",
"*",
"ps",
"=",
"append",
"(",
"*",
"ps",
",",
"permission",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"perm",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"ps",
",",
"nil",
"\n",
"}"
] | // ParsePermissions parses the s to a Permissions. | [
"ParsePermissions",
"parses",
"the",
"s",
"to",
"a",
"Permissions",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/permissions.go#L136-L177 |
160,316 | ginuerzh/gost | permissions.go | Can | func Can(action string, addr string, whitelist, blacklist *Permissions) bool {
if !strings.Contains(addr, ":") {
addr = addr + ":80"
}
host, strport, err := net.SplitHostPort(addr)
if err != nil {
return false
}
port, err := strconv.Atoi(strport)
if err != nil {
return false
}
return (whitelist == nil || whitelist.Can(action, host, port)) &&
(blacklist == nil || !blacklist.Can(action, host, port))
} | go | func Can(action string, addr string, whitelist, blacklist *Permissions) bool {
if !strings.Contains(addr, ":") {
addr = addr + ":80"
}
host, strport, err := net.SplitHostPort(addr)
if err != nil {
return false
}
port, err := strconv.Atoi(strport)
if err != nil {
return false
}
return (whitelist == nil || whitelist.Can(action, host, port)) &&
(blacklist == nil || !blacklist.Can(action, host, port))
} | [
"func",
"Can",
"(",
"action",
"string",
",",
"addr",
"string",
",",
"whitelist",
",",
"blacklist",
"*",
"Permissions",
")",
"bool",
"{",
"if",
"!",
"strings",
".",
"Contains",
"(",
"addr",
",",
"\"",
"\"",
")",
"{",
"addr",
"=",
"addr",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"host",
",",
"strport",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"addr",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"port",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"strport",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"(",
"whitelist",
"==",
"nil",
"||",
"whitelist",
".",
"Can",
"(",
"action",
",",
"host",
",",
"port",
")",
")",
"&&",
"(",
"blacklist",
"==",
"nil",
"||",
"!",
"blacklist",
".",
"Can",
"(",
"action",
",",
"host",
",",
"port",
")",
")",
"\n",
"}"
] | // Can tests whether the given action and address is allowed by the whitelist and blacklist. | [
"Can",
"tests",
"whether",
"the",
"given",
"action",
"and",
"address",
"is",
"allowed",
"by",
"the",
"whitelist",
"and",
"blacklist",
"."
] | 49f2ee612a5ecd7a07d6731cf241a91a702885b7 | https://github.com/ginuerzh/gost/blob/49f2ee612a5ecd7a07d6731cf241a91a702885b7/permissions.go#L205-L223 |
160,317 | jmoiron/sqlx | sqlx.go | mapper | func mapper() *reflectx.Mapper {
mprMu.Lock()
defer mprMu.Unlock()
if mpr == nil {
mpr = reflectx.NewMapperFunc("db", NameMapper)
} else if origMapper != reflect.ValueOf(NameMapper) {
// if NameMapper has changed, create a new mapper
mpr = reflectx.NewMapperFunc("db", NameMapper)
origMapper = reflect.ValueOf(NameMapper)
}
return mpr
} | go | func mapper() *reflectx.Mapper {
mprMu.Lock()
defer mprMu.Unlock()
if mpr == nil {
mpr = reflectx.NewMapperFunc("db", NameMapper)
} else if origMapper != reflect.ValueOf(NameMapper) {
// if NameMapper has changed, create a new mapper
mpr = reflectx.NewMapperFunc("db", NameMapper)
origMapper = reflect.ValueOf(NameMapper)
}
return mpr
} | [
"func",
"mapper",
"(",
")",
"*",
"reflectx",
".",
"Mapper",
"{",
"mprMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"mprMu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"mpr",
"==",
"nil",
"{",
"mpr",
"=",
"reflectx",
".",
"NewMapperFunc",
"(",
"\"",
"\"",
",",
"NameMapper",
")",
"\n",
"}",
"else",
"if",
"origMapper",
"!=",
"reflect",
".",
"ValueOf",
"(",
"NameMapper",
")",
"{",
"// if NameMapper has changed, create a new mapper",
"mpr",
"=",
"reflectx",
".",
"NewMapperFunc",
"(",
"\"",
"\"",
",",
"NameMapper",
")",
"\n",
"origMapper",
"=",
"reflect",
".",
"ValueOf",
"(",
"NameMapper",
")",
"\n",
"}",
"\n",
"return",
"mpr",
"\n",
"}"
] | // mapper returns a valid mapper using the configured NameMapper func. | [
"mapper",
"returns",
"a",
"valid",
"mapper",
"using",
"the",
"configured",
"NameMapper",
"func",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L38-L50 |
160,318 | jmoiron/sqlx | sqlx.go | isUnsafe | func isUnsafe(i interface{}) bool {
switch v := i.(type) {
case Row:
return v.unsafe
case *Row:
return v.unsafe
case Rows:
return v.unsafe
case *Rows:
return v.unsafe
case NamedStmt:
return v.Stmt.unsafe
case *NamedStmt:
return v.Stmt.unsafe
case Stmt:
return v.unsafe
case *Stmt:
return v.unsafe
case qStmt:
return v.unsafe
case *qStmt:
return v.unsafe
case DB:
return v.unsafe
case *DB:
return v.unsafe
case Tx:
return v.unsafe
case *Tx:
return v.unsafe
case sql.Rows, *sql.Rows:
return false
default:
return false
}
} | go | func isUnsafe(i interface{}) bool {
switch v := i.(type) {
case Row:
return v.unsafe
case *Row:
return v.unsafe
case Rows:
return v.unsafe
case *Rows:
return v.unsafe
case NamedStmt:
return v.Stmt.unsafe
case *NamedStmt:
return v.Stmt.unsafe
case Stmt:
return v.unsafe
case *Stmt:
return v.unsafe
case qStmt:
return v.unsafe
case *qStmt:
return v.unsafe
case DB:
return v.unsafe
case *DB:
return v.unsafe
case Tx:
return v.unsafe
case *Tx:
return v.unsafe
case sql.Rows, *sql.Rows:
return false
default:
return false
}
} | [
"func",
"isUnsafe",
"(",
"i",
"interface",
"{",
"}",
")",
"bool",
"{",
"switch",
"v",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"Row",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"*",
"Row",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"Rows",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"*",
"Rows",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"NamedStmt",
":",
"return",
"v",
".",
"Stmt",
".",
"unsafe",
"\n",
"case",
"*",
"NamedStmt",
":",
"return",
"v",
".",
"Stmt",
".",
"unsafe",
"\n",
"case",
"Stmt",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"*",
"Stmt",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"qStmt",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"*",
"qStmt",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"DB",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"*",
"DB",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"Tx",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"*",
"Tx",
":",
"return",
"v",
".",
"unsafe",
"\n",
"case",
"sql",
".",
"Rows",
",",
"*",
"sql",
".",
"Rows",
":",
"return",
"false",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // determine if any of our extensions are unsafe | [
"determine",
"if",
"any",
"of",
"our",
"extensions",
"are",
"unsafe"
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L114-L149 |
160,319 | jmoiron/sqlx | sqlx.go | MapperFunc | func (db *DB) MapperFunc(mf func(string) string) {
db.Mapper = reflectx.NewMapperFunc("db", mf)
} | go | func (db *DB) MapperFunc(mf func(string) string) {
db.Mapper = reflectx.NewMapperFunc("db", mf)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"MapperFunc",
"(",
"mf",
"func",
"(",
"string",
")",
"string",
")",
"{",
"db",
".",
"Mapper",
"=",
"reflectx",
".",
"NewMapperFunc",
"(",
"\"",
"\"",
",",
"mf",
")",
"\n",
"}"
] | // MapperFunc sets a new mapper for this db using the default sqlx struct tag
// and the provided mapper function. | [
"MapperFunc",
"sets",
"a",
"new",
"mapper",
"for",
"this",
"db",
"using",
"the",
"default",
"sqlx",
"struct",
"tag",
"and",
"the",
"provided",
"mapper",
"function",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L284-L286 |
160,320 | jmoiron/sqlx | sqlx.go | Rebind | func (db *DB) Rebind(query string) string {
return Rebind(BindType(db.driverName), query)
} | go | func (db *DB) Rebind(query string) string {
return Rebind(BindType(db.driverName), query)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Rebind",
"(",
"query",
"string",
")",
"string",
"{",
"return",
"Rebind",
"(",
"BindType",
"(",
"db",
".",
"driverName",
")",
",",
"query",
")",
"\n",
"}"
] | // Rebind transforms a query from QUESTION to the DB driver's bindvar type. | [
"Rebind",
"transforms",
"a",
"query",
"from",
"QUESTION",
"to",
"the",
"DB",
"driver",
"s",
"bindvar",
"type",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L289-L291 |
160,321 | jmoiron/sqlx | sqlx.go | Unsafe | func (db *DB) Unsafe() *DB {
return &DB{DB: db.DB, driverName: db.driverName, unsafe: true, Mapper: db.Mapper}
} | go | func (db *DB) Unsafe() *DB {
return &DB{DB: db.DB, driverName: db.driverName, unsafe: true, Mapper: db.Mapper}
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Unsafe",
"(",
")",
"*",
"DB",
"{",
"return",
"&",
"DB",
"{",
"DB",
":",
"db",
".",
"DB",
",",
"driverName",
":",
"db",
".",
"driverName",
",",
"unsafe",
":",
"true",
",",
"Mapper",
":",
"db",
".",
"Mapper",
"}",
"\n",
"}"
] | // Unsafe returns a version of DB which will silently succeed to scan when
// columns in the SQL result have no fields in the destination struct.
// sqlx.Stmt and sqlx.Tx which are created from this DB will inherit its
// safety behavior. | [
"Unsafe",
"returns",
"a",
"version",
"of",
"DB",
"which",
"will",
"silently",
"succeed",
"to",
"scan",
"when",
"columns",
"in",
"the",
"SQL",
"result",
"have",
"no",
"fields",
"in",
"the",
"destination",
"struct",
".",
"sqlx",
".",
"Stmt",
"and",
"sqlx",
".",
"Tx",
"which",
"are",
"created",
"from",
"this",
"DB",
"will",
"inherit",
"its",
"safety",
"behavior",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L297-L299 |
160,322 | jmoiron/sqlx | sqlx.go | BindNamed | func (db *DB) BindNamed(query string, arg interface{}) (string, []interface{}, error) {
return bindNamedMapper(BindType(db.driverName), query, arg, db.Mapper)
} | go | func (db *DB) BindNamed(query string, arg interface{}) (string, []interface{}, error) {
return bindNamedMapper(BindType(db.driverName), query, arg, db.Mapper)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"BindNamed",
"(",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"bindNamedMapper",
"(",
"BindType",
"(",
"db",
".",
"driverName",
")",
",",
"query",
",",
"arg",
",",
"db",
".",
"Mapper",
")",
"\n",
"}"
] | // BindNamed binds a query using the DB driver's bindvar type. | [
"BindNamed",
"binds",
"a",
"query",
"using",
"the",
"DB",
"driver",
"s",
"bindvar",
"type",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L302-L304 |
160,323 | jmoiron/sqlx | sqlx.go | NamedQuery | func (db *DB) NamedQuery(query string, arg interface{}) (*Rows, error) {
return NamedQuery(db, query, arg)
} | go | func (db *DB) NamedQuery(query string, arg interface{}) (*Rows, error) {
return NamedQuery(db, query, arg)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"NamedQuery",
"(",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"return",
"NamedQuery",
"(",
"db",
",",
"query",
",",
"arg",
")",
"\n",
"}"
] | // NamedQuery using this DB.
// Any named placeholder parameters are replaced with fields from arg. | [
"NamedQuery",
"using",
"this",
"DB",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L308-L310 |
160,324 | jmoiron/sqlx | sqlx.go | NamedExec | func (db *DB) NamedExec(query string, arg interface{}) (sql.Result, error) {
return NamedExec(db, query, arg)
} | go | func (db *DB) NamedExec(query string, arg interface{}) (sql.Result, error) {
return NamedExec(db, query, arg)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"NamedExec",
"(",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"sql",
".",
"Result",
",",
"error",
")",
"{",
"return",
"NamedExec",
"(",
"db",
",",
"query",
",",
"arg",
")",
"\n",
"}"
] | // NamedExec using this DB.
// Any named placeholder parameters are replaced with fields from arg. | [
"NamedExec",
"using",
"this",
"DB",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L314-L316 |
160,325 | jmoiron/sqlx | sqlx.go | Select | func (db *DB) Select(dest interface{}, query string, args ...interface{}) error {
return Select(db, dest, query, args...)
} | go | func (db *DB) Select(dest interface{}, query string, args ...interface{}) error {
return Select(db, dest, query, args...)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Select",
"(",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Select",
"(",
"db",
",",
"dest",
",",
"query",
",",
"args",
"...",
")",
"\n",
"}"
] | // Select using this DB.
// Any placeholder parameters are replaced with supplied args. | [
"Select",
"using",
"this",
"DB",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L320-L322 |
160,326 | jmoiron/sqlx | sqlx.go | Get | func (db *DB) Get(dest interface{}, query string, args ...interface{}) error {
return Get(db, dest, query, args...)
} | go | func (db *DB) Get(dest interface{}, query string, args ...interface{}) error {
return Get(db, dest, query, args...)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Get",
"(",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Get",
"(",
"db",
",",
"dest",
",",
"query",
",",
"args",
"...",
")",
"\n",
"}"
] | // Get using this DB.
// Any placeholder parameters are replaced with supplied args.
// An error is returned if the result set is empty. | [
"Get",
"using",
"this",
"DB",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"result",
"set",
"is",
"empty",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L327-L329 |
160,327 | jmoiron/sqlx | sqlx.go | Preparex | func (db *DB) Preparex(query string) (*Stmt, error) {
return Preparex(db, query)
} | go | func (db *DB) Preparex(query string) (*Stmt, error) {
return Preparex(db, query)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Preparex",
"(",
"query",
"string",
")",
"(",
"*",
"Stmt",
",",
"error",
")",
"{",
"return",
"Preparex",
"(",
"db",
",",
"query",
")",
"\n",
"}"
] | // Preparex returns an sqlx.Stmt instead of a sql.Stmt | [
"Preparex",
"returns",
"an",
"sqlx",
".",
"Stmt",
"instead",
"of",
"a",
"sql",
".",
"Stmt"
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L374-L376 |
160,328 | jmoiron/sqlx | sqlx.go | Rebind | func (tx *Tx) Rebind(query string) string {
return Rebind(BindType(tx.driverName), query)
} | go | func (tx *Tx) Rebind(query string) string {
return Rebind(BindType(tx.driverName), query)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Rebind",
"(",
"query",
"string",
")",
"string",
"{",
"return",
"Rebind",
"(",
"BindType",
"(",
"tx",
".",
"driverName",
")",
",",
"query",
")",
"\n",
"}"
] | // Rebind a query within a transaction's bindvar type. | [
"Rebind",
"a",
"query",
"within",
"a",
"transaction",
"s",
"bindvar",
"type",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L397-L399 |
160,329 | jmoiron/sqlx | sqlx.go | Unsafe | func (tx *Tx) Unsafe() *Tx {
return &Tx{Tx: tx.Tx, driverName: tx.driverName, unsafe: true, Mapper: tx.Mapper}
} | go | func (tx *Tx) Unsafe() *Tx {
return &Tx{Tx: tx.Tx, driverName: tx.driverName, unsafe: true, Mapper: tx.Mapper}
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Unsafe",
"(",
")",
"*",
"Tx",
"{",
"return",
"&",
"Tx",
"{",
"Tx",
":",
"tx",
".",
"Tx",
",",
"driverName",
":",
"tx",
".",
"driverName",
",",
"unsafe",
":",
"true",
",",
"Mapper",
":",
"tx",
".",
"Mapper",
"}",
"\n",
"}"
] | // Unsafe returns a version of Tx which will silently succeed to scan when
// columns in the SQL result have no fields in the destination struct. | [
"Unsafe",
"returns",
"a",
"version",
"of",
"Tx",
"which",
"will",
"silently",
"succeed",
"to",
"scan",
"when",
"columns",
"in",
"the",
"SQL",
"result",
"have",
"no",
"fields",
"in",
"the",
"destination",
"struct",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L403-L405 |
160,330 | jmoiron/sqlx | sqlx.go | BindNamed | func (tx *Tx) BindNamed(query string, arg interface{}) (string, []interface{}, error) {
return bindNamedMapper(BindType(tx.driverName), query, arg, tx.Mapper)
} | go | func (tx *Tx) BindNamed(query string, arg interface{}) (string, []interface{}, error) {
return bindNamedMapper(BindType(tx.driverName), query, arg, tx.Mapper)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"BindNamed",
"(",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"return",
"bindNamedMapper",
"(",
"BindType",
"(",
"tx",
".",
"driverName",
")",
",",
"query",
",",
"arg",
",",
"tx",
".",
"Mapper",
")",
"\n",
"}"
] | // BindNamed binds a query within a transaction's bindvar type. | [
"BindNamed",
"binds",
"a",
"query",
"within",
"a",
"transaction",
"s",
"bindvar",
"type",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L408-L410 |
160,331 | jmoiron/sqlx | sqlx.go | NamedQuery | func (tx *Tx) NamedQuery(query string, arg interface{}) (*Rows, error) {
return NamedQuery(tx, query, arg)
} | go | func (tx *Tx) NamedQuery(query string, arg interface{}) (*Rows, error) {
return NamedQuery(tx, query, arg)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"NamedQuery",
"(",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"return",
"NamedQuery",
"(",
"tx",
",",
"query",
",",
"arg",
")",
"\n",
"}"
] | // NamedQuery within a transaction.
// Any named placeholder parameters are replaced with fields from arg. | [
"NamedQuery",
"within",
"a",
"transaction",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L414-L416 |
160,332 | jmoiron/sqlx | sqlx.go | NamedExec | func (tx *Tx) NamedExec(query string, arg interface{}) (sql.Result, error) {
return NamedExec(tx, query, arg)
} | go | func (tx *Tx) NamedExec(query string, arg interface{}) (sql.Result, error) {
return NamedExec(tx, query, arg)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"NamedExec",
"(",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"sql",
".",
"Result",
",",
"error",
")",
"{",
"return",
"NamedExec",
"(",
"tx",
",",
"query",
",",
"arg",
")",
"\n",
"}"
] | // NamedExec a named query within a transaction.
// Any named placeholder parameters are replaced with fields from arg. | [
"NamedExec",
"a",
"named",
"query",
"within",
"a",
"transaction",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L420-L422 |
160,333 | jmoiron/sqlx | sqlx.go | Select | func (tx *Tx) Select(dest interface{}, query string, args ...interface{}) error {
return Select(tx, dest, query, args...)
} | go | func (tx *Tx) Select(dest interface{}, query string, args ...interface{}) error {
return Select(tx, dest, query, args...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Select",
"(",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Select",
"(",
"tx",
",",
"dest",
",",
"query",
",",
"args",
"...",
")",
"\n",
"}"
] | // Select within a transaction.
// Any placeholder parameters are replaced with supplied args. | [
"Select",
"within",
"a",
"transaction",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L426-L428 |
160,334 | jmoiron/sqlx | sqlx.go | Queryx | func (tx *Tx) Queryx(query string, args ...interface{}) (*Rows, error) {
r, err := tx.Tx.Query(query, args...)
if err != nil {
return nil, err
}
return &Rows{Rows: r, unsafe: tx.unsafe, Mapper: tx.Mapper}, err
} | go | func (tx *Tx) Queryx(query string, args ...interface{}) (*Rows, error) {
r, err := tx.Tx.Query(query, args...)
if err != nil {
return nil, err
}
return &Rows{Rows: r, unsafe: tx.unsafe, Mapper: tx.Mapper}, err
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Queryx",
"(",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"tx",
".",
"Tx",
".",
"Query",
"(",
"query",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Rows",
"{",
"Rows",
":",
"r",
",",
"unsafe",
":",
"tx",
".",
"unsafe",
",",
"Mapper",
":",
"tx",
".",
"Mapper",
"}",
",",
"err",
"\n",
"}"
] | // Queryx within a transaction.
// Any placeholder parameters are replaced with supplied args. | [
"Queryx",
"within",
"a",
"transaction",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L432-L438 |
160,335 | jmoiron/sqlx | sqlx.go | QueryRowx | func (tx *Tx) QueryRowx(query string, args ...interface{}) *Row {
rows, err := tx.Tx.Query(query, args...)
return &Row{rows: rows, err: err, unsafe: tx.unsafe, Mapper: tx.Mapper}
} | go | func (tx *Tx) QueryRowx(query string, args ...interface{}) *Row {
rows, err := tx.Tx.Query(query, args...)
return &Row{rows: rows, err: err, unsafe: tx.unsafe, Mapper: tx.Mapper}
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"QueryRowx",
"(",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Row",
"{",
"rows",
",",
"err",
":=",
"tx",
".",
"Tx",
".",
"Query",
"(",
"query",
",",
"args",
"...",
")",
"\n",
"return",
"&",
"Row",
"{",
"rows",
":",
"rows",
",",
"err",
":",
"err",
",",
"unsafe",
":",
"tx",
".",
"unsafe",
",",
"Mapper",
":",
"tx",
".",
"Mapper",
"}",
"\n",
"}"
] | // QueryRowx within a transaction.
// Any placeholder parameters are replaced with supplied args. | [
"QueryRowx",
"within",
"a",
"transaction",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L442-L445 |
160,336 | jmoiron/sqlx | sqlx.go | Get | func (tx *Tx) Get(dest interface{}, query string, args ...interface{}) error {
return Get(tx, dest, query, args...)
} | go | func (tx *Tx) Get(dest interface{}, query string, args ...interface{}) error {
return Get(tx, dest, query, args...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Get",
"(",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Get",
"(",
"tx",
",",
"dest",
",",
"query",
",",
"args",
"...",
")",
"\n",
"}"
] | // Get within a transaction.
// Any placeholder parameters are replaced with supplied args.
// An error is returned if the result set is empty. | [
"Get",
"within",
"a",
"transaction",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"result",
"set",
"is",
"empty",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L450-L452 |
160,337 | jmoiron/sqlx | sqlx.go | MustExec | func (tx *Tx) MustExec(query string, args ...interface{}) sql.Result {
return MustExec(tx, query, args...)
} | go | func (tx *Tx) MustExec(query string, args ...interface{}) sql.Result {
return MustExec(tx, query, args...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"MustExec",
"(",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"sql",
".",
"Result",
"{",
"return",
"MustExec",
"(",
"tx",
",",
"query",
",",
"args",
"...",
")",
"\n",
"}"
] | // MustExec runs MustExec within a transaction.
// Any placeholder parameters are replaced with supplied args. | [
"MustExec",
"runs",
"MustExec",
"within",
"a",
"transaction",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L456-L458 |
160,338 | jmoiron/sqlx | sqlx.go | Preparex | func (tx *Tx) Preparex(query string) (*Stmt, error) {
return Preparex(tx, query)
} | go | func (tx *Tx) Preparex(query string) (*Stmt, error) {
return Preparex(tx, query)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Preparex",
"(",
"query",
"string",
")",
"(",
"*",
"Stmt",
",",
"error",
")",
"{",
"return",
"Preparex",
"(",
"tx",
",",
"query",
")",
"\n",
"}"
] | // Preparex a statement within a transaction. | [
"Preparex",
"a",
"statement",
"within",
"a",
"transaction",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L461-L463 |
160,339 | jmoiron/sqlx | sqlx.go | NamedStmt | func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt {
return &NamedStmt{
QueryString: stmt.QueryString,
Params: stmt.Params,
Stmt: tx.Stmtx(stmt.Stmt),
}
} | go | func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt {
return &NamedStmt{
QueryString: stmt.QueryString,
Params: stmt.Params,
Stmt: tx.Stmtx(stmt.Stmt),
}
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"NamedStmt",
"(",
"stmt",
"*",
"NamedStmt",
")",
"*",
"NamedStmt",
"{",
"return",
"&",
"NamedStmt",
"{",
"QueryString",
":",
"stmt",
".",
"QueryString",
",",
"Params",
":",
"stmt",
".",
"Params",
",",
"Stmt",
":",
"tx",
".",
"Stmtx",
"(",
"stmt",
".",
"Stmt",
")",
",",
"}",
"\n",
"}"
] | // NamedStmt returns a version of the prepared statement which runs within a transaction. | [
"NamedStmt",
"returns",
"a",
"version",
"of",
"the",
"prepared",
"statement",
"which",
"runs",
"within",
"a",
"transaction",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L483-L489 |
160,340 | jmoiron/sqlx | sqlx.go | Unsafe | func (s *Stmt) Unsafe() *Stmt {
return &Stmt{Stmt: s.Stmt, unsafe: true, Mapper: s.Mapper}
} | go | func (s *Stmt) Unsafe() *Stmt {
return &Stmt{Stmt: s.Stmt, unsafe: true, Mapper: s.Mapper}
} | [
"func",
"(",
"s",
"*",
"Stmt",
")",
"Unsafe",
"(",
")",
"*",
"Stmt",
"{",
"return",
"&",
"Stmt",
"{",
"Stmt",
":",
"s",
".",
"Stmt",
",",
"unsafe",
":",
"true",
",",
"Mapper",
":",
"s",
".",
"Mapper",
"}",
"\n",
"}"
] | // Unsafe returns a version of Stmt which will silently succeed to scan when
// columns in the SQL result have no fields in the destination struct. | [
"Unsafe",
"returns",
"a",
"version",
"of",
"Stmt",
"which",
"will",
"silently",
"succeed",
"to",
"scan",
"when",
"columns",
"in",
"the",
"SQL",
"result",
"have",
"no",
"fields",
"in",
"the",
"destination",
"struct",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L505-L507 |
160,341 | jmoiron/sqlx | sqlx.go | Select | func (s *Stmt) Select(dest interface{}, args ...interface{}) error {
return Select(&qStmt{s}, dest, "", args...)
} | go | func (s *Stmt) Select(dest interface{}, args ...interface{}) error {
return Select(&qStmt{s}, dest, "", args...)
} | [
"func",
"(",
"s",
"*",
"Stmt",
")",
"Select",
"(",
"dest",
"interface",
"{",
"}",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Select",
"(",
"&",
"qStmt",
"{",
"s",
"}",
",",
"dest",
",",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"}"
] | // Select using the prepared statement.
// Any placeholder parameters are replaced with supplied args. | [
"Select",
"using",
"the",
"prepared",
"statement",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L511-L513 |
160,342 | jmoiron/sqlx | sqlx.go | Get | func (s *Stmt) Get(dest interface{}, args ...interface{}) error {
return Get(&qStmt{s}, dest, "", args...)
} | go | func (s *Stmt) Get(dest interface{}, args ...interface{}) error {
return Get(&qStmt{s}, dest, "", args...)
} | [
"func",
"(",
"s",
"*",
"Stmt",
")",
"Get",
"(",
"dest",
"interface",
"{",
"}",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"Get",
"(",
"&",
"qStmt",
"{",
"s",
"}",
",",
"dest",
",",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"}"
] | // Get using the prepared statement.
// Any placeholder parameters are replaced with supplied args.
// An error is returned if the result set is empty. | [
"Get",
"using",
"the",
"prepared",
"statement",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"result",
"set",
"is",
"empty",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L518-L520 |
160,343 | jmoiron/sqlx | sqlx.go | QueryRowx | func (s *Stmt) QueryRowx(args ...interface{}) *Row {
qs := &qStmt{s}
return qs.QueryRowx("", args...)
} | go | func (s *Stmt) QueryRowx(args ...interface{}) *Row {
qs := &qStmt{s}
return qs.QueryRowx("", args...)
} | [
"func",
"(",
"s",
"*",
"Stmt",
")",
"QueryRowx",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Row",
"{",
"qs",
":=",
"&",
"qStmt",
"{",
"s",
"}",
"\n",
"return",
"qs",
".",
"QueryRowx",
"(",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"}"
] | // QueryRowx using this statement.
// Any placeholder parameters are replaced with supplied args. | [
"QueryRowx",
"using",
"this",
"statement",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L531-L534 |
160,344 | jmoiron/sqlx | sqlx.go | Queryx | func (s *Stmt) Queryx(args ...interface{}) (*Rows, error) {
qs := &qStmt{s}
return qs.Queryx("", args...)
} | go | func (s *Stmt) Queryx(args ...interface{}) (*Rows, error) {
qs := &qStmt{s}
return qs.Queryx("", args...)
} | [
"func",
"(",
"s",
"*",
"Stmt",
")",
"Queryx",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"qs",
":=",
"&",
"qStmt",
"{",
"s",
"}",
"\n",
"return",
"qs",
".",
"Queryx",
"(",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"}"
] | // Queryx using this statement.
// Any placeholder parameters are replaced with supplied args. | [
"Queryx",
"using",
"this",
"statement",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L538-L541 |
160,345 | jmoiron/sqlx | sqlx.go | Connect | func Connect(driverName, dataSourceName string) (*DB, error) {
db, err := Open(driverName, dataSourceName)
if err != nil {
return nil, err
}
err = db.Ping()
if err != nil {
db.Close()
return nil, err
}
return db, nil
} | go | func Connect(driverName, dataSourceName string) (*DB, error) {
db, err := Open(driverName, dataSourceName)
if err != nil {
return nil, err
}
err = db.Ping()
if err != nil {
db.Close()
return nil, err
}
return db, nil
} | [
"func",
"Connect",
"(",
"driverName",
",",
"dataSourceName",
"string",
")",
"(",
"*",
"DB",
",",
"error",
")",
"{",
"db",
",",
"err",
":=",
"Open",
"(",
"driverName",
",",
"dataSourceName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"db",
".",
"Ping",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"db",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"db",
",",
"nil",
"\n",
"}"
] | // Connect to a database and verify with a ping. | [
"Connect",
"to",
"a",
"database",
"and",
"verify",
"with",
"a",
"ping",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L633-L644 |
160,346 | jmoiron/sqlx | sqlx.go | MustConnect | func MustConnect(driverName, dataSourceName string) *DB {
db, err := Connect(driverName, dataSourceName)
if err != nil {
panic(err)
}
return db
} | go | func MustConnect(driverName, dataSourceName string) *DB {
db, err := Connect(driverName, dataSourceName)
if err != nil {
panic(err)
}
return db
} | [
"func",
"MustConnect",
"(",
"driverName",
",",
"dataSourceName",
"string",
")",
"*",
"DB",
"{",
"db",
",",
"err",
":=",
"Connect",
"(",
"driverName",
",",
"dataSourceName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"db",
"\n",
"}"
] | // MustConnect connects to a database and panics on error. | [
"MustConnect",
"connects",
"to",
"a",
"database",
"and",
"panics",
"on",
"error",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L647-L653 |
160,347 | jmoiron/sqlx | sqlx.go | Preparex | func Preparex(p Preparer, query string) (*Stmt, error) {
s, err := p.Prepare(query)
if err != nil {
return nil, err
}
return &Stmt{Stmt: s, unsafe: isUnsafe(p), Mapper: mapperFor(p)}, err
} | go | func Preparex(p Preparer, query string) (*Stmt, error) {
s, err := p.Prepare(query)
if err != nil {
return nil, err
}
return &Stmt{Stmt: s, unsafe: isUnsafe(p), Mapper: mapperFor(p)}, err
} | [
"func",
"Preparex",
"(",
"p",
"Preparer",
",",
"query",
"string",
")",
"(",
"*",
"Stmt",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"p",
".",
"Prepare",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Stmt",
"{",
"Stmt",
":",
"s",
",",
"unsafe",
":",
"isUnsafe",
"(",
"p",
")",
",",
"Mapper",
":",
"mapperFor",
"(",
"p",
")",
"}",
",",
"err",
"\n",
"}"
] | // Preparex prepares a statement. | [
"Preparex",
"prepares",
"a",
"statement",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L656-L662 |
160,348 | jmoiron/sqlx | sqlx.go | Get | func Get(q Queryer, dest interface{}, query string, args ...interface{}) error {
r := q.QueryRowx(query, args...)
return r.scanAny(dest, false)
} | go | func Get(q Queryer, dest interface{}, query string, args ...interface{}) error {
r := q.QueryRowx(query, args...)
return r.scanAny(dest, false)
} | [
"func",
"Get",
"(",
"q",
"Queryer",
",",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"r",
":=",
"q",
".",
"QueryRowx",
"(",
"query",
",",
"args",
"...",
")",
"\n",
"return",
"r",
".",
"scanAny",
"(",
"dest",
",",
"false",
")",
"\n",
"}"
] | // Get does a QueryRow using the provided Queryer, and scans the resulting row
// to dest. If dest is scannable, the result must only have one column. Otherwise,
// StructScan is used. Get will return sql.ErrNoRows like row.Scan would.
// Any placeholder parameters are replaced with supplied args.
// An error is returned if the result set is empty. | [
"Get",
"does",
"a",
"QueryRow",
"using",
"the",
"provided",
"Queryer",
"and",
"scans",
"the",
"resulting",
"row",
"to",
"dest",
".",
"If",
"dest",
"is",
"scannable",
"the",
"result",
"must",
"only",
"have",
"one",
"column",
".",
"Otherwise",
"StructScan",
"is",
"used",
".",
"Get",
"will",
"return",
"sql",
".",
"ErrNoRows",
"like",
"row",
".",
"Scan",
"would",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"result",
"set",
"is",
"empty",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L684-L687 |
160,349 | jmoiron/sqlx | sqlx.go | MustExec | func MustExec(e Execer, query string, args ...interface{}) sql.Result {
res, err := e.Exec(query, args...)
if err != nil {
panic(err)
}
return res
} | go | func MustExec(e Execer, query string, args ...interface{}) sql.Result {
res, err := e.Exec(query, args...)
if err != nil {
panic(err)
}
return res
} | [
"func",
"MustExec",
"(",
"e",
"Execer",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"sql",
".",
"Result",
"{",
"res",
",",
"err",
":=",
"e",
".",
"Exec",
"(",
"query",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // MustExec execs the query using e and panics if there was an error.
// Any placeholder parameters are replaced with supplied args. | [
"MustExec",
"execs",
"the",
"query",
"using",
"e",
"and",
"panics",
"if",
"there",
"was",
"an",
"error",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx.go#L715-L721 |
160,350 | jmoiron/sqlx | named_context.go | ExecContext | func (n *NamedStmt) ExecContext(ctx context.Context, arg interface{}) (sql.Result, error) {
args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
if err != nil {
return *new(sql.Result), err
}
return n.Stmt.ExecContext(ctx, args...)
} | go | func (n *NamedStmt) ExecContext(ctx context.Context, arg interface{}) (sql.Result, error) {
args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
if err != nil {
return *new(sql.Result), err
}
return n.Stmt.ExecContext(ctx, args...)
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"ExecContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"sql",
".",
"Result",
",",
"error",
")",
"{",
"args",
",",
"err",
":=",
"bindAnyArgs",
"(",
"n",
".",
"Params",
",",
"arg",
",",
"n",
".",
"Stmt",
".",
"Mapper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"*",
"new",
"(",
"sql",
".",
"Result",
")",
",",
"err",
"\n",
"}",
"\n",
"return",
"n",
".",
"Stmt",
".",
"ExecContext",
"(",
"ctx",
",",
"args",
"...",
")",
"\n",
"}"
] | // ExecContext executes a named statement using the struct passed.
// Any named placeholder parameters are replaced with fields from arg. | [
"ExecContext",
"executes",
"a",
"named",
"statement",
"using",
"the",
"struct",
"passed",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named_context.go#L36-L42 |
160,351 | jmoiron/sqlx | named_context.go | QueryContext | func (n *NamedStmt) QueryContext(ctx context.Context, arg interface{}) (*sql.Rows, error) {
args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
if err != nil {
return nil, err
}
return n.Stmt.QueryContext(ctx, args...)
} | go | func (n *NamedStmt) QueryContext(ctx context.Context, arg interface{}) (*sql.Rows, error) {
args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
if err != nil {
return nil, err
}
return n.Stmt.QueryContext(ctx, args...)
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"QueryContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"*",
"sql",
".",
"Rows",
",",
"error",
")",
"{",
"args",
",",
"err",
":=",
"bindAnyArgs",
"(",
"n",
".",
"Params",
",",
"arg",
",",
"n",
".",
"Stmt",
".",
"Mapper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"n",
".",
"Stmt",
".",
"QueryContext",
"(",
"ctx",
",",
"args",
"...",
")",
"\n",
"}"
] | // QueryContext executes a named statement using the struct argument, returning rows.
// Any named placeholder parameters are replaced with fields from arg. | [
"QueryContext",
"executes",
"a",
"named",
"statement",
"using",
"the",
"struct",
"argument",
"returning",
"rows",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named_context.go#L46-L52 |
160,352 | jmoiron/sqlx | named_context.go | MustExecContext | func (n *NamedStmt) MustExecContext(ctx context.Context, arg interface{}) sql.Result {
res, err := n.ExecContext(ctx, arg)
if err != nil {
panic(err)
}
return res
} | go | func (n *NamedStmt) MustExecContext(ctx context.Context, arg interface{}) sql.Result {
res, err := n.ExecContext(ctx, arg)
if err != nil {
panic(err)
}
return res
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"MustExecContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"arg",
"interface",
"{",
"}",
")",
"sql",
".",
"Result",
"{",
"res",
",",
"err",
":=",
"n",
".",
"ExecContext",
"(",
"ctx",
",",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // MustExecContext execs a NamedStmt, panicing on error
// Any named placeholder parameters are replaced with fields from arg. | [
"MustExecContext",
"execs",
"a",
"NamedStmt",
"panicing",
"on",
"error",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named_context.go#L68-L74 |
160,353 | jmoiron/sqlx | named_context.go | QueryxContext | func (n *NamedStmt) QueryxContext(ctx context.Context, arg interface{}) (*Rows, error) {
r, err := n.QueryContext(ctx, arg)
if err != nil {
return nil, err
}
return &Rows{Rows: r, Mapper: n.Stmt.Mapper, unsafe: isUnsafe(n)}, err
} | go | func (n *NamedStmt) QueryxContext(ctx context.Context, arg interface{}) (*Rows, error) {
r, err := n.QueryContext(ctx, arg)
if err != nil {
return nil, err
}
return &Rows{Rows: r, Mapper: n.Stmt.Mapper, unsafe: isUnsafe(n)}, err
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"QueryxContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"n",
".",
"QueryContext",
"(",
"ctx",
",",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Rows",
"{",
"Rows",
":",
"r",
",",
"Mapper",
":",
"n",
".",
"Stmt",
".",
"Mapper",
",",
"unsafe",
":",
"isUnsafe",
"(",
"n",
")",
"}",
",",
"err",
"\n",
"}"
] | // QueryxContext using this NamedStmt
// Any named placeholder parameters are replaced with fields from arg. | [
"QueryxContext",
"using",
"this",
"NamedStmt",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named_context.go#L78-L84 |
160,354 | jmoiron/sqlx | named_context.go | QueryRowxContext | func (n *NamedStmt) QueryRowxContext(ctx context.Context, arg interface{}) *Row {
return n.QueryRowContext(ctx, arg)
} | go | func (n *NamedStmt) QueryRowxContext(ctx context.Context, arg interface{}) *Row {
return n.QueryRowContext(ctx, arg)
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"QueryRowxContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"arg",
"interface",
"{",
"}",
")",
"*",
"Row",
"{",
"return",
"n",
".",
"QueryRowContext",
"(",
"ctx",
",",
"arg",
")",
"\n",
"}"
] | // QueryRowxContext this NamedStmt. Because of limitations with QueryRow, this is
// an alias for QueryRow.
// Any named placeholder parameters are replaced with fields from arg. | [
"QueryRowxContext",
"this",
"NamedStmt",
".",
"Because",
"of",
"limitations",
"with",
"QueryRow",
"this",
"is",
"an",
"alias",
"for",
"QueryRow",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named_context.go#L89-L91 |
160,355 | jmoiron/sqlx | named_context.go | SelectContext | func (n *NamedStmt) SelectContext(ctx context.Context, dest interface{}, arg interface{}) error {
rows, err := n.QueryxContext(ctx, arg)
if err != nil {
return err
}
// if something happens here, we want to make sure the rows are Closed
defer rows.Close()
return scanAll(rows, dest, false)
} | go | func (n *NamedStmt) SelectContext(ctx context.Context, dest interface{}, arg interface{}) error {
rows, err := n.QueryxContext(ctx, arg)
if err != nil {
return err
}
// if something happens here, we want to make sure the rows are Closed
defer rows.Close()
return scanAll(rows, dest, false)
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"SelectContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"dest",
"interface",
"{",
"}",
",",
"arg",
"interface",
"{",
"}",
")",
"error",
"{",
"rows",
",",
"err",
":=",
"n",
".",
"QueryxContext",
"(",
"ctx",
",",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// if something happens here, we want to make sure the rows are Closed",
"defer",
"rows",
".",
"Close",
"(",
")",
"\n",
"return",
"scanAll",
"(",
"rows",
",",
"dest",
",",
"false",
")",
"\n",
"}"
] | // SelectContext using this NamedStmt
// Any named placeholder parameters are replaced with fields from arg. | [
"SelectContext",
"using",
"this",
"NamedStmt",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named_context.go#L95-L103 |
160,356 | jmoiron/sqlx | named_context.go | GetContext | func (n *NamedStmt) GetContext(ctx context.Context, dest interface{}, arg interface{}) error {
r := n.QueryRowxContext(ctx, arg)
return r.scanAny(dest, false)
} | go | func (n *NamedStmt) GetContext(ctx context.Context, dest interface{}, arg interface{}) error {
r := n.QueryRowxContext(ctx, arg)
return r.scanAny(dest, false)
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"GetContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"dest",
"interface",
"{",
"}",
",",
"arg",
"interface",
"{",
"}",
")",
"error",
"{",
"r",
":=",
"n",
".",
"QueryRowxContext",
"(",
"ctx",
",",
"arg",
")",
"\n",
"return",
"r",
".",
"scanAny",
"(",
"dest",
",",
"false",
")",
"\n",
"}"
] | // GetContext using this NamedStmt
// Any named placeholder parameters are replaced with fields from arg. | [
"GetContext",
"using",
"this",
"NamedStmt",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named_context.go#L107-L110 |
160,357 | jmoiron/sqlx | named_context.go | NamedExecContext | func NamedExecContext(ctx context.Context, e ExtContext, query string, arg interface{}) (sql.Result, error) {
q, args, err := bindNamedMapper(BindType(e.DriverName()), query, arg, mapperFor(e))
if err != nil {
return nil, err
}
return e.ExecContext(ctx, q, args...)
} | go | func NamedExecContext(ctx context.Context, e ExtContext, query string, arg interface{}) (sql.Result, error) {
q, args, err := bindNamedMapper(BindType(e.DriverName()), query, arg, mapperFor(e))
if err != nil {
return nil, err
}
return e.ExecContext(ctx, q, args...)
} | [
"func",
"NamedExecContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"e",
"ExtContext",
",",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"sql",
".",
"Result",
",",
"error",
")",
"{",
"q",
",",
"args",
",",
"err",
":=",
"bindNamedMapper",
"(",
"BindType",
"(",
"e",
".",
"DriverName",
"(",
")",
")",
",",
"query",
",",
"arg",
",",
"mapperFor",
"(",
"e",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"e",
".",
"ExecContext",
"(",
"ctx",
",",
"q",
",",
"args",
"...",
")",
"\n",
"}"
] | // NamedExecContext uses BindStruct to get a query executable by the driver and
// then runs Exec on the result. Returns an error from the binding
// or the query execution itself. | [
"NamedExecContext",
"uses",
"BindStruct",
"to",
"get",
"a",
"query",
"executable",
"by",
"the",
"driver",
"and",
"then",
"runs",
"Exec",
"on",
"the",
"result",
".",
"Returns",
"an",
"error",
"from",
"the",
"binding",
"or",
"the",
"query",
"execution",
"itself",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named_context.go#L126-L132 |
160,358 | jmoiron/sqlx | bind.go | BindType | func BindType(driverName string) int {
switch driverName {
case "postgres", "pgx", "pq-timeouts", "cloudsqlpostgres", "ql":
return DOLLAR
case "mysql":
return QUESTION
case "sqlite3":
return QUESTION
case "oci8", "ora", "goracle":
return NAMED
case "sqlserver":
return AT
}
return UNKNOWN
} | go | func BindType(driverName string) int {
switch driverName {
case "postgres", "pgx", "pq-timeouts", "cloudsqlpostgres", "ql":
return DOLLAR
case "mysql":
return QUESTION
case "sqlite3":
return QUESTION
case "oci8", "ora", "goracle":
return NAMED
case "sqlserver":
return AT
}
return UNKNOWN
} | [
"func",
"BindType",
"(",
"driverName",
"string",
")",
"int",
"{",
"switch",
"driverName",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"DOLLAR",
"\n",
"case",
"\"",
"\"",
":",
"return",
"QUESTION",
"\n",
"case",
"\"",
"\"",
":",
"return",
"QUESTION",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"NAMED",
"\n",
"case",
"\"",
"\"",
":",
"return",
"AT",
"\n",
"}",
"\n",
"return",
"UNKNOWN",
"\n",
"}"
] | // BindType returns the bindtype for a given database given a drivername. | [
"BindType",
"returns",
"the",
"bindtype",
"for",
"a",
"given",
"database",
"given",
"a",
"drivername",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/bind.go#L24-L38 |
160,359 | jmoiron/sqlx | bind.go | rebindBuff | func rebindBuff(bindType int, query string) string {
if bindType != DOLLAR {
return query
}
b := make([]byte, 0, len(query))
rqb := bytes.NewBuffer(b)
j := 1
for _, r := range query {
if r == '?' {
rqb.WriteRune('$')
rqb.WriteString(strconv.Itoa(j))
j++
} else {
rqb.WriteRune(r)
}
}
return rqb.String()
} | go | func rebindBuff(bindType int, query string) string {
if bindType != DOLLAR {
return query
}
b := make([]byte, 0, len(query))
rqb := bytes.NewBuffer(b)
j := 1
for _, r := range query {
if r == '?' {
rqb.WriteRune('$')
rqb.WriteString(strconv.Itoa(j))
j++
} else {
rqb.WriteRune(r)
}
}
return rqb.String()
} | [
"func",
"rebindBuff",
"(",
"bindType",
"int",
",",
"query",
"string",
")",
"string",
"{",
"if",
"bindType",
"!=",
"DOLLAR",
"{",
"return",
"query",
"\n",
"}",
"\n\n",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"query",
")",
")",
"\n",
"rqb",
":=",
"bytes",
".",
"NewBuffer",
"(",
"b",
")",
"\n",
"j",
":=",
"1",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"query",
"{",
"if",
"r",
"==",
"'?'",
"{",
"rqb",
".",
"WriteRune",
"(",
"'$'",
")",
"\n",
"rqb",
".",
"WriteString",
"(",
"strconv",
".",
"Itoa",
"(",
"j",
")",
")",
"\n",
"j",
"++",
"\n",
"}",
"else",
"{",
"rqb",
".",
"WriteRune",
"(",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"rqb",
".",
"String",
"(",
")",
"\n",
"}"
] | // Experimental implementation of Rebind which uses a bytes.Buffer. The code is
// much simpler and should be more resistant to odd unicode, but it is twice as
// slow. Kept here for benchmarking purposes and to possibly replace Rebind if
// problems arise with its somewhat naive handling of unicode. | [
"Experimental",
"implementation",
"of",
"Rebind",
"which",
"uses",
"a",
"bytes",
".",
"Buffer",
".",
"The",
"code",
"is",
"much",
"simpler",
"and",
"should",
"be",
"more",
"resistant",
"to",
"odd",
"unicode",
"but",
"it",
"is",
"twice",
"as",
"slow",
".",
"Kept",
"here",
"for",
"benchmarking",
"purposes",
"and",
"to",
"possibly",
"replace",
"Rebind",
"if",
"problems",
"arise",
"with",
"its",
"somewhat",
"naive",
"handling",
"of",
"unicode",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/bind.go#L80-L99 |
160,360 | jmoiron/sqlx | bind.go | In | func In(query string, args ...interface{}) (string, []interface{}, error) {
// argMeta stores reflect.Value and length for slices and
// the value itself for non-slice arguments
type argMeta struct {
v reflect.Value
i interface{}
length int
}
var flatArgsCount int
var anySlices bool
meta := make([]argMeta, len(args))
for i, arg := range args {
if a, ok := arg.(driver.Valuer); ok {
arg, _ = a.Value()
}
v := reflect.ValueOf(arg)
t := reflectx.Deref(v.Type())
// []byte is a driver.Value type so it should not be expanded
if t.Kind() == reflect.Slice && t != reflect.TypeOf([]byte{}) {
meta[i].length = v.Len()
meta[i].v = v
anySlices = true
flatArgsCount += meta[i].length
if meta[i].length == 0 {
return "", nil, errors.New("empty slice passed to 'in' query")
}
} else {
meta[i].i = arg
flatArgsCount++
}
}
// don't do any parsing if there aren't any slices; note that this means
// some errors that we might have caught below will not be returned.
if !anySlices {
return query, args, nil
}
newArgs := make([]interface{}, 0, flatArgsCount)
buf := make([]byte, 0, len(query)+len(", ?")*flatArgsCount)
var arg, offset int
for i := strings.IndexByte(query[offset:], '?'); i != -1; i = strings.IndexByte(query[offset:], '?') {
if arg >= len(meta) {
// if an argument wasn't passed, lets return an error; this is
// not actually how database/sql Exec/Query works, but since we are
// creating an argument list programmatically, we want to be able
// to catch these programmer errors earlier.
return "", nil, errors.New("number of bindVars exceeds arguments")
}
argMeta := meta[arg]
arg++
// not a slice, continue.
// our questionmark will either be written before the next expansion
// of a slice or after the loop when writing the rest of the query
if argMeta.length == 0 {
offset = offset + i + 1
newArgs = append(newArgs, argMeta.i)
continue
}
// write everything up to and including our ? character
buf = append(buf, query[:offset+i+1]...)
for si := 1; si < argMeta.length; si++ {
buf = append(buf, ", ?"...)
}
newArgs = appendReflectSlice(newArgs, argMeta.v, argMeta.length)
// slice the query and reset the offset. this avoids some bookkeeping for
// the write after the loop
query = query[offset+i+1:]
offset = 0
}
buf = append(buf, query...)
if arg < len(meta) {
return "", nil, errors.New("number of bindVars less than number arguments")
}
return string(buf), newArgs, nil
} | go | func In(query string, args ...interface{}) (string, []interface{}, error) {
// argMeta stores reflect.Value and length for slices and
// the value itself for non-slice arguments
type argMeta struct {
v reflect.Value
i interface{}
length int
}
var flatArgsCount int
var anySlices bool
meta := make([]argMeta, len(args))
for i, arg := range args {
if a, ok := arg.(driver.Valuer); ok {
arg, _ = a.Value()
}
v := reflect.ValueOf(arg)
t := reflectx.Deref(v.Type())
// []byte is a driver.Value type so it should not be expanded
if t.Kind() == reflect.Slice && t != reflect.TypeOf([]byte{}) {
meta[i].length = v.Len()
meta[i].v = v
anySlices = true
flatArgsCount += meta[i].length
if meta[i].length == 0 {
return "", nil, errors.New("empty slice passed to 'in' query")
}
} else {
meta[i].i = arg
flatArgsCount++
}
}
// don't do any parsing if there aren't any slices; note that this means
// some errors that we might have caught below will not be returned.
if !anySlices {
return query, args, nil
}
newArgs := make([]interface{}, 0, flatArgsCount)
buf := make([]byte, 0, len(query)+len(", ?")*flatArgsCount)
var arg, offset int
for i := strings.IndexByte(query[offset:], '?'); i != -1; i = strings.IndexByte(query[offset:], '?') {
if arg >= len(meta) {
// if an argument wasn't passed, lets return an error; this is
// not actually how database/sql Exec/Query works, but since we are
// creating an argument list programmatically, we want to be able
// to catch these programmer errors earlier.
return "", nil, errors.New("number of bindVars exceeds arguments")
}
argMeta := meta[arg]
arg++
// not a slice, continue.
// our questionmark will either be written before the next expansion
// of a slice or after the loop when writing the rest of the query
if argMeta.length == 0 {
offset = offset + i + 1
newArgs = append(newArgs, argMeta.i)
continue
}
// write everything up to and including our ? character
buf = append(buf, query[:offset+i+1]...)
for si := 1; si < argMeta.length; si++ {
buf = append(buf, ", ?"...)
}
newArgs = appendReflectSlice(newArgs, argMeta.v, argMeta.length)
// slice the query and reset the offset. this avoids some bookkeeping for
// the write after the loop
query = query[offset+i+1:]
offset = 0
}
buf = append(buf, query...)
if arg < len(meta) {
return "", nil, errors.New("number of bindVars less than number arguments")
}
return string(buf), newArgs, nil
} | [
"func",
"In",
"(",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// argMeta stores reflect.Value and length for slices and",
"// the value itself for non-slice arguments",
"type",
"argMeta",
"struct",
"{",
"v",
"reflect",
".",
"Value",
"\n",
"i",
"interface",
"{",
"}",
"\n",
"length",
"int",
"\n",
"}",
"\n\n",
"var",
"flatArgsCount",
"int",
"\n",
"var",
"anySlices",
"bool",
"\n\n",
"meta",
":=",
"make",
"(",
"[",
"]",
"argMeta",
",",
"len",
"(",
"args",
")",
")",
"\n\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"if",
"a",
",",
"ok",
":=",
"arg",
".",
"(",
"driver",
".",
"Valuer",
")",
";",
"ok",
"{",
"arg",
",",
"_",
"=",
"a",
".",
"Value",
"(",
")",
"\n",
"}",
"\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"arg",
")",
"\n",
"t",
":=",
"reflectx",
".",
"Deref",
"(",
"v",
".",
"Type",
"(",
")",
")",
"\n\n",
"// []byte is a driver.Value type so it should not be expanded",
"if",
"t",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Slice",
"&&",
"t",
"!=",
"reflect",
".",
"TypeOf",
"(",
"[",
"]",
"byte",
"{",
"}",
")",
"{",
"meta",
"[",
"i",
"]",
".",
"length",
"=",
"v",
".",
"Len",
"(",
")",
"\n",
"meta",
"[",
"i",
"]",
".",
"v",
"=",
"v",
"\n\n",
"anySlices",
"=",
"true",
"\n",
"flatArgsCount",
"+=",
"meta",
"[",
"i",
"]",
".",
"length",
"\n\n",
"if",
"meta",
"[",
"i",
"]",
".",
"length",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"meta",
"[",
"i",
"]",
".",
"i",
"=",
"arg",
"\n",
"flatArgsCount",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"// don't do any parsing if there aren't any slices; note that this means",
"// some errors that we might have caught below will not be returned.",
"if",
"!",
"anySlices",
"{",
"return",
"query",
",",
"args",
",",
"nil",
"\n",
"}",
"\n\n",
"newArgs",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
",",
"flatArgsCount",
")",
"\n",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"query",
")",
"+",
"len",
"(",
"\"",
"\"",
")",
"*",
"flatArgsCount",
")",
"\n\n",
"var",
"arg",
",",
"offset",
"int",
"\n\n",
"for",
"i",
":=",
"strings",
".",
"IndexByte",
"(",
"query",
"[",
"offset",
":",
"]",
",",
"'?'",
")",
";",
"i",
"!=",
"-",
"1",
";",
"i",
"=",
"strings",
".",
"IndexByte",
"(",
"query",
"[",
"offset",
":",
"]",
",",
"'?'",
")",
"{",
"if",
"arg",
">=",
"len",
"(",
"meta",
")",
"{",
"// if an argument wasn't passed, lets return an error; this is",
"// not actually how database/sql Exec/Query works, but since we are",
"// creating an argument list programmatically, we want to be able",
"// to catch these programmer errors earlier.",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"argMeta",
":=",
"meta",
"[",
"arg",
"]",
"\n",
"arg",
"++",
"\n\n",
"// not a slice, continue.",
"// our questionmark will either be written before the next expansion",
"// of a slice or after the loop when writing the rest of the query",
"if",
"argMeta",
".",
"length",
"==",
"0",
"{",
"offset",
"=",
"offset",
"+",
"i",
"+",
"1",
"\n",
"newArgs",
"=",
"append",
"(",
"newArgs",
",",
"argMeta",
".",
"i",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// write everything up to and including our ? character",
"buf",
"=",
"append",
"(",
"buf",
",",
"query",
"[",
":",
"offset",
"+",
"i",
"+",
"1",
"]",
"...",
")",
"\n\n",
"for",
"si",
":=",
"1",
";",
"si",
"<",
"argMeta",
".",
"length",
";",
"si",
"++",
"{",
"buf",
"=",
"append",
"(",
"buf",
",",
"\"",
"\"",
"...",
")",
"\n",
"}",
"\n\n",
"newArgs",
"=",
"appendReflectSlice",
"(",
"newArgs",
",",
"argMeta",
".",
"v",
",",
"argMeta",
".",
"length",
")",
"\n\n",
"// slice the query and reset the offset. this avoids some bookkeeping for",
"// the write after the loop",
"query",
"=",
"query",
"[",
"offset",
"+",
"i",
"+",
"1",
":",
"]",
"\n",
"offset",
"=",
"0",
"\n",
"}",
"\n\n",
"buf",
"=",
"append",
"(",
"buf",
",",
"query",
"...",
")",
"\n\n",
"if",
"arg",
"<",
"len",
"(",
"meta",
")",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"buf",
")",
",",
"newArgs",
",",
"nil",
"\n",
"}"
] | // In expands slice values in args, returning the modified query string
// and a new arg list that can be executed by a database. The `query` should
// use the `?` bindVar. The return value uses the `?` bindVar. | [
"In",
"expands",
"slice",
"values",
"in",
"args",
"returning",
"the",
"modified",
"query",
"string",
"and",
"a",
"new",
"arg",
"list",
"that",
"can",
"be",
"executed",
"by",
"a",
"database",
".",
"The",
"query",
"should",
"use",
"the",
"?",
"bindVar",
".",
"The",
"return",
"value",
"uses",
"the",
"?",
"bindVar",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/bind.go#L104-L196 |
160,361 | jmoiron/sqlx | sqlx_context.go | ConnectContext | func ConnectContext(ctx context.Context, driverName, dataSourceName string) (*DB, error) {
db, err := Open(driverName, dataSourceName)
if err != nil {
return db, err
}
err = db.PingContext(ctx)
return db, err
} | go | func ConnectContext(ctx context.Context, driverName, dataSourceName string) (*DB, error) {
db, err := Open(driverName, dataSourceName)
if err != nil {
return db, err
}
err = db.PingContext(ctx)
return db, err
} | [
"func",
"ConnectContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"driverName",
",",
"dataSourceName",
"string",
")",
"(",
"*",
"DB",
",",
"error",
")",
"{",
"db",
",",
"err",
":=",
"Open",
"(",
"driverName",
",",
"dataSourceName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"db",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"db",
".",
"PingContext",
"(",
"ctx",
")",
"\n",
"return",
"db",
",",
"err",
"\n",
"}"
] | // ConnectContext to a database and verify with a ping. | [
"ConnectContext",
"to",
"a",
"database",
"and",
"verify",
"with",
"a",
"ping",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L15-L22 |
160,362 | jmoiron/sqlx | sqlx_context.go | PreparexContext | func PreparexContext(ctx context.Context, p PreparerContext, query string) (*Stmt, error) {
s, err := p.PrepareContext(ctx, query)
if err != nil {
return nil, err
}
return &Stmt{Stmt: s, unsafe: isUnsafe(p), Mapper: mapperFor(p)}, err
} | go | func PreparexContext(ctx context.Context, p PreparerContext, query string) (*Stmt, error) {
s, err := p.PrepareContext(ctx, query)
if err != nil {
return nil, err
}
return &Stmt{Stmt: s, unsafe: isUnsafe(p), Mapper: mapperFor(p)}, err
} | [
"func",
"PreparexContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"p",
"PreparerContext",
",",
"query",
"string",
")",
"(",
"*",
"Stmt",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"p",
".",
"PrepareContext",
"(",
"ctx",
",",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Stmt",
"{",
"Stmt",
":",
"s",
",",
"unsafe",
":",
"isUnsafe",
"(",
"p",
")",
",",
"Mapper",
":",
"mapperFor",
"(",
"p",
")",
"}",
",",
"err",
"\n",
"}"
] | // PreparexContext prepares a statement.
//
// The provided context is used for the preparation of the statement, not for
// the execution of the statement. | [
"PreparexContext",
"prepares",
"a",
"statement",
".",
"The",
"provided",
"context",
"is",
"used",
"for",
"the",
"preparation",
"of",
"the",
"statement",
"not",
"for",
"the",
"execution",
"of",
"the",
"statement",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L68-L74 |
160,363 | jmoiron/sqlx | sqlx_context.go | GetContext | func GetContext(ctx context.Context, q QueryerContext, dest interface{}, query string, args ...interface{}) error {
r := q.QueryRowxContext(ctx, query, args...)
return r.scanAny(dest, false)
} | go | func GetContext(ctx context.Context, q QueryerContext, dest interface{}, query string, args ...interface{}) error {
r := q.QueryRowxContext(ctx, query, args...)
return r.scanAny(dest, false)
} | [
"func",
"GetContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"QueryerContext",
",",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"r",
":=",
"q",
".",
"QueryRowxContext",
"(",
"ctx",
",",
"query",
",",
"args",
"...",
")",
"\n",
"return",
"r",
".",
"scanAny",
"(",
"dest",
",",
"false",
")",
"\n",
"}"
] | // GetContext does a QueryRow using the provided Queryer, and scans the
// resulting row to dest. If dest is scannable, the result must only have one
// column. Otherwise, StructScan is used. Get will return sql.ErrNoRows like
// row.Scan would. Any placeholder parameters are replaced with supplied args.
// An error is returned if the result set is empty. | [
"GetContext",
"does",
"a",
"QueryRow",
"using",
"the",
"provided",
"Queryer",
"and",
"scans",
"the",
"resulting",
"row",
"to",
"dest",
".",
"If",
"dest",
"is",
"scannable",
"the",
"result",
"must",
"only",
"have",
"one",
"column",
".",
"Otherwise",
"StructScan",
"is",
"used",
".",
"Get",
"will",
"return",
"sql",
".",
"ErrNoRows",
"like",
"row",
".",
"Scan",
"would",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"result",
"set",
"is",
"empty",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L81-L84 |
160,364 | jmoiron/sqlx | sqlx_context.go | MustExecContext | func MustExecContext(ctx context.Context, e ExecerContext, query string, args ...interface{}) sql.Result {
res, err := e.ExecContext(ctx, query, args...)
if err != nil {
panic(err)
}
return res
} | go | func MustExecContext(ctx context.Context, e ExecerContext, query string, args ...interface{}) sql.Result {
res, err := e.ExecContext(ctx, query, args...)
if err != nil {
panic(err)
}
return res
} | [
"func",
"MustExecContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"e",
"ExecerContext",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"sql",
".",
"Result",
"{",
"res",
",",
"err",
":=",
"e",
".",
"ExecContext",
"(",
"ctx",
",",
"query",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // MustExecContext execs the query using e and panics if there was an error.
// Any placeholder parameters are replaced with supplied args. | [
"MustExecContext",
"execs",
"the",
"query",
"using",
"e",
"and",
"panics",
"if",
"there",
"was",
"an",
"error",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L112-L118 |
160,365 | jmoiron/sqlx | sqlx_context.go | NamedQueryContext | func (db *DB) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*Rows, error) {
return NamedQueryContext(ctx, db, query, arg)
} | go | func (db *DB) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*Rows, error) {
return NamedQueryContext(ctx, db, query, arg)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"NamedQueryContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"return",
"NamedQueryContext",
"(",
"ctx",
",",
"db",
",",
"query",
",",
"arg",
")",
"\n",
"}"
] | // NamedQueryContext using this DB.
// Any named placeholder parameters are replaced with fields from arg. | [
"NamedQueryContext",
"using",
"this",
"DB",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L127-L129 |
160,366 | jmoiron/sqlx | sqlx_context.go | NamedExecContext | func (db *DB) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
return NamedExecContext(ctx, db, query, arg)
} | go | func (db *DB) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
return NamedExecContext(ctx, db, query, arg)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"NamedExecContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"sql",
".",
"Result",
",",
"error",
")",
"{",
"return",
"NamedExecContext",
"(",
"ctx",
",",
"db",
",",
"query",
",",
"arg",
")",
"\n",
"}"
] | // NamedExecContext using this DB.
// Any named placeholder parameters are replaced with fields from arg. | [
"NamedExecContext",
"using",
"this",
"DB",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L133-L135 |
160,367 | jmoiron/sqlx | sqlx_context.go | SelectContext | func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return SelectContext(ctx, db, dest, query, args...)
} | go | func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return SelectContext(ctx, db, dest, query, args...)
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"SelectContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"SelectContext",
"(",
"ctx",
",",
"db",
",",
"dest",
",",
"query",
",",
"args",
"...",
")",
"\n",
"}"
] | // SelectContext using this DB.
// Any placeholder parameters are replaced with supplied args. | [
"SelectContext",
"using",
"this",
"DB",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L139-L141 |
160,368 | jmoiron/sqlx | sqlx_context.go | NamedStmtContext | func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt {
return &NamedStmt{
QueryString: stmt.QueryString,
Params: stmt.Params,
Stmt: tx.StmtxContext(ctx, stmt.Stmt),
}
} | go | func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt {
return &NamedStmt{
QueryString: stmt.QueryString,
Params: stmt.Params,
Stmt: tx.StmtxContext(ctx, stmt.Stmt),
}
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"NamedStmtContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"stmt",
"*",
"NamedStmt",
")",
"*",
"NamedStmt",
"{",
"return",
"&",
"NamedStmt",
"{",
"QueryString",
":",
"stmt",
".",
"QueryString",
",",
"Params",
":",
"stmt",
".",
"Params",
",",
"Stmt",
":",
"tx",
".",
"StmtxContext",
"(",
"ctx",
",",
"stmt",
".",
"Stmt",
")",
",",
"}",
"\n",
"}"
] | // NamedStmtContext returns a version of the prepared statement which runs
// within a transaction. | [
"NamedStmtContext",
"returns",
"a",
"version",
"of",
"the",
"prepared",
"statement",
"which",
"runs",
"within",
"a",
"transaction",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L230-L236 |
160,369 | jmoiron/sqlx | sqlx_context.go | MustExecContext | func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result {
return MustExecContext(ctx, tx, query, args...)
} | go | func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result {
return MustExecContext(ctx, tx, query, args...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"MustExecContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"sql",
".",
"Result",
"{",
"return",
"MustExecContext",
"(",
"ctx",
",",
"tx",
",",
"query",
",",
"args",
"...",
")",
"\n",
"}"
] | // MustExecContext runs MustExecContext within a transaction.
// Any placeholder parameters are replaced with supplied args. | [
"MustExecContext",
"runs",
"MustExecContext",
"within",
"a",
"transaction",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L253-L255 |
160,370 | jmoiron/sqlx | sqlx_context.go | QueryxContext | func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
r, err := tx.Tx.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
return &Rows{Rows: r, unsafe: tx.unsafe, Mapper: tx.Mapper}, err
} | go | func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
r, err := tx.Tx.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
return &Rows{Rows: r, unsafe: tx.unsafe, Mapper: tx.Mapper}, err
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"QueryxContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"tx",
".",
"Tx",
".",
"QueryContext",
"(",
"ctx",
",",
"query",
",",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Rows",
"{",
"Rows",
":",
"r",
",",
"unsafe",
":",
"tx",
".",
"unsafe",
",",
"Mapper",
":",
"tx",
".",
"Mapper",
"}",
",",
"err",
"\n",
"}"
] | // QueryxContext within a transaction and context.
// Any placeholder parameters are replaced with supplied args. | [
"QueryxContext",
"within",
"a",
"transaction",
"and",
"context",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L259-L265 |
160,371 | jmoiron/sqlx | sqlx_context.go | GetContext | func (tx *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return GetContext(ctx, tx, dest, query, args...)
} | go | func (tx *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return GetContext(ctx, tx, dest, query, args...)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"GetContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"dest",
"interface",
"{",
"}",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"GetContext",
"(",
"ctx",
",",
"tx",
",",
"dest",
",",
"query",
",",
"args",
"...",
")",
"\n",
"}"
] | // GetContext within a transaction and context.
// Any placeholder parameters are replaced with supplied args.
// An error is returned if the result set is empty. | [
"GetContext",
"within",
"a",
"transaction",
"and",
"context",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"result",
"set",
"is",
"empty",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L276-L278 |
160,372 | jmoiron/sqlx | sqlx_context.go | QueryRowxContext | func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row {
rows, err := tx.Tx.QueryContext(ctx, query, args...)
return &Row{rows: rows, err: err, unsafe: tx.unsafe, Mapper: tx.Mapper}
} | go | func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row {
rows, err := tx.Tx.QueryContext(ctx, query, args...)
return &Row{rows: rows, err: err, unsafe: tx.unsafe, Mapper: tx.Mapper}
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"QueryRowxContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Row",
"{",
"rows",
",",
"err",
":=",
"tx",
".",
"Tx",
".",
"QueryContext",
"(",
"ctx",
",",
"query",
",",
"args",
"...",
")",
"\n",
"return",
"&",
"Row",
"{",
"rows",
":",
"rows",
",",
"err",
":",
"err",
",",
"unsafe",
":",
"tx",
".",
"unsafe",
",",
"Mapper",
":",
"tx",
".",
"Mapper",
"}",
"\n",
"}"
] | // QueryRowxContext within a transaction and context.
// Any placeholder parameters are replaced with supplied args. | [
"QueryRowxContext",
"within",
"a",
"transaction",
"and",
"context",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L282-L285 |
160,373 | jmoiron/sqlx | sqlx_context.go | NamedExecContext | func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
return NamedExecContext(ctx, tx, query, arg)
} | go | func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
return NamedExecContext(ctx, tx, query, arg)
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"NamedExecContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
",",
"arg",
"interface",
"{",
"}",
")",
"(",
"sql",
".",
"Result",
",",
"error",
")",
"{",
"return",
"NamedExecContext",
"(",
"ctx",
",",
"tx",
",",
"query",
",",
"arg",
")",
"\n",
"}"
] | // NamedExecContext using this Tx.
// Any named placeholder parameters are replaced with fields from arg. | [
"NamedExecContext",
"using",
"this",
"Tx",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L289-L291 |
160,374 | jmoiron/sqlx | sqlx_context.go | SelectContext | func (s *Stmt) SelectContext(ctx context.Context, dest interface{}, args ...interface{}) error {
return SelectContext(ctx, &qStmt{s}, dest, "", args...)
} | go | func (s *Stmt) SelectContext(ctx context.Context, dest interface{}, args ...interface{}) error {
return SelectContext(ctx, &qStmt{s}, dest, "", args...)
} | [
"func",
"(",
"s",
"*",
"Stmt",
")",
"SelectContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"dest",
"interface",
"{",
"}",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"SelectContext",
"(",
"ctx",
",",
"&",
"qStmt",
"{",
"s",
"}",
",",
"dest",
",",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"}"
] | // SelectContext using the prepared statement.
// Any placeholder parameters are replaced with supplied args. | [
"SelectContext",
"using",
"the",
"prepared",
"statement",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L295-L297 |
160,375 | jmoiron/sqlx | sqlx_context.go | QueryRowxContext | func (s *Stmt) QueryRowxContext(ctx context.Context, args ...interface{}) *Row {
qs := &qStmt{s}
return qs.QueryRowxContext(ctx, "", args...)
} | go | func (s *Stmt) QueryRowxContext(ctx context.Context, args ...interface{}) *Row {
qs := &qStmt{s}
return qs.QueryRowxContext(ctx, "", args...)
} | [
"func",
"(",
"s",
"*",
"Stmt",
")",
"QueryRowxContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Row",
"{",
"qs",
":=",
"&",
"qStmt",
"{",
"s",
"}",
"\n",
"return",
"qs",
".",
"QueryRowxContext",
"(",
"ctx",
",",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"}"
] | // QueryRowxContext using this statement.
// Any placeholder parameters are replaced with supplied args. | [
"QueryRowxContext",
"using",
"this",
"statement",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L315-L318 |
160,376 | jmoiron/sqlx | sqlx_context.go | QueryxContext | func (s *Stmt) QueryxContext(ctx context.Context, args ...interface{}) (*Rows, error) {
qs := &qStmt{s}
return qs.QueryxContext(ctx, "", args...)
} | go | func (s *Stmt) QueryxContext(ctx context.Context, args ...interface{}) (*Rows, error) {
qs := &qStmt{s}
return qs.QueryxContext(ctx, "", args...)
} | [
"func",
"(",
"s",
"*",
"Stmt",
")",
"QueryxContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"qs",
":=",
"&",
"qStmt",
"{",
"s",
"}",
"\n",
"return",
"qs",
".",
"QueryxContext",
"(",
"ctx",
",",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"}"
] | // QueryxContext using this statement.
// Any placeholder parameters are replaced with supplied args. | [
"QueryxContext",
"using",
"this",
"statement",
".",
"Any",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"supplied",
"args",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/sqlx_context.go#L322-L325 |
160,377 | jmoiron/sqlx | reflectx/reflect.go | NewMapper | func NewMapper(tagName string) *Mapper {
return &Mapper{
cache: make(map[reflect.Type]*StructMap),
tagName: tagName,
}
} | go | func NewMapper(tagName string) *Mapper {
return &Mapper{
cache: make(map[reflect.Type]*StructMap),
tagName: tagName,
}
} | [
"func",
"NewMapper",
"(",
"tagName",
"string",
")",
"*",
"Mapper",
"{",
"return",
"&",
"Mapper",
"{",
"cache",
":",
"make",
"(",
"map",
"[",
"reflect",
".",
"Type",
"]",
"*",
"StructMap",
")",
",",
"tagName",
":",
"tagName",
",",
"}",
"\n",
"}"
] | // NewMapper returns a new mapper using the tagName as its struct field tag.
// If tagName is the empty string, it is ignored. | [
"NewMapper",
"returns",
"a",
"new",
"mapper",
"using",
"the",
"tagName",
"as",
"its",
"struct",
"field",
"tag",
".",
"If",
"tagName",
"is",
"the",
"empty",
"string",
"it",
"is",
"ignored",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L73-L78 |
160,378 | jmoiron/sqlx | reflectx/reflect.go | NewMapperTagFunc | func NewMapperTagFunc(tagName string, mapFunc, tagMapFunc func(string) string) *Mapper {
return &Mapper{
cache: make(map[reflect.Type]*StructMap),
tagName: tagName,
mapFunc: mapFunc,
tagMapFunc: tagMapFunc,
}
} | go | func NewMapperTagFunc(tagName string, mapFunc, tagMapFunc func(string) string) *Mapper {
return &Mapper{
cache: make(map[reflect.Type]*StructMap),
tagName: tagName,
mapFunc: mapFunc,
tagMapFunc: tagMapFunc,
}
} | [
"func",
"NewMapperTagFunc",
"(",
"tagName",
"string",
",",
"mapFunc",
",",
"tagMapFunc",
"func",
"(",
"string",
")",
"string",
")",
"*",
"Mapper",
"{",
"return",
"&",
"Mapper",
"{",
"cache",
":",
"make",
"(",
"map",
"[",
"reflect",
".",
"Type",
"]",
"*",
"StructMap",
")",
",",
"tagName",
":",
"tagName",
",",
"mapFunc",
":",
"mapFunc",
",",
"tagMapFunc",
":",
"tagMapFunc",
",",
"}",
"\n",
"}"
] | // NewMapperTagFunc returns a new mapper which contains a mapper for field names
// AND a mapper for tag values. This is useful for tags like json which can
// have values like "name,omitempty". | [
"NewMapperTagFunc",
"returns",
"a",
"new",
"mapper",
"which",
"contains",
"a",
"mapper",
"for",
"field",
"names",
"AND",
"a",
"mapper",
"for",
"tag",
"values",
".",
"This",
"is",
"useful",
"for",
"tags",
"like",
"json",
"which",
"can",
"have",
"values",
"like",
"name",
"omitempty",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L83-L90 |
160,379 | jmoiron/sqlx | reflectx/reflect.go | TypeMap | func (m *Mapper) TypeMap(t reflect.Type) *StructMap {
m.mutex.Lock()
mapping, ok := m.cache[t]
if !ok {
mapping = getMapping(t, m.tagName, m.mapFunc, m.tagMapFunc)
m.cache[t] = mapping
}
m.mutex.Unlock()
return mapping
} | go | func (m *Mapper) TypeMap(t reflect.Type) *StructMap {
m.mutex.Lock()
mapping, ok := m.cache[t]
if !ok {
mapping = getMapping(t, m.tagName, m.mapFunc, m.tagMapFunc)
m.cache[t] = mapping
}
m.mutex.Unlock()
return mapping
} | [
"func",
"(",
"m",
"*",
"Mapper",
")",
"TypeMap",
"(",
"t",
"reflect",
".",
"Type",
")",
"*",
"StructMap",
"{",
"m",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"mapping",
",",
"ok",
":=",
"m",
".",
"cache",
"[",
"t",
"]",
"\n",
"if",
"!",
"ok",
"{",
"mapping",
"=",
"getMapping",
"(",
"t",
",",
"m",
".",
"tagName",
",",
"m",
".",
"mapFunc",
",",
"m",
".",
"tagMapFunc",
")",
"\n",
"m",
".",
"cache",
"[",
"t",
"]",
"=",
"mapping",
"\n",
"}",
"\n",
"m",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"mapping",
"\n",
"}"
] | // TypeMap returns a mapping of field strings to int slices representing
// the traversal down the struct to reach the field. | [
"TypeMap",
"returns",
"a",
"mapping",
"of",
"field",
"strings",
"to",
"int",
"slices",
"representing",
"the",
"traversal",
"down",
"the",
"struct",
"to",
"reach",
"the",
"field",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L105-L114 |
160,380 | jmoiron/sqlx | reflectx/reflect.go | FieldMap | func (m *Mapper) FieldMap(v reflect.Value) map[string]reflect.Value {
v = reflect.Indirect(v)
mustBe(v, reflect.Struct)
r := map[string]reflect.Value{}
tm := m.TypeMap(v.Type())
for tagName, fi := range tm.Names {
r[tagName] = FieldByIndexes(v, fi.Index)
}
return r
} | go | func (m *Mapper) FieldMap(v reflect.Value) map[string]reflect.Value {
v = reflect.Indirect(v)
mustBe(v, reflect.Struct)
r := map[string]reflect.Value{}
tm := m.TypeMap(v.Type())
for tagName, fi := range tm.Names {
r[tagName] = FieldByIndexes(v, fi.Index)
}
return r
} | [
"func",
"(",
"m",
"*",
"Mapper",
")",
"FieldMap",
"(",
"v",
"reflect",
".",
"Value",
")",
"map",
"[",
"string",
"]",
"reflect",
".",
"Value",
"{",
"v",
"=",
"reflect",
".",
"Indirect",
"(",
"v",
")",
"\n",
"mustBe",
"(",
"v",
",",
"reflect",
".",
"Struct",
")",
"\n\n",
"r",
":=",
"map",
"[",
"string",
"]",
"reflect",
".",
"Value",
"{",
"}",
"\n",
"tm",
":=",
"m",
".",
"TypeMap",
"(",
"v",
".",
"Type",
"(",
")",
")",
"\n",
"for",
"tagName",
",",
"fi",
":=",
"range",
"tm",
".",
"Names",
"{",
"r",
"[",
"tagName",
"]",
"=",
"FieldByIndexes",
"(",
"v",
",",
"fi",
".",
"Index",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // FieldMap returns the mapper's mapping of field names to reflect values. Panics
// if v's Kind is not Struct, or v is not Indirectable to a struct kind. | [
"FieldMap",
"returns",
"the",
"mapper",
"s",
"mapping",
"of",
"field",
"names",
"to",
"reflect",
"values",
".",
"Panics",
"if",
"v",
"s",
"Kind",
"is",
"not",
"Struct",
"or",
"v",
"is",
"not",
"Indirectable",
"to",
"a",
"struct",
"kind",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L118-L128 |
160,381 | jmoiron/sqlx | reflectx/reflect.go | FieldByName | func (m *Mapper) FieldByName(v reflect.Value, name string) reflect.Value {
v = reflect.Indirect(v)
mustBe(v, reflect.Struct)
tm := m.TypeMap(v.Type())
fi, ok := tm.Names[name]
if !ok {
return v
}
return FieldByIndexes(v, fi.Index)
} | go | func (m *Mapper) FieldByName(v reflect.Value, name string) reflect.Value {
v = reflect.Indirect(v)
mustBe(v, reflect.Struct)
tm := m.TypeMap(v.Type())
fi, ok := tm.Names[name]
if !ok {
return v
}
return FieldByIndexes(v, fi.Index)
} | [
"func",
"(",
"m",
"*",
"Mapper",
")",
"FieldByName",
"(",
"v",
"reflect",
".",
"Value",
",",
"name",
"string",
")",
"reflect",
".",
"Value",
"{",
"v",
"=",
"reflect",
".",
"Indirect",
"(",
"v",
")",
"\n",
"mustBe",
"(",
"v",
",",
"reflect",
".",
"Struct",
")",
"\n\n",
"tm",
":=",
"m",
".",
"TypeMap",
"(",
"v",
".",
"Type",
"(",
")",
")",
"\n",
"fi",
",",
"ok",
":=",
"tm",
".",
"Names",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"v",
"\n",
"}",
"\n",
"return",
"FieldByIndexes",
"(",
"v",
",",
"fi",
".",
"Index",
")",
"\n",
"}"
] | // FieldByName returns a field by its mapped name as a reflect.Value.
// Panics if v's Kind is not Struct or v is not Indirectable to a struct Kind.
// Returns zero Value if the name is not found. | [
"FieldByName",
"returns",
"a",
"field",
"by",
"its",
"mapped",
"name",
"as",
"a",
"reflect",
".",
"Value",
".",
"Panics",
"if",
"v",
"s",
"Kind",
"is",
"not",
"Struct",
"or",
"v",
"is",
"not",
"Indirectable",
"to",
"a",
"struct",
"Kind",
".",
"Returns",
"zero",
"Value",
"if",
"the",
"name",
"is",
"not",
"found",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L133-L143 |
160,382 | jmoiron/sqlx | reflectx/reflect.go | FieldsByName | func (m *Mapper) FieldsByName(v reflect.Value, names []string) []reflect.Value {
v = reflect.Indirect(v)
mustBe(v, reflect.Struct)
tm := m.TypeMap(v.Type())
vals := make([]reflect.Value, 0, len(names))
for _, name := range names {
fi, ok := tm.Names[name]
if !ok {
vals = append(vals, *new(reflect.Value))
} else {
vals = append(vals, FieldByIndexes(v, fi.Index))
}
}
return vals
} | go | func (m *Mapper) FieldsByName(v reflect.Value, names []string) []reflect.Value {
v = reflect.Indirect(v)
mustBe(v, reflect.Struct)
tm := m.TypeMap(v.Type())
vals := make([]reflect.Value, 0, len(names))
for _, name := range names {
fi, ok := tm.Names[name]
if !ok {
vals = append(vals, *new(reflect.Value))
} else {
vals = append(vals, FieldByIndexes(v, fi.Index))
}
}
return vals
} | [
"func",
"(",
"m",
"*",
"Mapper",
")",
"FieldsByName",
"(",
"v",
"reflect",
".",
"Value",
",",
"names",
"[",
"]",
"string",
")",
"[",
"]",
"reflect",
".",
"Value",
"{",
"v",
"=",
"reflect",
".",
"Indirect",
"(",
"v",
")",
"\n",
"mustBe",
"(",
"v",
",",
"reflect",
".",
"Struct",
")",
"\n\n",
"tm",
":=",
"m",
".",
"TypeMap",
"(",
"v",
".",
"Type",
"(",
")",
")",
"\n",
"vals",
":=",
"make",
"(",
"[",
"]",
"reflect",
".",
"Value",
",",
"0",
",",
"len",
"(",
"names",
")",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"fi",
",",
"ok",
":=",
"tm",
".",
"Names",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"vals",
"=",
"append",
"(",
"vals",
",",
"*",
"new",
"(",
"reflect",
".",
"Value",
")",
")",
"\n",
"}",
"else",
"{",
"vals",
"=",
"append",
"(",
"vals",
",",
"FieldByIndexes",
"(",
"v",
",",
"fi",
".",
"Index",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"vals",
"\n",
"}"
] | // FieldsByName returns a slice of values corresponding to the slice of names
// for the value. Panics if v's Kind is not Struct or v is not Indirectable
// to a struct Kind. Returns zero Value for each name not found. | [
"FieldsByName",
"returns",
"a",
"slice",
"of",
"values",
"corresponding",
"to",
"the",
"slice",
"of",
"names",
"for",
"the",
"value",
".",
"Panics",
"if",
"v",
"s",
"Kind",
"is",
"not",
"Struct",
"or",
"v",
"is",
"not",
"Indirectable",
"to",
"a",
"struct",
"Kind",
".",
"Returns",
"zero",
"Value",
"for",
"each",
"name",
"not",
"found",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L148-L163 |
160,383 | jmoiron/sqlx | reflectx/reflect.go | TraversalsByName | func (m *Mapper) TraversalsByName(t reflect.Type, names []string) [][]int {
r := make([][]int, 0, len(names))
m.TraversalsByNameFunc(t, names, func(_ int, i []int) error {
if i == nil {
r = append(r, []int{})
} else {
r = append(r, i)
}
return nil
})
return r
} | go | func (m *Mapper) TraversalsByName(t reflect.Type, names []string) [][]int {
r := make([][]int, 0, len(names))
m.TraversalsByNameFunc(t, names, func(_ int, i []int) error {
if i == nil {
r = append(r, []int{})
} else {
r = append(r, i)
}
return nil
})
return r
} | [
"func",
"(",
"m",
"*",
"Mapper",
")",
"TraversalsByName",
"(",
"t",
"reflect",
".",
"Type",
",",
"names",
"[",
"]",
"string",
")",
"[",
"]",
"[",
"]",
"int",
"{",
"r",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"int",
",",
"0",
",",
"len",
"(",
"names",
")",
")",
"\n",
"m",
".",
"TraversalsByNameFunc",
"(",
"t",
",",
"names",
",",
"func",
"(",
"_",
"int",
",",
"i",
"[",
"]",
"int",
")",
"error",
"{",
"if",
"i",
"==",
"nil",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"[",
"]",
"int",
"{",
"}",
")",
"\n",
"}",
"else",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"i",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // TraversalsByName returns a slice of int slices which represent the struct
// traversals for each mapped name. Panics if t is not a struct or Indirectable
// to a struct. Returns empty int slice for each name not found. | [
"TraversalsByName",
"returns",
"a",
"slice",
"of",
"int",
"slices",
"which",
"represent",
"the",
"struct",
"traversals",
"for",
"each",
"mapped",
"name",
".",
"Panics",
"if",
"t",
"is",
"not",
"a",
"struct",
"or",
"Indirectable",
"to",
"a",
"struct",
".",
"Returns",
"empty",
"int",
"slice",
"for",
"each",
"name",
"not",
"found",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L168-L180 |
160,384 | jmoiron/sqlx | reflectx/reflect.go | TraversalsByNameFunc | func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error {
t = Deref(t)
mustBe(t, reflect.Struct)
tm := m.TypeMap(t)
for i, name := range names {
fi, ok := tm.Names[name]
if !ok {
if err := fn(i, nil); err != nil {
return err
}
} else {
if err := fn(i, fi.Index); err != nil {
return err
}
}
}
return nil
} | go | func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error {
t = Deref(t)
mustBe(t, reflect.Struct)
tm := m.TypeMap(t)
for i, name := range names {
fi, ok := tm.Names[name]
if !ok {
if err := fn(i, nil); err != nil {
return err
}
} else {
if err := fn(i, fi.Index); err != nil {
return err
}
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Mapper",
")",
"TraversalsByNameFunc",
"(",
"t",
"reflect",
".",
"Type",
",",
"names",
"[",
"]",
"string",
",",
"fn",
"func",
"(",
"int",
",",
"[",
"]",
"int",
")",
"error",
")",
"error",
"{",
"t",
"=",
"Deref",
"(",
"t",
")",
"\n",
"mustBe",
"(",
"t",
",",
"reflect",
".",
"Struct",
")",
"\n",
"tm",
":=",
"m",
".",
"TypeMap",
"(",
"t",
")",
"\n",
"for",
"i",
",",
"name",
":=",
"range",
"names",
"{",
"fi",
",",
"ok",
":=",
"tm",
".",
"Names",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"if",
"err",
":=",
"fn",
"(",
"i",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"fn",
"(",
"i",
",",
"fi",
".",
"Index",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // TraversalsByNameFunc traverses the mapped names and calls fn with the index of
// each name and the struct traversal represented by that name. Panics if t is not
// a struct or Indirectable to a struct. Returns the first error returned by fn or nil. | [
"TraversalsByNameFunc",
"traverses",
"the",
"mapped",
"names",
"and",
"calls",
"fn",
"with",
"the",
"index",
"of",
"each",
"name",
"and",
"the",
"struct",
"traversal",
"represented",
"by",
"that",
"name",
".",
"Panics",
"if",
"t",
"is",
"not",
"a",
"struct",
"or",
"Indirectable",
"to",
"a",
"struct",
".",
"Returns",
"the",
"first",
"error",
"returned",
"by",
"fn",
"or",
"nil",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L185-L202 |
160,385 | jmoiron/sqlx | reflectx/reflect.go | FieldByIndexes | func FieldByIndexes(v reflect.Value, indexes []int) reflect.Value {
for _, i := range indexes {
v = reflect.Indirect(v).Field(i)
// if this is a pointer and it's nil, allocate a new value and set it
if v.Kind() == reflect.Ptr && v.IsNil() {
alloc := reflect.New(Deref(v.Type()))
v.Set(alloc)
}
if v.Kind() == reflect.Map && v.IsNil() {
v.Set(reflect.MakeMap(v.Type()))
}
}
return v
} | go | func FieldByIndexes(v reflect.Value, indexes []int) reflect.Value {
for _, i := range indexes {
v = reflect.Indirect(v).Field(i)
// if this is a pointer and it's nil, allocate a new value and set it
if v.Kind() == reflect.Ptr && v.IsNil() {
alloc := reflect.New(Deref(v.Type()))
v.Set(alloc)
}
if v.Kind() == reflect.Map && v.IsNil() {
v.Set(reflect.MakeMap(v.Type()))
}
}
return v
} | [
"func",
"FieldByIndexes",
"(",
"v",
"reflect",
".",
"Value",
",",
"indexes",
"[",
"]",
"int",
")",
"reflect",
".",
"Value",
"{",
"for",
"_",
",",
"i",
":=",
"range",
"indexes",
"{",
"v",
"=",
"reflect",
".",
"Indirect",
"(",
"v",
")",
".",
"Field",
"(",
"i",
")",
"\n",
"// if this is a pointer and it's nil, allocate a new value and set it",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"&&",
"v",
".",
"IsNil",
"(",
")",
"{",
"alloc",
":=",
"reflect",
".",
"New",
"(",
"Deref",
"(",
"v",
".",
"Type",
"(",
")",
")",
")",
"\n",
"v",
".",
"Set",
"(",
"alloc",
")",
"\n",
"}",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Map",
"&&",
"v",
".",
"IsNil",
"(",
")",
"{",
"v",
".",
"Set",
"(",
"reflect",
".",
"MakeMap",
"(",
"v",
".",
"Type",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] | // FieldByIndexes returns a value for the field given by the struct traversal
// for the given value. | [
"FieldByIndexes",
"returns",
"a",
"value",
"for",
"the",
"field",
"given",
"by",
"the",
"struct",
"traversal",
"for",
"the",
"given",
"value",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L206-L219 |
160,386 | jmoiron/sqlx | reflectx/reflect.go | FieldByIndexesReadOnly | func FieldByIndexesReadOnly(v reflect.Value, indexes []int) reflect.Value {
for _, i := range indexes {
v = reflect.Indirect(v).Field(i)
}
return v
} | go | func FieldByIndexesReadOnly(v reflect.Value, indexes []int) reflect.Value {
for _, i := range indexes {
v = reflect.Indirect(v).Field(i)
}
return v
} | [
"func",
"FieldByIndexesReadOnly",
"(",
"v",
"reflect",
".",
"Value",
",",
"indexes",
"[",
"]",
"int",
")",
"reflect",
".",
"Value",
"{",
"for",
"_",
",",
"i",
":=",
"range",
"indexes",
"{",
"v",
"=",
"reflect",
".",
"Indirect",
"(",
"v",
")",
".",
"Field",
"(",
"i",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] | // FieldByIndexesReadOnly returns a value for a particular struct traversal,
// but is not concerned with allocating nil pointers because the value is
// going to be used for reading and not setting. | [
"FieldByIndexesReadOnly",
"returns",
"a",
"value",
"for",
"a",
"particular",
"struct",
"traversal",
"but",
"is",
"not",
"concerned",
"with",
"allocating",
"nil",
"pointers",
"because",
"the",
"value",
"is",
"going",
"to",
"be",
"used",
"for",
"reading",
"and",
"not",
"setting",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L224-L229 |
160,387 | jmoiron/sqlx | reflectx/reflect.go | Deref | func Deref(t reflect.Type) reflect.Type {
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
return t
} | go | func Deref(t reflect.Type) reflect.Type {
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
return t
} | [
"func",
"Deref",
"(",
"t",
"reflect",
".",
"Type",
")",
"reflect",
".",
"Type",
"{",
"if",
"t",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"t",
"=",
"t",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"return",
"t",
"\n",
"}"
] | // Deref is Indirect for reflect.Types | [
"Deref",
"is",
"Indirect",
"for",
"reflect",
".",
"Types"
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L232-L237 |
160,388 | jmoiron/sqlx | reflectx/reflect.go | mustBe | func mustBe(v kinder, expected reflect.Kind) {
if k := v.Kind(); k != expected {
panic(&reflect.ValueError{Method: methodName(), Kind: k})
}
} | go | func mustBe(v kinder, expected reflect.Kind) {
if k := v.Kind(); k != expected {
panic(&reflect.ValueError{Method: methodName(), Kind: k})
}
} | [
"func",
"mustBe",
"(",
"v",
"kinder",
",",
"expected",
"reflect",
".",
"Kind",
")",
"{",
"if",
"k",
":=",
"v",
".",
"Kind",
"(",
")",
";",
"k",
"!=",
"expected",
"{",
"panic",
"(",
"&",
"reflect",
".",
"ValueError",
"{",
"Method",
":",
"methodName",
"(",
")",
",",
"Kind",
":",
"k",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // mustBe checks a value against a kind, panicing with a reflect.ValueError
// if the kind isn't that which is required. | [
"mustBe",
"checks",
"a",
"value",
"against",
"a",
"kind",
"panicing",
"with",
"a",
"reflect",
".",
"ValueError",
"if",
"the",
"kind",
"isn",
"t",
"that",
"which",
"is",
"required",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L247-L251 |
160,389 | jmoiron/sqlx | reflectx/reflect.go | methodName | func methodName() string {
pc, _, _, _ := runtime.Caller(2)
f := runtime.FuncForPC(pc)
if f == nil {
return "unknown method"
}
return f.Name()
} | go | func methodName() string {
pc, _, _, _ := runtime.Caller(2)
f := runtime.FuncForPC(pc)
if f == nil {
return "unknown method"
}
return f.Name()
} | [
"func",
"methodName",
"(",
")",
"string",
"{",
"pc",
",",
"_",
",",
"_",
",",
"_",
":=",
"runtime",
".",
"Caller",
"(",
"2",
")",
"\n",
"f",
":=",
"runtime",
".",
"FuncForPC",
"(",
"pc",
")",
"\n",
"if",
"f",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"f",
".",
"Name",
"(",
")",
"\n",
"}"
] | // methodName returns the caller of the function calling methodName | [
"methodName",
"returns",
"the",
"caller",
"of",
"the",
"function",
"calling",
"methodName"
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L254-L261 |
160,390 | jmoiron/sqlx | reflectx/reflect.go | parseOptions | func parseOptions(tag string) map[string]string {
parts := strings.Split(tag, ",")
options := make(map[string]string, len(parts))
if len(parts) > 1 {
for _, opt := range parts[1:] {
// short circuit potentially expensive split op
if strings.Contains(opt, "=") {
kv := strings.Split(opt, "=")
options[kv[0]] = kv[1]
continue
}
options[opt] = ""
}
}
return options
} | go | func parseOptions(tag string) map[string]string {
parts := strings.Split(tag, ",")
options := make(map[string]string, len(parts))
if len(parts) > 1 {
for _, opt := range parts[1:] {
// short circuit potentially expensive split op
if strings.Contains(opt, "=") {
kv := strings.Split(opt, "=")
options[kv[0]] = kv[1]
continue
}
options[opt] = ""
}
}
return options
} | [
"func",
"parseOptions",
"(",
"tag",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"tag",
",",
"\"",
"\"",
")",
"\n",
"options",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"len",
"(",
"parts",
")",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
">",
"1",
"{",
"for",
"_",
",",
"opt",
":=",
"range",
"parts",
"[",
"1",
":",
"]",
"{",
"// short circuit potentially expensive split op",
"if",
"strings",
".",
"Contains",
"(",
"opt",
",",
"\"",
"\"",
")",
"{",
"kv",
":=",
"strings",
".",
"Split",
"(",
"opt",
",",
"\"",
"\"",
")",
"\n",
"options",
"[",
"kv",
"[",
"0",
"]",
"]",
"=",
"kv",
"[",
"1",
"]",
"\n",
"continue",
"\n",
"}",
"\n",
"options",
"[",
"opt",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"options",
"\n",
"}"
] | // parseOptions parses options out of a tag string, skipping the name | [
"parseOptions",
"parses",
"options",
"out",
"of",
"a",
"tag",
"string",
"skipping",
"the",
"name"
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/reflectx/reflect.go#L324-L339 |
160,391 | jmoiron/sqlx | types/types.go | Value | func (g GzippedText) Value() (driver.Value, error) {
b := make([]byte, 0, len(g))
buf := bytes.NewBuffer(b)
w := gzip.NewWriter(buf)
w.Write(g)
w.Close()
return buf.Bytes(), nil
} | go | func (g GzippedText) Value() (driver.Value, error) {
b := make([]byte, 0, len(g))
buf := bytes.NewBuffer(b)
w := gzip.NewWriter(buf)
w.Write(g)
w.Close()
return buf.Bytes(), nil
} | [
"func",
"(",
"g",
"GzippedText",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"len",
"(",
"g",
")",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"b",
")",
"\n",
"w",
":=",
"gzip",
".",
"NewWriter",
"(",
"buf",
")",
"\n",
"w",
".",
"Write",
"(",
"g",
")",
"\n",
"w",
".",
"Close",
"(",
")",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n\n",
"}"
] | // Value implements the driver.Valuer interface, gzipping the raw value of
// this GzippedText. | [
"Value",
"implements",
"the",
"driver",
".",
"Valuer",
"interface",
"gzipping",
"the",
"raw",
"value",
"of",
"this",
"GzippedText",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/types/types.go#L19-L27 |
160,392 | jmoiron/sqlx | types/types.go | Scan | func (g *GzippedText) Scan(src interface{}) error {
var source []byte
switch src := src.(type) {
case string:
source = []byte(src)
case []byte:
source = src
default:
return errors.New("Incompatible type for GzippedText")
}
reader, err := gzip.NewReader(bytes.NewReader(source))
if err != nil {
return err
}
defer reader.Close()
b, err := ioutil.ReadAll(reader)
if err != nil {
return err
}
*g = GzippedText(b)
return nil
} | go | func (g *GzippedText) Scan(src interface{}) error {
var source []byte
switch src := src.(type) {
case string:
source = []byte(src)
case []byte:
source = src
default:
return errors.New("Incompatible type for GzippedText")
}
reader, err := gzip.NewReader(bytes.NewReader(source))
if err != nil {
return err
}
defer reader.Close()
b, err := ioutil.ReadAll(reader)
if err != nil {
return err
}
*g = GzippedText(b)
return nil
} | [
"func",
"(",
"g",
"*",
"GzippedText",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"source",
"[",
"]",
"byte",
"\n",
"switch",
"src",
":=",
"src",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"source",
"=",
"[",
"]",
"byte",
"(",
"src",
")",
"\n",
"case",
"[",
"]",
"byte",
":",
"source",
"=",
"src",
"\n",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"reader",
",",
"err",
":=",
"gzip",
".",
"NewReader",
"(",
"bytes",
".",
"NewReader",
"(",
"source",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"reader",
".",
"Close",
"(",
")",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"g",
"=",
"GzippedText",
"(",
"b",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Scan implements the sql.Scanner interface, ungzipping the value coming off
// the wire and storing the raw result in the GzippedText. | [
"Scan",
"implements",
"the",
"sql",
".",
"Scanner",
"interface",
"ungzipping",
"the",
"value",
"coming",
"off",
"the",
"wire",
"and",
"storing",
"the",
"raw",
"result",
"in",
"the",
"GzippedText",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/types/types.go#L31-L52 |
160,393 | jmoiron/sqlx | types/types.go | Value | func (j JSONText) Value() (driver.Value, error) {
var m json.RawMessage
var err = j.Unmarshal(&m)
if err != nil {
return []byte{}, err
}
return []byte(j), nil
} | go | func (j JSONText) Value() (driver.Value, error) {
var m json.RawMessage
var err = j.Unmarshal(&m)
if err != nil {
return []byte{}, err
}
return []byte(j), nil
} | [
"func",
"(",
"j",
"JSONText",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"var",
"m",
"json",
".",
"RawMessage",
"\n",
"var",
"err",
"=",
"j",
".",
"Unmarshal",
"(",
"&",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"byte",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"(",
"j",
")",
",",
"nil",
"\n",
"}"
] | // Value returns j as a value. This does a validating unmarshal into another
// RawMessage. If j is invalid json, it returns an error. | [
"Value",
"returns",
"j",
"as",
"a",
"value",
".",
"This",
"does",
"a",
"validating",
"unmarshal",
"into",
"another",
"RawMessage",
".",
"If",
"j",
"is",
"invalid",
"json",
"it",
"returns",
"an",
"error",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/types/types.go#L81-L88 |
160,394 | jmoiron/sqlx | types/types.go | Unmarshal | func (j *JSONText) Unmarshal(v interface{}) error {
if len(*j) == 0 {
*j = emptyJSON
}
return json.Unmarshal([]byte(*j), v)
} | go | func (j *JSONText) Unmarshal(v interface{}) error {
if len(*j) == 0 {
*j = emptyJSON
}
return json.Unmarshal([]byte(*j), v)
} | [
"func",
"(",
"j",
"*",
"JSONText",
")",
"Unmarshal",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"*",
"j",
")",
"==",
"0",
"{",
"*",
"j",
"=",
"emptyJSON",
"\n",
"}",
"\n",
"return",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"*",
"j",
")",
",",
"v",
")",
"\n",
"}"
] | // Unmarshal unmarshal's the json in j to v, as in json.Unmarshal. | [
"Unmarshal",
"unmarshal",
"s",
"the",
"json",
"in",
"j",
"to",
"v",
"as",
"in",
"json",
".",
"Unmarshal",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/types/types.go#L112-L117 |
160,395 | jmoiron/sqlx | types/types.go | Scan | func (b *BitBool) Scan(src interface{}) error {
v, ok := src.([]byte)
if !ok {
return errors.New("bad []byte type assertion")
}
*b = v[0] == 1
return nil
} | go | func (b *BitBool) Scan(src interface{}) error {
v, ok := src.([]byte)
if !ok {
return errors.New("bad []byte type assertion")
}
*b = v[0] == 1
return nil
} | [
"func",
"(",
"b",
"*",
"BitBool",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"v",
",",
"ok",
":=",
"src",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"*",
"b",
"=",
"v",
"[",
"0",
"]",
"==",
"1",
"\n",
"return",
"nil",
"\n",
"}"
] | // Scan implements the sql.Scanner interface,
// and turns the bitfield incoming from MySQL into a BitBool | [
"Scan",
"implements",
"the",
"sql",
".",
"Scanner",
"interface",
"and",
"turns",
"the",
"bitfield",
"incoming",
"from",
"MySQL",
"into",
"a",
"BitBool"
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/types/types.go#L165-L172 |
160,396 | jmoiron/sqlx | named.go | Exec | func (n *NamedStmt) Exec(arg interface{}) (sql.Result, error) {
args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
if err != nil {
return *new(sql.Result), err
}
return n.Stmt.Exec(args...)
} | go | func (n *NamedStmt) Exec(arg interface{}) (sql.Result, error) {
args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
if err != nil {
return *new(sql.Result), err
}
return n.Stmt.Exec(args...)
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"Exec",
"(",
"arg",
"interface",
"{",
"}",
")",
"(",
"sql",
".",
"Result",
",",
"error",
")",
"{",
"args",
",",
"err",
":=",
"bindAnyArgs",
"(",
"n",
".",
"Params",
",",
"arg",
",",
"n",
".",
"Stmt",
".",
"Mapper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"*",
"new",
"(",
"sql",
".",
"Result",
")",
",",
"err",
"\n",
"}",
"\n",
"return",
"n",
".",
"Stmt",
".",
"Exec",
"(",
"args",
"...",
")",
"\n",
"}"
] | // Exec executes a named statement using the struct passed.
// Any named placeholder parameters are replaced with fields from arg. | [
"Exec",
"executes",
"a",
"named",
"statement",
"using",
"the",
"struct",
"passed",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named.go#L42-L48 |
160,397 | jmoiron/sqlx | named.go | Query | func (n *NamedStmt) Query(arg interface{}) (*sql.Rows, error) {
args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
if err != nil {
return nil, err
}
return n.Stmt.Query(args...)
} | go | func (n *NamedStmt) Query(arg interface{}) (*sql.Rows, error) {
args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
if err != nil {
return nil, err
}
return n.Stmt.Query(args...)
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"Query",
"(",
"arg",
"interface",
"{",
"}",
")",
"(",
"*",
"sql",
".",
"Rows",
",",
"error",
")",
"{",
"args",
",",
"err",
":=",
"bindAnyArgs",
"(",
"n",
".",
"Params",
",",
"arg",
",",
"n",
".",
"Stmt",
".",
"Mapper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"n",
".",
"Stmt",
".",
"Query",
"(",
"args",
"...",
")",
"\n",
"}"
] | // Query executes a named statement using the struct argument, returning rows.
// Any named placeholder parameters are replaced with fields from arg. | [
"Query",
"executes",
"a",
"named",
"statement",
"using",
"the",
"struct",
"argument",
"returning",
"rows",
".",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named.go#L52-L58 |
160,398 | jmoiron/sqlx | named.go | MustExec | func (n *NamedStmt) MustExec(arg interface{}) sql.Result {
res, err := n.Exec(arg)
if err != nil {
panic(err)
}
return res
} | go | func (n *NamedStmt) MustExec(arg interface{}) sql.Result {
res, err := n.Exec(arg)
if err != nil {
panic(err)
}
return res
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"MustExec",
"(",
"arg",
"interface",
"{",
"}",
")",
"sql",
".",
"Result",
"{",
"res",
",",
"err",
":=",
"n",
".",
"Exec",
"(",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // MustExec execs a NamedStmt, panicing on error
// Any named placeholder parameters are replaced with fields from arg. | [
"MustExec",
"execs",
"a",
"NamedStmt",
"panicing",
"on",
"error",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named.go#L74-L80 |
160,399 | jmoiron/sqlx | named.go | Queryx | func (n *NamedStmt) Queryx(arg interface{}) (*Rows, error) {
r, err := n.Query(arg)
if err != nil {
return nil, err
}
return &Rows{Rows: r, Mapper: n.Stmt.Mapper, unsafe: isUnsafe(n)}, err
} | go | func (n *NamedStmt) Queryx(arg interface{}) (*Rows, error) {
r, err := n.Query(arg)
if err != nil {
return nil, err
}
return &Rows{Rows: r, Mapper: n.Stmt.Mapper, unsafe: isUnsafe(n)}, err
} | [
"func",
"(",
"n",
"*",
"NamedStmt",
")",
"Queryx",
"(",
"arg",
"interface",
"{",
"}",
")",
"(",
"*",
"Rows",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"n",
".",
"Query",
"(",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Rows",
"{",
"Rows",
":",
"r",
",",
"Mapper",
":",
"n",
".",
"Stmt",
".",
"Mapper",
",",
"unsafe",
":",
"isUnsafe",
"(",
"n",
")",
"}",
",",
"err",
"\n",
"}"
] | // Queryx using this NamedStmt
// Any named placeholder parameters are replaced with fields from arg. | [
"Queryx",
"using",
"this",
"NamedStmt",
"Any",
"named",
"placeholder",
"parameters",
"are",
"replaced",
"with",
"fields",
"from",
"arg",
"."
] | 38398a30ed8516ffda617a04c822de09df8a3ec5 | https://github.com/jmoiron/sqlx/blob/38398a30ed8516ffda617a04c822de09df8a3ec5/named.go#L84-L90 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.