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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
146,800
davecgh/go-spew
spew/format.go
constructOrigFormat
func (f *formatState) constructOrigFormat(verb rune) (format string) { buf := bytes.NewBuffer(percentBytes) for _, flag := range supportedFlags { if f.fs.Flag(int(flag)) { buf.WriteRune(flag) } } if width, ok := f.fs.Width(); ok { buf.WriteString(strconv.Itoa(width)) } if precision, ok := f.fs.Precision(); ok { buf.Write(precisionBytes) buf.WriteString(strconv.Itoa(precision)) } buf.WriteRune(verb) format = buf.String() return format }
go
func (f *formatState) constructOrigFormat(verb rune) (format string) { buf := bytes.NewBuffer(percentBytes) for _, flag := range supportedFlags { if f.fs.Flag(int(flag)) { buf.WriteRune(flag) } } if width, ok := f.fs.Width(); ok { buf.WriteString(strconv.Itoa(width)) } if precision, ok := f.fs.Precision(); ok { buf.Write(precisionBytes) buf.WriteString(strconv.Itoa(precision)) } buf.WriteRune(verb) format = buf.String() return format }
[ "func", "(", "f", "*", "formatState", ")", "constructOrigFormat", "(", "verb", "rune", ")", "(", "format", "string", ")", "{", "buf", ":=", "bytes", ".", "NewBuffer", "(", "percentBytes", ")", "\n\n", "for", "_", ",", "flag", ":=", "range", "supportedFlags", "{", "if", "f", ".", "fs", ".", "Flag", "(", "int", "(", "flag", ")", ")", "{", "buf", ".", "WriteRune", "(", "flag", ")", "\n", "}", "\n", "}", "\n\n", "if", "width", ",", "ok", ":=", "f", ".", "fs", ".", "Width", "(", ")", ";", "ok", "{", "buf", ".", "WriteString", "(", "strconv", ".", "Itoa", "(", "width", ")", ")", "\n", "}", "\n\n", "if", "precision", ",", "ok", ":=", "f", ".", "fs", ".", "Precision", "(", ")", ";", "ok", "{", "buf", ".", "Write", "(", "precisionBytes", ")", "\n", "buf", ".", "WriteString", "(", "strconv", ".", "Itoa", "(", "precision", ")", ")", "\n", "}", "\n\n", "buf", ".", "WriteRune", "(", "verb", ")", "\n\n", "format", "=", "buf", ".", "String", "(", ")", "\n", "return", "format", "\n", "}" ]
// constructOrigFormat recreates the original format string including precision // and width information to pass along to the standard fmt package. This allows // automatic deferral of all format strings this package doesn't support.
[ "constructOrigFormat", "recreates", "the", "original", "format", "string", "including", "precision", "and", "width", "information", "to", "pass", "along", "to", "the", "standard", "fmt", "package", ".", "This", "allows", "automatic", "deferral", "of", "all", "format", "strings", "this", "package", "doesn", "t", "support", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/format.go#L65-L87
146,801
davecgh/go-spew
spew/format.go
unpackValue
func (f *formatState) unpackValue(v reflect.Value) reflect.Value { if v.Kind() == reflect.Interface { f.ignoreNextType = false if !v.IsNil() { v = v.Elem() } } return v }
go
func (f *formatState) unpackValue(v reflect.Value) reflect.Value { if v.Kind() == reflect.Interface { f.ignoreNextType = false if !v.IsNil() { v = v.Elem() } } return v }
[ "func", "(", "f", "*", "formatState", ")", "unpackValue", "(", "v", "reflect", ".", "Value", ")", "reflect", ".", "Value", "{", "if", "v", ".", "Kind", "(", ")", "==", "reflect", ".", "Interface", "{", "f", ".", "ignoreNextType", "=", "false", "\n", "if", "!", "v", ".", "IsNil", "(", ")", "{", "v", "=", "v", ".", "Elem", "(", ")", "\n", "}", "\n", "}", "\n", "return", "v", "\n", "}" ]
// unpackValue returns values inside of non-nil interfaces when possible and // ensures that types for values which have been unpacked from an interface // are displayed when the show types flag is also set. // This is useful for data types like structs, arrays, slices, and maps which // can contain varying types packed inside an interface.
[ "unpackValue", "returns", "values", "inside", "of", "non", "-", "nil", "interfaces", "when", "possible", "and", "ensures", "that", "types", "for", "values", "which", "have", "been", "unpacked", "from", "an", "interface", "are", "displayed", "when", "the", "show", "types", "flag", "is", "also", "set", ".", "This", "is", "useful", "for", "data", "types", "like", "structs", "arrays", "slices", "and", "maps", "which", "can", "contain", "varying", "types", "packed", "inside", "an", "interface", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/format.go#L94-L102
146,802
davecgh/go-spew
spew/format.go
formatPtr
func (f *formatState) formatPtr(v reflect.Value) { // Display nil if top level pointer is nil. showTypes := f.fs.Flag('#') if v.IsNil() && (!showTypes || f.ignoreNextType) { f.fs.Write(nilAngleBytes) return } // Remove pointers at or below the current depth from map used to detect // circular refs. for k, depth := range f.pointers { if depth >= f.depth { delete(f.pointers, k) } } // Keep list of all dereferenced pointers to possibly show later. pointerChain := make([]uintptr, 0) // Figure out how many levels of indirection there are by derferencing // pointers and unpacking interfaces down the chain while detecting circular // references. nilFound := false cycleFound := false indirects := 0 ve := v for ve.Kind() == reflect.Ptr { if ve.IsNil() { nilFound = true break } indirects++ addr := ve.Pointer() pointerChain = append(pointerChain, addr) if pd, ok := f.pointers[addr]; ok && pd < f.depth { cycleFound = true indirects-- break } f.pointers[addr] = f.depth ve = ve.Elem() if ve.Kind() == reflect.Interface { if ve.IsNil() { nilFound = true break } ve = ve.Elem() } } // Display type or indirection level depending on flags. if showTypes && !f.ignoreNextType { f.fs.Write(openParenBytes) f.fs.Write(bytes.Repeat(asteriskBytes, indirects)) f.fs.Write([]byte(ve.Type().String())) f.fs.Write(closeParenBytes) } else { if nilFound || cycleFound { indirects += strings.Count(ve.Type().String(), "*") } f.fs.Write(openAngleBytes) f.fs.Write([]byte(strings.Repeat("*", indirects))) f.fs.Write(closeAngleBytes) } // Display pointer information depending on flags. if f.fs.Flag('+') && (len(pointerChain) > 0) { f.fs.Write(openParenBytes) for i, addr := range pointerChain { if i > 0 { f.fs.Write(pointerChainBytes) } printHexPtr(f.fs, addr) } f.fs.Write(closeParenBytes) } // Display dereferenced value. switch { case nilFound: f.fs.Write(nilAngleBytes) case cycleFound: f.fs.Write(circularShortBytes) default: f.ignoreNextType = true f.format(ve) } }
go
func (f *formatState) formatPtr(v reflect.Value) { // Display nil if top level pointer is nil. showTypes := f.fs.Flag('#') if v.IsNil() && (!showTypes || f.ignoreNextType) { f.fs.Write(nilAngleBytes) return } // Remove pointers at or below the current depth from map used to detect // circular refs. for k, depth := range f.pointers { if depth >= f.depth { delete(f.pointers, k) } } // Keep list of all dereferenced pointers to possibly show later. pointerChain := make([]uintptr, 0) // Figure out how many levels of indirection there are by derferencing // pointers and unpacking interfaces down the chain while detecting circular // references. nilFound := false cycleFound := false indirects := 0 ve := v for ve.Kind() == reflect.Ptr { if ve.IsNil() { nilFound = true break } indirects++ addr := ve.Pointer() pointerChain = append(pointerChain, addr) if pd, ok := f.pointers[addr]; ok && pd < f.depth { cycleFound = true indirects-- break } f.pointers[addr] = f.depth ve = ve.Elem() if ve.Kind() == reflect.Interface { if ve.IsNil() { nilFound = true break } ve = ve.Elem() } } // Display type or indirection level depending on flags. if showTypes && !f.ignoreNextType { f.fs.Write(openParenBytes) f.fs.Write(bytes.Repeat(asteriskBytes, indirects)) f.fs.Write([]byte(ve.Type().String())) f.fs.Write(closeParenBytes) } else { if nilFound || cycleFound { indirects += strings.Count(ve.Type().String(), "*") } f.fs.Write(openAngleBytes) f.fs.Write([]byte(strings.Repeat("*", indirects))) f.fs.Write(closeAngleBytes) } // Display pointer information depending on flags. if f.fs.Flag('+') && (len(pointerChain) > 0) { f.fs.Write(openParenBytes) for i, addr := range pointerChain { if i > 0 { f.fs.Write(pointerChainBytes) } printHexPtr(f.fs, addr) } f.fs.Write(closeParenBytes) } // Display dereferenced value. switch { case nilFound: f.fs.Write(nilAngleBytes) case cycleFound: f.fs.Write(circularShortBytes) default: f.ignoreNextType = true f.format(ve) } }
[ "func", "(", "f", "*", "formatState", ")", "formatPtr", "(", "v", "reflect", ".", "Value", ")", "{", "// Display nil if top level pointer is nil.", "showTypes", ":=", "f", ".", "fs", ".", "Flag", "(", "'#'", ")", "\n", "if", "v", ".", "IsNil", "(", ")", "&&", "(", "!", "showTypes", "||", "f", ".", "ignoreNextType", ")", "{", "f", ".", "fs", ".", "Write", "(", "nilAngleBytes", ")", "\n", "return", "\n", "}", "\n\n", "// Remove pointers at or below the current depth from map used to detect", "// circular refs.", "for", "k", ",", "depth", ":=", "range", "f", ".", "pointers", "{", "if", "depth", ">=", "f", ".", "depth", "{", "delete", "(", "f", ".", "pointers", ",", "k", ")", "\n", "}", "\n", "}", "\n\n", "// Keep list of all dereferenced pointers to possibly show later.", "pointerChain", ":=", "make", "(", "[", "]", "uintptr", ",", "0", ")", "\n\n", "// Figure out how many levels of indirection there are by derferencing", "// pointers and unpacking interfaces down the chain while detecting circular", "// references.", "nilFound", ":=", "false", "\n", "cycleFound", ":=", "false", "\n", "indirects", ":=", "0", "\n", "ve", ":=", "v", "\n", "for", "ve", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "if", "ve", ".", "IsNil", "(", ")", "{", "nilFound", "=", "true", "\n", "break", "\n", "}", "\n", "indirects", "++", "\n", "addr", ":=", "ve", ".", "Pointer", "(", ")", "\n", "pointerChain", "=", "append", "(", "pointerChain", ",", "addr", ")", "\n", "if", "pd", ",", "ok", ":=", "f", ".", "pointers", "[", "addr", "]", ";", "ok", "&&", "pd", "<", "f", ".", "depth", "{", "cycleFound", "=", "true", "\n", "indirects", "--", "\n", "break", "\n", "}", "\n", "f", ".", "pointers", "[", "addr", "]", "=", "f", ".", "depth", "\n\n", "ve", "=", "ve", ".", "Elem", "(", ")", "\n", "if", "ve", ".", "Kind", "(", ")", "==", "reflect", ".", "Interface", "{", "if", "ve", ".", "IsNil", "(", ")", "{", "nilFound", "=", "true", "\n", "break", "\n", "}", "\n", "ve", "=", "ve", ".", "Elem", "(", ")", "\n", "}", "\n", "}", "\n\n", "// Display type or indirection level depending on flags.", "if", "showTypes", "&&", "!", "f", ".", "ignoreNextType", "{", "f", ".", "fs", ".", "Write", "(", "openParenBytes", ")", "\n", "f", ".", "fs", ".", "Write", "(", "bytes", ".", "Repeat", "(", "asteriskBytes", ",", "indirects", ")", ")", "\n", "f", ".", "fs", ".", "Write", "(", "[", "]", "byte", "(", "ve", ".", "Type", "(", ")", ".", "String", "(", ")", ")", ")", "\n", "f", ".", "fs", ".", "Write", "(", "closeParenBytes", ")", "\n", "}", "else", "{", "if", "nilFound", "||", "cycleFound", "{", "indirects", "+=", "strings", ".", "Count", "(", "ve", ".", "Type", "(", ")", ".", "String", "(", ")", ",", "\"", "\"", ")", "\n", "}", "\n", "f", ".", "fs", ".", "Write", "(", "openAngleBytes", ")", "\n", "f", ".", "fs", ".", "Write", "(", "[", "]", "byte", "(", "strings", ".", "Repeat", "(", "\"", "\"", ",", "indirects", ")", ")", ")", "\n", "f", ".", "fs", ".", "Write", "(", "closeAngleBytes", ")", "\n", "}", "\n\n", "// Display pointer information depending on flags.", "if", "f", ".", "fs", ".", "Flag", "(", "'+'", ")", "&&", "(", "len", "(", "pointerChain", ")", ">", "0", ")", "{", "f", ".", "fs", ".", "Write", "(", "openParenBytes", ")", "\n", "for", "i", ",", "addr", ":=", "range", "pointerChain", "{", "if", "i", ">", "0", "{", "f", ".", "fs", ".", "Write", "(", "pointerChainBytes", ")", "\n", "}", "\n", "printHexPtr", "(", "f", ".", "fs", ",", "addr", ")", "\n", "}", "\n", "f", ".", "fs", ".", "Write", "(", "closeParenBytes", ")", "\n", "}", "\n\n", "// Display dereferenced value.", "switch", "{", "case", "nilFound", ":", "f", ".", "fs", ".", "Write", "(", "nilAngleBytes", ")", "\n\n", "case", "cycleFound", ":", "f", ".", "fs", ".", "Write", "(", "circularShortBytes", ")", "\n\n", "default", ":", "f", ".", "ignoreNextType", "=", "true", "\n", "f", ".", "format", "(", "ve", ")", "\n", "}", "\n", "}" ]
// formatPtr handles formatting of pointers by indirecting them as necessary.
[ "formatPtr", "handles", "formatting", "of", "pointers", "by", "indirecting", "them", "as", "necessary", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/format.go#L105-L195
146,803
davecgh/go-spew
spew/format.go
Format
func (f *formatState) Format(fs fmt.State, verb rune) { f.fs = fs // Use standard formatting for verbs that are not v. if verb != 'v' { format := f.constructOrigFormat(verb) fmt.Fprintf(fs, format, f.value) return } if f.value == nil { if fs.Flag('#') { fs.Write(interfaceBytes) } fs.Write(nilAngleBytes) return } f.format(reflect.ValueOf(f.value)) }
go
func (f *formatState) Format(fs fmt.State, verb rune) { f.fs = fs // Use standard formatting for verbs that are not v. if verb != 'v' { format := f.constructOrigFormat(verb) fmt.Fprintf(fs, format, f.value) return } if f.value == nil { if fs.Flag('#') { fs.Write(interfaceBytes) } fs.Write(nilAngleBytes) return } f.format(reflect.ValueOf(f.value)) }
[ "func", "(", "f", "*", "formatState", ")", "Format", "(", "fs", "fmt", ".", "State", ",", "verb", "rune", ")", "{", "f", ".", "fs", "=", "fs", "\n\n", "// Use standard formatting for verbs that are not v.", "if", "verb", "!=", "'v'", "{", "format", ":=", "f", ".", "constructOrigFormat", "(", "verb", ")", "\n", "fmt", ".", "Fprintf", "(", "fs", ",", "format", ",", "f", ".", "value", ")", "\n", "return", "\n", "}", "\n\n", "if", "f", ".", "value", "==", "nil", "{", "if", "fs", ".", "Flag", "(", "'#'", ")", "{", "fs", ".", "Write", "(", "interfaceBytes", ")", "\n", "}", "\n", "fs", ".", "Write", "(", "nilAngleBytes", ")", "\n", "return", "\n", "}", "\n\n", "f", ".", "format", "(", "reflect", ".", "ValueOf", "(", "f", ".", "value", ")", ")", "\n", "}" ]
// Format satisfies the fmt.Formatter interface. See NewFormatter for usage // details.
[ "Format", "satisfies", "the", "fmt", ".", "Formatter", "interface", ".", "See", "NewFormatter", "for", "usage", "details", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/format.go#L371-L390
146,804
davecgh/go-spew
spew/format.go
newFormatter
func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { fs := &formatState{value: v, cs: cs} fs.pointers = make(map[uintptr]int) return fs }
go
func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { fs := &formatState{value: v, cs: cs} fs.pointers = make(map[uintptr]int) return fs }
[ "func", "newFormatter", "(", "cs", "*", "ConfigState", ",", "v", "interface", "{", "}", ")", "fmt", ".", "Formatter", "{", "fs", ":=", "&", "formatState", "{", "value", ":", "v", ",", "cs", ":", "cs", "}", "\n", "fs", ".", "pointers", "=", "make", "(", "map", "[", "uintptr", "]", "int", ")", "\n", "return", "fs", "\n", "}" ]
// newFormatter is a helper function to consolidate the logic from the various // public methods which take varying config states.
[ "newFormatter", "is", "a", "helper", "function", "to", "consolidate", "the", "logic", "from", "the", "various", "public", "methods", "which", "take", "varying", "config", "states", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/format.go#L394-L398
146,805
davecgh/go-spew
spew/dump.go
indent
func (d *dumpState) indent() { if d.ignoreNextIndent { d.ignoreNextIndent = false return } d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) }
go
func (d *dumpState) indent() { if d.ignoreNextIndent { d.ignoreNextIndent = false return } d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) }
[ "func", "(", "d", "*", "dumpState", ")", "indent", "(", ")", "{", "if", "d", ".", "ignoreNextIndent", "{", "d", ".", "ignoreNextIndent", "=", "false", "\n", "return", "\n", "}", "\n", "d", ".", "w", ".", "Write", "(", "bytes", ".", "Repeat", "(", "[", "]", "byte", "(", "d", ".", "cs", ".", "Indent", ")", ",", "d", ".", "depth", ")", ")", "\n", "}" ]
// indent performs indentation according to the depth level and cs.Indent // option.
[ "indent", "performs", "indentation", "according", "to", "the", "depth", "level", "and", "cs", ".", "Indent", "option", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/dump.go#L62-L68
146,806
davecgh/go-spew
spew/dump.go
unpackValue
func (d *dumpState) unpackValue(v reflect.Value) reflect.Value { if v.Kind() == reflect.Interface && !v.IsNil() { v = v.Elem() } return v }
go
func (d *dumpState) unpackValue(v reflect.Value) reflect.Value { if v.Kind() == reflect.Interface && !v.IsNil() { v = v.Elem() } return v }
[ "func", "(", "d", "*", "dumpState", ")", "unpackValue", "(", "v", "reflect", ".", "Value", ")", "reflect", ".", "Value", "{", "if", "v", ".", "Kind", "(", ")", "==", "reflect", ".", "Interface", "&&", "!", "v", ".", "IsNil", "(", ")", "{", "v", "=", "v", ".", "Elem", "(", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// unpackValue returns values inside of non-nil interfaces when possible. // This is useful for data types like structs, arrays, slices, and maps which // can contain varying types packed inside an interface.
[ "unpackValue", "returns", "values", "inside", "of", "non", "-", "nil", "interfaces", "when", "possible", ".", "This", "is", "useful", "for", "data", "types", "like", "structs", "arrays", "slices", "and", "maps", "which", "can", "contain", "varying", "types", "packed", "inside", "an", "interface", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/dump.go#L73-L78
146,807
davecgh/go-spew
spew/dump.go
dumpPtr
func (d *dumpState) dumpPtr(v reflect.Value) { // Remove pointers at or below the current depth from map used to detect // circular refs. for k, depth := range d.pointers { if depth >= d.depth { delete(d.pointers, k) } } // Keep list of all dereferenced pointers to show later. pointerChain := make([]uintptr, 0) // Figure out how many levels of indirection there are by dereferencing // pointers and unpacking interfaces down the chain while detecting circular // references. nilFound := false cycleFound := false indirects := 0 ve := v for ve.Kind() == reflect.Ptr { if ve.IsNil() { nilFound = true break } indirects++ addr := ve.Pointer() pointerChain = append(pointerChain, addr) if pd, ok := d.pointers[addr]; ok && pd < d.depth { cycleFound = true indirects-- break } d.pointers[addr] = d.depth ve = ve.Elem() if ve.Kind() == reflect.Interface { if ve.IsNil() { nilFound = true break } ve = ve.Elem() } } // Display type information. d.w.Write(openParenBytes) d.w.Write(bytes.Repeat(asteriskBytes, indirects)) d.w.Write([]byte(ve.Type().String())) d.w.Write(closeParenBytes) // Display pointer information. if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 { d.w.Write(openParenBytes) for i, addr := range pointerChain { if i > 0 { d.w.Write(pointerChainBytes) } printHexPtr(d.w, addr) } d.w.Write(closeParenBytes) } // Display dereferenced value. d.w.Write(openParenBytes) switch { case nilFound: d.w.Write(nilAngleBytes) case cycleFound: d.w.Write(circularBytes) default: d.ignoreNextType = true d.dump(ve) } d.w.Write(closeParenBytes) }
go
func (d *dumpState) dumpPtr(v reflect.Value) { // Remove pointers at or below the current depth from map used to detect // circular refs. for k, depth := range d.pointers { if depth >= d.depth { delete(d.pointers, k) } } // Keep list of all dereferenced pointers to show later. pointerChain := make([]uintptr, 0) // Figure out how many levels of indirection there are by dereferencing // pointers and unpacking interfaces down the chain while detecting circular // references. nilFound := false cycleFound := false indirects := 0 ve := v for ve.Kind() == reflect.Ptr { if ve.IsNil() { nilFound = true break } indirects++ addr := ve.Pointer() pointerChain = append(pointerChain, addr) if pd, ok := d.pointers[addr]; ok && pd < d.depth { cycleFound = true indirects-- break } d.pointers[addr] = d.depth ve = ve.Elem() if ve.Kind() == reflect.Interface { if ve.IsNil() { nilFound = true break } ve = ve.Elem() } } // Display type information. d.w.Write(openParenBytes) d.w.Write(bytes.Repeat(asteriskBytes, indirects)) d.w.Write([]byte(ve.Type().String())) d.w.Write(closeParenBytes) // Display pointer information. if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 { d.w.Write(openParenBytes) for i, addr := range pointerChain { if i > 0 { d.w.Write(pointerChainBytes) } printHexPtr(d.w, addr) } d.w.Write(closeParenBytes) } // Display dereferenced value. d.w.Write(openParenBytes) switch { case nilFound: d.w.Write(nilAngleBytes) case cycleFound: d.w.Write(circularBytes) default: d.ignoreNextType = true d.dump(ve) } d.w.Write(closeParenBytes) }
[ "func", "(", "d", "*", "dumpState", ")", "dumpPtr", "(", "v", "reflect", ".", "Value", ")", "{", "// Remove pointers at or below the current depth from map used to detect", "// circular refs.", "for", "k", ",", "depth", ":=", "range", "d", ".", "pointers", "{", "if", "depth", ">=", "d", ".", "depth", "{", "delete", "(", "d", ".", "pointers", ",", "k", ")", "\n", "}", "\n", "}", "\n\n", "// Keep list of all dereferenced pointers to show later.", "pointerChain", ":=", "make", "(", "[", "]", "uintptr", ",", "0", ")", "\n\n", "// Figure out how many levels of indirection there are by dereferencing", "// pointers and unpacking interfaces down the chain while detecting circular", "// references.", "nilFound", ":=", "false", "\n", "cycleFound", ":=", "false", "\n", "indirects", ":=", "0", "\n", "ve", ":=", "v", "\n", "for", "ve", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "if", "ve", ".", "IsNil", "(", ")", "{", "nilFound", "=", "true", "\n", "break", "\n", "}", "\n", "indirects", "++", "\n", "addr", ":=", "ve", ".", "Pointer", "(", ")", "\n", "pointerChain", "=", "append", "(", "pointerChain", ",", "addr", ")", "\n", "if", "pd", ",", "ok", ":=", "d", ".", "pointers", "[", "addr", "]", ";", "ok", "&&", "pd", "<", "d", ".", "depth", "{", "cycleFound", "=", "true", "\n", "indirects", "--", "\n", "break", "\n", "}", "\n", "d", ".", "pointers", "[", "addr", "]", "=", "d", ".", "depth", "\n\n", "ve", "=", "ve", ".", "Elem", "(", ")", "\n", "if", "ve", ".", "Kind", "(", ")", "==", "reflect", ".", "Interface", "{", "if", "ve", ".", "IsNil", "(", ")", "{", "nilFound", "=", "true", "\n", "break", "\n", "}", "\n", "ve", "=", "ve", ".", "Elem", "(", ")", "\n", "}", "\n", "}", "\n\n", "// Display type information.", "d", ".", "w", ".", "Write", "(", "openParenBytes", ")", "\n", "d", ".", "w", ".", "Write", "(", "bytes", ".", "Repeat", "(", "asteriskBytes", ",", "indirects", ")", ")", "\n", "d", ".", "w", ".", "Write", "(", "[", "]", "byte", "(", "ve", ".", "Type", "(", ")", ".", "String", "(", ")", ")", ")", "\n", "d", ".", "w", ".", "Write", "(", "closeParenBytes", ")", "\n\n", "// Display pointer information.", "if", "!", "d", ".", "cs", ".", "DisablePointerAddresses", "&&", "len", "(", "pointerChain", ")", ">", "0", "{", "d", ".", "w", ".", "Write", "(", "openParenBytes", ")", "\n", "for", "i", ",", "addr", ":=", "range", "pointerChain", "{", "if", "i", ">", "0", "{", "d", ".", "w", ".", "Write", "(", "pointerChainBytes", ")", "\n", "}", "\n", "printHexPtr", "(", "d", ".", "w", ",", "addr", ")", "\n", "}", "\n", "d", ".", "w", ".", "Write", "(", "closeParenBytes", ")", "\n", "}", "\n\n", "// Display dereferenced value.", "d", ".", "w", ".", "Write", "(", "openParenBytes", ")", "\n", "switch", "{", "case", "nilFound", ":", "d", ".", "w", ".", "Write", "(", "nilAngleBytes", ")", "\n\n", "case", "cycleFound", ":", "d", ".", "w", ".", "Write", "(", "circularBytes", ")", "\n\n", "default", ":", "d", ".", "ignoreNextType", "=", "true", "\n", "d", ".", "dump", "(", "ve", ")", "\n", "}", "\n", "d", ".", "w", ".", "Write", "(", "closeParenBytes", ")", "\n", "}" ]
// dumpPtr handles formatting of pointers by indirecting them as necessary.
[ "dumpPtr", "handles", "formatting", "of", "pointers", "by", "indirecting", "them", "as", "necessary", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/dump.go#L81-L157
146,808
davecgh/go-spew
spew/dump.go
fdump
func fdump(cs *ConfigState, w io.Writer, a ...interface{}) { for _, arg := range a { if arg == nil { w.Write(interfaceBytes) w.Write(spaceBytes) w.Write(nilAngleBytes) w.Write(newlineBytes) continue } d := dumpState{w: w, cs: cs} d.pointers = make(map[uintptr]int) d.dump(reflect.ValueOf(arg)) d.w.Write(newlineBytes) } }
go
func fdump(cs *ConfigState, w io.Writer, a ...interface{}) { for _, arg := range a { if arg == nil { w.Write(interfaceBytes) w.Write(spaceBytes) w.Write(nilAngleBytes) w.Write(newlineBytes) continue } d := dumpState{w: w, cs: cs} d.pointers = make(map[uintptr]int) d.dump(reflect.ValueOf(arg)) d.w.Write(newlineBytes) } }
[ "func", "fdump", "(", "cs", "*", "ConfigState", ",", "w", "io", ".", "Writer", ",", "a", "...", "interface", "{", "}", ")", "{", "for", "_", ",", "arg", ":=", "range", "a", "{", "if", "arg", "==", "nil", "{", "w", ".", "Write", "(", "interfaceBytes", ")", "\n", "w", ".", "Write", "(", "spaceBytes", ")", "\n", "w", ".", "Write", "(", "nilAngleBytes", ")", "\n", "w", ".", "Write", "(", "newlineBytes", ")", "\n", "continue", "\n", "}", "\n\n", "d", ":=", "dumpState", "{", "w", ":", "w", ",", "cs", ":", "cs", "}", "\n", "d", ".", "pointers", "=", "make", "(", "map", "[", "uintptr", "]", "int", ")", "\n", "d", ".", "dump", "(", "reflect", ".", "ValueOf", "(", "arg", ")", ")", "\n", "d", ".", "w", ".", "Write", "(", "newlineBytes", ")", "\n", "}", "\n", "}" ]
// fdump is a helper function to consolidate the logic from the various public // methods which take varying writers and config states.
[ "fdump", "is", "a", "helper", "function", "to", "consolidate", "the", "logic", "from", "the", "various", "public", "methods", "which", "take", "varying", "writers", "and", "config", "states", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/dump.go#L453-L468
146,809
davecgh/go-spew
spew/dump.go
Sdump
func Sdump(a ...interface{}) string { var buf bytes.Buffer fdump(&Config, &buf, a...) return buf.String() }
go
func Sdump(a ...interface{}) string { var buf bytes.Buffer fdump(&Config, &buf, a...) return buf.String() }
[ "func", "Sdump", "(", "a", "...", "interface", "{", "}", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "fdump", "(", "&", "Config", ",", "&", "buf", ",", "a", "...", ")", "\n", "return", "buf", ".", "String", "(", ")", "\n", "}" ]
// Sdump returns a string with the passed arguments formatted exactly the same // as Dump.
[ "Sdump", "returns", "a", "string", "with", "the", "passed", "arguments", "formatted", "exactly", "the", "same", "as", "Dump", "." ]
d8f796af33cc11cb798c1aaeb27a4ebc5099927d
https://github.com/davecgh/go-spew/blob/d8f796af33cc11cb798c1aaeb27a4ebc5099927d/spew/dump.go#L478-L482
146,810
jackc/pgx
pgtype/uuid.go
parseUUID
func parseUUID(src string) (dst [16]byte, err error) { if len(src) < 36 { return dst, errors.Errorf("cannot parse UUID %v", src) } src = src[0:8] + src[9:13] + src[14:18] + src[19:23] + src[24:] buf, err := hex.DecodeString(src) if err != nil { return dst, err } copy(dst[:], buf) return dst, err }
go
func parseUUID(src string) (dst [16]byte, err error) { if len(src) < 36 { return dst, errors.Errorf("cannot parse UUID %v", src) } src = src[0:8] + src[9:13] + src[14:18] + src[19:23] + src[24:] buf, err := hex.DecodeString(src) if err != nil { return dst, err } copy(dst[:], buf) return dst, err }
[ "func", "parseUUID", "(", "src", "string", ")", "(", "dst", "[", "16", "]", "byte", ",", "err", "error", ")", "{", "if", "len", "(", "src", ")", "<", "36", "{", "return", "dst", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "src", ")", "\n", "}", "\n", "src", "=", "src", "[", "0", ":", "8", "]", "+", "src", "[", "9", ":", "13", "]", "+", "src", "[", "14", ":", "18", "]", "+", "src", "[", "19", ":", "23", "]", "+", "src", "[", "24", ":", "]", "\n", "buf", ",", "err", ":=", "hex", ".", "DecodeString", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "dst", ",", "err", "\n", "}", "\n\n", "copy", "(", "dst", "[", ":", "]", ",", "buf", ")", "\n", "return", "dst", ",", "err", "\n", "}" ]
// parseUUID converts a string UUID in standard form to a byte array.
[ "parseUUID", "converts", "a", "string", "UUID", "in", "standard", "form", "to", "a", "byte", "array", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/uuid.go#L89-L101
146,811
jackc/pgx
pgtype/uuid.go
encodeUUID
func encodeUUID(src [16]byte) string { return fmt.Sprintf("%x-%x-%x-%x-%x", src[0:4], src[4:6], src[6:8], src[8:10], src[10:16]) }
go
func encodeUUID(src [16]byte) string { return fmt.Sprintf("%x-%x-%x-%x-%x", src[0:4], src[4:6], src[6:8], src[8:10], src[10:16]) }
[ "func", "encodeUUID", "(", "src", "[", "16", "]", "byte", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "src", "[", "0", ":", "4", "]", ",", "src", "[", "4", ":", "6", "]", ",", "src", "[", "6", ":", "8", "]", ",", "src", "[", "8", ":", "10", "]", ",", "src", "[", "10", ":", "16", "]", ")", "\n", "}" ]
// encodeUUID converts a uuid byte array to UUID standard string form.
[ "encodeUUID", "converts", "a", "uuid", "byte", "array", "to", "UUID", "standard", "string", "form", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/uuid.go#L104-L106
146,812
jackc/pgx
pgtype/pgtype.go
DeepCopy
func (ci *ConnInfo) DeepCopy() *ConnInfo { ci2 := &ConnInfo{ oidToDataType: make(map[OID]*DataType, len(ci.oidToDataType)), nameToDataType: make(map[string]*DataType, len(ci.nameToDataType)), reflectTypeToDataType: make(map[reflect.Type]*DataType, len(ci.reflectTypeToDataType)), } for _, dt := range ci.oidToDataType { ci2.RegisterDataType(DataType{ Value: reflect.New(reflect.ValueOf(dt.Value).Elem().Type()).Interface().(Value), Name: dt.Name, OID: dt.OID, }) } return ci2 }
go
func (ci *ConnInfo) DeepCopy() *ConnInfo { ci2 := &ConnInfo{ oidToDataType: make(map[OID]*DataType, len(ci.oidToDataType)), nameToDataType: make(map[string]*DataType, len(ci.nameToDataType)), reflectTypeToDataType: make(map[reflect.Type]*DataType, len(ci.reflectTypeToDataType)), } for _, dt := range ci.oidToDataType { ci2.RegisterDataType(DataType{ Value: reflect.New(reflect.ValueOf(dt.Value).Elem().Type()).Interface().(Value), Name: dt.Name, OID: dt.OID, }) } return ci2 }
[ "func", "(", "ci", "*", "ConnInfo", ")", "DeepCopy", "(", ")", "*", "ConnInfo", "{", "ci2", ":=", "&", "ConnInfo", "{", "oidToDataType", ":", "make", "(", "map", "[", "OID", "]", "*", "DataType", ",", "len", "(", "ci", ".", "oidToDataType", ")", ")", ",", "nameToDataType", ":", "make", "(", "map", "[", "string", "]", "*", "DataType", ",", "len", "(", "ci", ".", "nameToDataType", ")", ")", ",", "reflectTypeToDataType", ":", "make", "(", "map", "[", "reflect", ".", "Type", "]", "*", "DataType", ",", "len", "(", "ci", ".", "reflectTypeToDataType", ")", ")", ",", "}", "\n\n", "for", "_", ",", "dt", ":=", "range", "ci", ".", "oidToDataType", "{", "ci2", ".", "RegisterDataType", "(", "DataType", "{", "Value", ":", "reflect", ".", "New", "(", "reflect", ".", "ValueOf", "(", "dt", ".", "Value", ")", ".", "Elem", "(", ")", ".", "Type", "(", ")", ")", ".", "Interface", "(", ")", ".", "(", "Value", ")", ",", "Name", ":", "dt", ".", "Name", ",", "OID", ":", "dt", ".", "OID", ",", "}", ")", "\n", "}", "\n\n", "return", "ci2", "\n", "}" ]
// DeepCopy makes a deep copy of the ConnInfo.
[ "DeepCopy", "makes", "a", "deep", "copy", "of", "the", "ConnInfo", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/pgtype.go#L192-L208
146,813
jackc/pgx
pgtype/timestamp.go
Set
func (dst *Timestamp) Set(src interface{}) error { if src == nil { *dst = Timestamp{Status: Null} return nil } switch value := src.(type) { case time.Time: *dst = Timestamp{Time: time.Date(value.Year(), value.Month(), value.Day(), value.Hour(), value.Minute(), value.Second(), value.Nanosecond(), time.UTC), Status: Present} default: if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } return errors.Errorf("cannot convert %v to Timestamp", value) } return nil }
go
func (dst *Timestamp) Set(src interface{}) error { if src == nil { *dst = Timestamp{Status: Null} return nil } switch value := src.(type) { case time.Time: *dst = Timestamp{Time: time.Date(value.Year(), value.Month(), value.Day(), value.Hour(), value.Minute(), value.Second(), value.Nanosecond(), time.UTC), Status: Present} default: if originalSrc, ok := underlyingTimeType(src); ok { return dst.Set(originalSrc) } return errors.Errorf("cannot convert %v to Timestamp", value) } return nil }
[ "func", "(", "dst", "*", "Timestamp", ")", "Set", "(", "src", "interface", "{", "}", ")", "error", "{", "if", "src", "==", "nil", "{", "*", "dst", "=", "Timestamp", "{", "Status", ":", "Null", "}", "\n", "return", "nil", "\n", "}", "\n\n", "switch", "value", ":=", "src", ".", "(", "type", ")", "{", "case", "time", ".", "Time", ":", "*", "dst", "=", "Timestamp", "{", "Time", ":", "time", ".", "Date", "(", "value", ".", "Year", "(", ")", ",", "value", ".", "Month", "(", ")", ",", "value", ".", "Day", "(", ")", ",", "value", ".", "Hour", "(", ")", ",", "value", ".", "Minute", "(", ")", ",", "value", ".", "Second", "(", ")", ",", "value", ".", "Nanosecond", "(", ")", ",", "time", ".", "UTC", ")", ",", "Status", ":", "Present", "}", "\n", "default", ":", "if", "originalSrc", ",", "ok", ":=", "underlyingTimeType", "(", "src", ")", ";", "ok", "{", "return", "dst", ".", "Set", "(", "originalSrc", ")", "\n", "}", "\n", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "value", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Set converts src into a Timestamp and stores in dst. If src is a // time.Time in a non-UTC time zone, the time zone is discarded.
[ "Set", "converts", "src", "into", "a", "Timestamp", "and", "stores", "in", "dst", ".", "If", "src", "is", "a", "time", ".", "Time", "in", "a", "non", "-", "UTC", "time", "zone", "the", "time", "zone", "is", "discarded", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/timestamp.go#L27-L44
146,814
jackc/pgx
pgtype/timestamp.go
DecodeText
func (dst *Timestamp) DecodeText(ci *ConnInfo, src []byte) error { if src == nil { *dst = Timestamp{Status: Null} return nil } sbuf := string(src) switch sbuf { case "infinity": *dst = Timestamp{Status: Present, InfinityModifier: Infinity} case "-infinity": *dst = Timestamp{Status: Present, InfinityModifier: -Infinity} default: tim, err := time.Parse(pgTimestampFormat, sbuf) if err != nil { return err } *dst = Timestamp{Time: tim, Status: Present} } return nil }
go
func (dst *Timestamp) DecodeText(ci *ConnInfo, src []byte) error { if src == nil { *dst = Timestamp{Status: Null} return nil } sbuf := string(src) switch sbuf { case "infinity": *dst = Timestamp{Status: Present, InfinityModifier: Infinity} case "-infinity": *dst = Timestamp{Status: Present, InfinityModifier: -Infinity} default: tim, err := time.Parse(pgTimestampFormat, sbuf) if err != nil { return err } *dst = Timestamp{Time: tim, Status: Present} } return nil }
[ "func", "(", "dst", "*", "Timestamp", ")", "DecodeText", "(", "ci", "*", "ConnInfo", ",", "src", "[", "]", "byte", ")", "error", "{", "if", "src", "==", "nil", "{", "*", "dst", "=", "Timestamp", "{", "Status", ":", "Null", "}", "\n", "return", "nil", "\n", "}", "\n\n", "sbuf", ":=", "string", "(", "src", ")", "\n", "switch", "sbuf", "{", "case", "\"", "\"", ":", "*", "dst", "=", "Timestamp", "{", "Status", ":", "Present", ",", "InfinityModifier", ":", "Infinity", "}", "\n", "case", "\"", "\"", ":", "*", "dst", "=", "Timestamp", "{", "Status", ":", "Present", ",", "InfinityModifier", ":", "-", "Infinity", "}", "\n", "default", ":", "tim", ",", "err", ":=", "time", ".", "Parse", "(", "pgTimestampFormat", ",", "sbuf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "*", "dst", "=", "Timestamp", "{", "Time", ":", "tim", ",", "Status", ":", "Present", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DecodeText decodes from src into dst. The decoded time is considered to // be in UTC.
[ "DecodeText", "decodes", "from", "src", "into", "dst", ".", "The", "decoded", "time", "is", "considered", "to", "be", "in", "UTC", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/timestamp.go#L84-L106
146,815
jackc/pgx
pgtype/timestamp.go
EncodeText
func (src *Timestamp) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil case Undefined: return nil, errUndefined } if src.Time.Location() != time.UTC { return nil, errors.Errorf("cannot encode non-UTC time into timestamp") } var s string switch src.InfinityModifier { case None: s = src.Time.Format(pgTimestampFormat) case Infinity: s = "infinity" case NegativeInfinity: s = "-infinity" } return append(buf, s...), nil }
go
func (src *Timestamp) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil case Undefined: return nil, errUndefined } if src.Time.Location() != time.UTC { return nil, errors.Errorf("cannot encode non-UTC time into timestamp") } var s string switch src.InfinityModifier { case None: s = src.Time.Format(pgTimestampFormat) case Infinity: s = "infinity" case NegativeInfinity: s = "-infinity" } return append(buf, s...), nil }
[ "func", "(", "src", "*", "Timestamp", ")", "EncodeText", "(", "ci", "*", "ConnInfo", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "switch", "src", ".", "Status", "{", "case", "Null", ":", "return", "nil", ",", "nil", "\n", "case", "Undefined", ":", "return", "nil", ",", "errUndefined", "\n", "}", "\n", "if", "src", ".", "Time", ".", "Location", "(", ")", "!=", "time", ".", "UTC", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "s", "string", "\n\n", "switch", "src", ".", "InfinityModifier", "{", "case", "None", ":", "s", "=", "src", ".", "Time", ".", "Format", "(", "pgTimestampFormat", ")", "\n", "case", "Infinity", ":", "s", "=", "\"", "\"", "\n", "case", "NegativeInfinity", ":", "s", "=", "\"", "\"", "\n", "}", "\n\n", "return", "append", "(", "buf", ",", "s", "...", ")", ",", "nil", "\n", "}" ]
// EncodeText writes the text encoding of src into w. If src.Time is not in // the UTC time zone it returns an error.
[ "EncodeText", "writes", "the", "text", "encoding", "of", "src", "into", "w", ".", "If", "src", ".", "Time", "is", "not", "in", "the", "UTC", "time", "zone", "it", "returns", "an", "error", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/timestamp.go#L138-L161
146,816
jackc/pgx
pgtype/timestamp.go
EncodeBinary
func (src *Timestamp) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil case Undefined: return nil, errUndefined } if src.Time.Location() != time.UTC { return nil, errors.Errorf("cannot encode non-UTC time into timestamp") } var microsecSinceY2K int64 switch src.InfinityModifier { case None: microsecSinceUnixEpoch := src.Time.Unix()*1000000 + int64(src.Time.Nanosecond())/1000 microsecSinceY2K = microsecSinceUnixEpoch - microsecFromUnixEpochToY2K case Infinity: microsecSinceY2K = infinityMicrosecondOffset case NegativeInfinity: microsecSinceY2K = negativeInfinityMicrosecondOffset } return pgio.AppendInt64(buf, microsecSinceY2K), nil }
go
func (src *Timestamp) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) { switch src.Status { case Null: return nil, nil case Undefined: return nil, errUndefined } if src.Time.Location() != time.UTC { return nil, errors.Errorf("cannot encode non-UTC time into timestamp") } var microsecSinceY2K int64 switch src.InfinityModifier { case None: microsecSinceUnixEpoch := src.Time.Unix()*1000000 + int64(src.Time.Nanosecond())/1000 microsecSinceY2K = microsecSinceUnixEpoch - microsecFromUnixEpochToY2K case Infinity: microsecSinceY2K = infinityMicrosecondOffset case NegativeInfinity: microsecSinceY2K = negativeInfinityMicrosecondOffset } return pgio.AppendInt64(buf, microsecSinceY2K), nil }
[ "func", "(", "src", "*", "Timestamp", ")", "EncodeBinary", "(", "ci", "*", "ConnInfo", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "switch", "src", ".", "Status", "{", "case", "Null", ":", "return", "nil", ",", "nil", "\n", "case", "Undefined", ":", "return", "nil", ",", "errUndefined", "\n", "}", "\n", "if", "src", ".", "Time", ".", "Location", "(", ")", "!=", "time", ".", "UTC", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "var", "microsecSinceY2K", "int64", "\n", "switch", "src", ".", "InfinityModifier", "{", "case", "None", ":", "microsecSinceUnixEpoch", ":=", "src", ".", "Time", ".", "Unix", "(", ")", "*", "1000000", "+", "int64", "(", "src", ".", "Time", ".", "Nanosecond", "(", ")", ")", "/", "1000", "\n", "microsecSinceY2K", "=", "microsecSinceUnixEpoch", "-", "microsecFromUnixEpochToY2K", "\n", "case", "Infinity", ":", "microsecSinceY2K", "=", "infinityMicrosecondOffset", "\n", "case", "NegativeInfinity", ":", "microsecSinceY2K", "=", "negativeInfinityMicrosecondOffset", "\n", "}", "\n\n", "return", "pgio", ".", "AppendInt64", "(", "buf", ",", "microsecSinceY2K", ")", ",", "nil", "\n", "}" ]
// EncodeBinary writes the binary encoding of src into w. If src.Time is not in // the UTC time zone it returns an error.
[ "EncodeBinary", "writes", "the", "binary", "encoding", "of", "src", "into", "w", ".", "If", "src", ".", "Time", "is", "not", "in", "the", "UTC", "time", "zone", "it", "returns", "an", "error", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/timestamp.go#L165-L188
146,817
jackc/pgx
batch.go
Queue
func (b *Batch) Queue(query string, arguments []interface{}, parameterOIDs []pgtype.OID, resultFormatCodes []int16) { b.items = append(b.items, &batchItem{ query: query, arguments: arguments, parameterOIDs: parameterOIDs, resultFormatCodes: resultFormatCodes, }) }
go
func (b *Batch) Queue(query string, arguments []interface{}, parameterOIDs []pgtype.OID, resultFormatCodes []int16) { b.items = append(b.items, &batchItem{ query: query, arguments: arguments, parameterOIDs: parameterOIDs, resultFormatCodes: resultFormatCodes, }) }
[ "func", "(", "b", "*", "Batch", ")", "Queue", "(", "query", "string", ",", "arguments", "[", "]", "interface", "{", "}", ",", "parameterOIDs", "[", "]", "pgtype", ".", "OID", ",", "resultFormatCodes", "[", "]", "int16", ")", "{", "b", ".", "items", "=", "append", "(", "b", ".", "items", ",", "&", "batchItem", "{", "query", ":", "query", ",", "arguments", ":", "arguments", ",", "parameterOIDs", ":", "parameterOIDs", ",", "resultFormatCodes", ":", "resultFormatCodes", ",", "}", ")", "\n", "}" ]
// Queue queues a query to batch b. parameterOIDs are required if there are // parameters and query is not the name of a prepared statement. // resultFormatCodes are required if there is a result.
[ "Queue", "queues", "a", "query", "to", "batch", "b", ".", "parameterOIDs", "are", "required", "if", "there", "are", "parameters", "and", "query", "is", "not", "the", "name", "of", "a", "prepared", "statement", ".", "resultFormatCodes", "are", "required", "if", "there", "is", "a", "result", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/batch.go#L49-L56
146,818
jackc/pgx
batch.go
ExecResults
func (b *Batch) ExecResults() (CommandTag, error) { if b.err != nil { return "", b.err } select { case <-b.ctx.Done(): b.die(b.ctx.Err()) return "", b.ctx.Err() default: } if err := b.ensureCommandComplete(); err != nil { b.die(err) return "", err } b.resultsRead++ b.pendingCommandComplete = true for { msg, err := b.conn.rxMsg() if err != nil { return "", err } switch msg := msg.(type) { case *pgproto3.CommandComplete: b.pendingCommandComplete = false return CommandTag(msg.CommandTag), nil default: if err := b.conn.processContextFreeMsg(msg); err != nil { return "", err } } } }
go
func (b *Batch) ExecResults() (CommandTag, error) { if b.err != nil { return "", b.err } select { case <-b.ctx.Done(): b.die(b.ctx.Err()) return "", b.ctx.Err() default: } if err := b.ensureCommandComplete(); err != nil { b.die(err) return "", err } b.resultsRead++ b.pendingCommandComplete = true for { msg, err := b.conn.rxMsg() if err != nil { return "", err } switch msg := msg.(type) { case *pgproto3.CommandComplete: b.pendingCommandComplete = false return CommandTag(msg.CommandTag), nil default: if err := b.conn.processContextFreeMsg(msg); err != nil { return "", err } } } }
[ "func", "(", "b", "*", "Batch", ")", "ExecResults", "(", ")", "(", "CommandTag", ",", "error", ")", "{", "if", "b", ".", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "b", ".", "err", "\n", "}", "\n\n", "select", "{", "case", "<-", "b", ".", "ctx", ".", "Done", "(", ")", ":", "b", ".", "die", "(", "b", ".", "ctx", ".", "Err", "(", ")", ")", "\n", "return", "\"", "\"", ",", "b", ".", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "}", "\n\n", "if", "err", ":=", "b", ".", "ensureCommandComplete", "(", ")", ";", "err", "!=", "nil", "{", "b", ".", "die", "(", "err", ")", "\n", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "b", ".", "resultsRead", "++", "\n\n", "b", ".", "pendingCommandComplete", "=", "true", "\n\n", "for", "{", "msg", ",", "err", ":=", "b", ".", "conn", ".", "rxMsg", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "switch", "msg", ":=", "msg", ".", "(", "type", ")", "{", "case", "*", "pgproto3", ".", "CommandComplete", ":", "b", ".", "pendingCommandComplete", "=", "false", "\n", "return", "CommandTag", "(", "msg", ".", "CommandTag", ")", ",", "nil", "\n", "default", ":", "if", "err", ":=", "b", ".", "conn", ".", "processContextFreeMsg", "(", "msg", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// ExecResults reads the results from the next query in the batch as if the // query has been sent with Exec.
[ "ExecResults", "reads", "the", "results", "from", "the", "next", "query", "in", "the", "batch", "as", "if", "the", "query", "has", "been", "sent", "with", "Exec", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/batch.go#L163-L200
146,819
jackc/pgx
batch.go
QueryResults
func (b *Batch) QueryResults() (*Rows, error) { rows := b.conn.getRows("batch query", nil) if b.err != nil { rows.fatal(b.err) return rows, b.err } select { case <-b.ctx.Done(): b.die(b.ctx.Err()) rows.fatal(b.err) return rows, b.ctx.Err() default: } if err := b.ensureCommandComplete(); err != nil { b.die(err) rows.fatal(err) return rows, err } b.resultsRead++ b.pendingCommandComplete = true fieldDescriptions, err := b.conn.readUntilRowDescription() if err != nil { b.die(err) rows.fatal(b.err) return rows, err } rows.batch = b rows.fields = fieldDescriptions return rows, nil }
go
func (b *Batch) QueryResults() (*Rows, error) { rows := b.conn.getRows("batch query", nil) if b.err != nil { rows.fatal(b.err) return rows, b.err } select { case <-b.ctx.Done(): b.die(b.ctx.Err()) rows.fatal(b.err) return rows, b.ctx.Err() default: } if err := b.ensureCommandComplete(); err != nil { b.die(err) rows.fatal(err) return rows, err } b.resultsRead++ b.pendingCommandComplete = true fieldDescriptions, err := b.conn.readUntilRowDescription() if err != nil { b.die(err) rows.fatal(b.err) return rows, err } rows.batch = b rows.fields = fieldDescriptions return rows, nil }
[ "func", "(", "b", "*", "Batch", ")", "QueryResults", "(", ")", "(", "*", "Rows", ",", "error", ")", "{", "rows", ":=", "b", ".", "conn", ".", "getRows", "(", "\"", "\"", ",", "nil", ")", "\n\n", "if", "b", ".", "err", "!=", "nil", "{", "rows", ".", "fatal", "(", "b", ".", "err", ")", "\n", "return", "rows", ",", "b", ".", "err", "\n", "}", "\n\n", "select", "{", "case", "<-", "b", ".", "ctx", ".", "Done", "(", ")", ":", "b", ".", "die", "(", "b", ".", "ctx", ".", "Err", "(", ")", ")", "\n", "rows", ".", "fatal", "(", "b", ".", "err", ")", "\n", "return", "rows", ",", "b", ".", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "}", "\n\n", "if", "err", ":=", "b", ".", "ensureCommandComplete", "(", ")", ";", "err", "!=", "nil", "{", "b", ".", "die", "(", "err", ")", "\n", "rows", ".", "fatal", "(", "err", ")", "\n", "return", "rows", ",", "err", "\n", "}", "\n\n", "b", ".", "resultsRead", "++", "\n\n", "b", ".", "pendingCommandComplete", "=", "true", "\n\n", "fieldDescriptions", ",", "err", ":=", "b", ".", "conn", ".", "readUntilRowDescription", "(", ")", "\n", "if", "err", "!=", "nil", "{", "b", ".", "die", "(", "err", ")", "\n", "rows", ".", "fatal", "(", "b", ".", "err", ")", "\n", "return", "rows", ",", "err", "\n", "}", "\n\n", "rows", ".", "batch", "=", "b", "\n", "rows", ".", "fields", "=", "fieldDescriptions", "\n", "return", "rows", ",", "nil", "\n", "}" ]
// QueryResults reads the results from the next query in the batch as if the // query has been sent with Query.
[ "QueryResults", "reads", "the", "results", "from", "the", "next", "query", "in", "the", "batch", "as", "if", "the", "query", "has", "been", "sent", "with", "Query", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/batch.go#L204-L240
146,820
jackc/pgx
batch.go
QueryRowResults
func (b *Batch) QueryRowResults() *Row { rows, _ := b.QueryResults() return (*Row)(rows) }
go
func (b *Batch) QueryRowResults() *Row { rows, _ := b.QueryResults() return (*Row)(rows) }
[ "func", "(", "b", "*", "Batch", ")", "QueryRowResults", "(", ")", "*", "Row", "{", "rows", ",", "_", ":=", "b", ".", "QueryResults", "(", ")", "\n", "return", "(", "*", "Row", ")", "(", "rows", ")", "\n\n", "}" ]
// QueryRowResults reads the results from the next query in the batch as if the // query has been sent with QueryRow.
[ "QueryRowResults", "reads", "the", "results", "from", "the", "next", "query", "in", "the", "batch", "as", "if", "the", "query", "has", "been", "sent", "with", "QueryRow", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/batch.go#L244-L248
146,821
jackc/pgx
batch.go
Close
func (b *Batch) Close() (err error) { if b.err != nil { return b.err } defer func() { err = b.conn.termContext(err) if b.conn != nil && b.connPool != nil { b.connPool.Release(b.conn) } }() for i := b.resultsRead; i < len(b.items); i++ { if _, err = b.ExecResults(); err != nil { return err } } if err = b.conn.ensureConnectionReadyForQuery(); err != nil { return err } return nil }
go
func (b *Batch) Close() (err error) { if b.err != nil { return b.err } defer func() { err = b.conn.termContext(err) if b.conn != nil && b.connPool != nil { b.connPool.Release(b.conn) } }() for i := b.resultsRead; i < len(b.items); i++ { if _, err = b.ExecResults(); err != nil { return err } } if err = b.conn.ensureConnectionReadyForQuery(); err != nil { return err } return nil }
[ "func", "(", "b", "*", "Batch", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "if", "b", ".", "err", "!=", "nil", "{", "return", "b", ".", "err", "\n", "}", "\n\n", "defer", "func", "(", ")", "{", "err", "=", "b", ".", "conn", ".", "termContext", "(", "err", ")", "\n", "if", "b", ".", "conn", "!=", "nil", "&&", "b", ".", "connPool", "!=", "nil", "{", "b", ".", "connPool", ".", "Release", "(", "b", ".", "conn", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "for", "i", ":=", "b", ".", "resultsRead", ";", "i", "<", "len", "(", "b", ".", "items", ")", ";", "i", "++", "{", "if", "_", ",", "err", "=", "b", ".", "ExecResults", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "err", "=", "b", ".", "conn", ".", "ensureConnectionReadyForQuery", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Close closes the batch operation. Any error that occured during a batch // operation may have made it impossible to resyncronize the connection with the // server. In this case the underlying connection will have been closed.
[ "Close", "closes", "the", "batch", "operation", ".", "Any", "error", "that", "occured", "during", "a", "batch", "operation", "may", "have", "made", "it", "impossible", "to", "resyncronize", "the", "connection", "with", "the", "server", ".", "In", "this", "case", "the", "underlying", "connection", "will", "have", "been", "closed", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/batch.go#L253-L276
146,822
jackc/pgx
tx.go
Begin
func (c *Conn) Begin() (*Tx, error) { return c.BeginEx(context.Background(), nil) }
go
func (c *Conn) Begin() (*Tx, error) { return c.BeginEx(context.Background(), nil) }
[ "func", "(", "c", "*", "Conn", ")", "Begin", "(", ")", "(", "*", "Tx", ",", "error", ")", "{", "return", "c", ".", "BeginEx", "(", "context", ".", "Background", "(", ")", ",", "nil", ")", "\n", "}" ]
// Begin starts a transaction with the default transaction mode for the // current connection. To use a specific transaction mode see BeginEx.
[ "Begin", "starts", "a", "transaction", "with", "the", "default", "transaction", "mode", "for", "the", "current", "connection", ".", "To", "use", "a", "specific", "transaction", "mode", "see", "BeginEx", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/tx.go#L84-L86
146,823
jackc/pgx
tx.go
CommitEx
func (tx *Tx) CommitEx(ctx context.Context) error { if tx.status != TxStatusInProgress { return ErrTxClosed } commandTag, err := tx.conn.ExecEx(ctx, "commit", nil) if err == nil && commandTag == "COMMIT" { tx.status = TxStatusCommitSuccess } else if err == nil && commandTag == "ROLLBACK" { tx.status = TxStatusCommitFailure tx.err = ErrTxCommitRollback } else { tx.status = TxStatusCommitFailure tx.err = err // A commit failure leaves the connection in an undefined state tx.conn.die(errors.New("commit failed")) } if tx.connPool != nil { tx.connPool.Release(tx.conn) } return tx.err }
go
func (tx *Tx) CommitEx(ctx context.Context) error { if tx.status != TxStatusInProgress { return ErrTxClosed } commandTag, err := tx.conn.ExecEx(ctx, "commit", nil) if err == nil && commandTag == "COMMIT" { tx.status = TxStatusCommitSuccess } else if err == nil && commandTag == "ROLLBACK" { tx.status = TxStatusCommitFailure tx.err = ErrTxCommitRollback } else { tx.status = TxStatusCommitFailure tx.err = err // A commit failure leaves the connection in an undefined state tx.conn.die(errors.New("commit failed")) } if tx.connPool != nil { tx.connPool.Release(tx.conn) } return tx.err }
[ "func", "(", "tx", "*", "Tx", ")", "CommitEx", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "tx", ".", "status", "!=", "TxStatusInProgress", "{", "return", "ErrTxClosed", "\n", "}", "\n\n", "commandTag", ",", "err", ":=", "tx", ".", "conn", ".", "ExecEx", "(", "ctx", ",", "\"", "\"", ",", "nil", ")", "\n", "if", "err", "==", "nil", "&&", "commandTag", "==", "\"", "\"", "{", "tx", ".", "status", "=", "TxStatusCommitSuccess", "\n", "}", "else", "if", "err", "==", "nil", "&&", "commandTag", "==", "\"", "\"", "{", "tx", ".", "status", "=", "TxStatusCommitFailure", "\n", "tx", ".", "err", "=", "ErrTxCommitRollback", "\n", "}", "else", "{", "tx", ".", "status", "=", "TxStatusCommitFailure", "\n", "tx", ".", "err", "=", "err", "\n", "// A commit failure leaves the connection in an undefined state", "tx", ".", "conn", ".", "die", "(", "errors", ".", "New", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "if", "tx", ".", "connPool", "!=", "nil", "{", "tx", ".", "connPool", ".", "Release", "(", "tx", ".", "conn", ")", "\n", "}", "\n\n", "return", "tx", ".", "err", "\n", "}" ]
// CommitEx commits the transaction with a context.
[ "CommitEx", "commits", "the", "transaction", "with", "a", "context", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/tx.go#L120-L143
146,824
jackc/pgx
tx.go
RollbackEx
func (tx *Tx) RollbackEx(ctx context.Context) error { if tx.status != TxStatusInProgress { return ErrTxClosed } _, tx.err = tx.conn.ExecEx(ctx, "rollback", nil) if tx.err == nil { tx.status = TxStatusRollbackSuccess } else { tx.status = TxStatusRollbackFailure // A rollback failure leaves the connection in an undefined state tx.conn.die(errors.New("rollback failed")) } if tx.connPool != nil { tx.connPool.Release(tx.conn) } return tx.err }
go
func (tx *Tx) RollbackEx(ctx context.Context) error { if tx.status != TxStatusInProgress { return ErrTxClosed } _, tx.err = tx.conn.ExecEx(ctx, "rollback", nil) if tx.err == nil { tx.status = TxStatusRollbackSuccess } else { tx.status = TxStatusRollbackFailure // A rollback failure leaves the connection in an undefined state tx.conn.die(errors.New("rollback failed")) } if tx.connPool != nil { tx.connPool.Release(tx.conn) } return tx.err }
[ "func", "(", "tx", "*", "Tx", ")", "RollbackEx", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "tx", ".", "status", "!=", "TxStatusInProgress", "{", "return", "ErrTxClosed", "\n", "}", "\n\n", "_", ",", "tx", ".", "err", "=", "tx", ".", "conn", ".", "ExecEx", "(", "ctx", ",", "\"", "\"", ",", "nil", ")", "\n", "if", "tx", ".", "err", "==", "nil", "{", "tx", ".", "status", "=", "TxStatusRollbackSuccess", "\n", "}", "else", "{", "tx", ".", "status", "=", "TxStatusRollbackFailure", "\n", "// A rollback failure leaves the connection in an undefined state", "tx", ".", "conn", ".", "die", "(", "errors", ".", "New", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "if", "tx", ".", "connPool", "!=", "nil", "{", "tx", ".", "connPool", ".", "Release", "(", "tx", ".", "conn", ")", "\n", "}", "\n\n", "return", "tx", ".", "err", "\n", "}" ]
// RollbackEx is the context version of Rollback
[ "RollbackEx", "is", "the", "context", "version", "of", "Rollback" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/tx.go#L156-L175
146,825
jackc/pgx
pgtype/convert.go
underlyingNumberType
func underlyingNumberType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return nil, false } convVal := refVal.Elem().Interface() return convVal, true case reflect.Int: convVal := int(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Int8: convVal := int8(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Int16: convVal := int16(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Int32: convVal := int32(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Int64: convVal := int64(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint: convVal := uint(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint8: convVal := uint8(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint16: convVal := uint16(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint32: convVal := uint32(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint64: convVal := uint64(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Float32: convVal := float32(refVal.Float()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Float64: convVal := refVal.Float() return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.String: convVal := refVal.String() return convVal, reflect.TypeOf(convVal) != refVal.Type() } return nil, false }
go
func underlyingNumberType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return nil, false } convVal := refVal.Elem().Interface() return convVal, true case reflect.Int: convVal := int(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Int8: convVal := int8(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Int16: convVal := int16(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Int32: convVal := int32(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Int64: convVal := int64(refVal.Int()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint: convVal := uint(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint8: convVal := uint8(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint16: convVal := uint16(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint32: convVal := uint32(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Uint64: convVal := uint64(refVal.Uint()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Float32: convVal := float32(refVal.Float()) return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.Float64: convVal := refVal.Float() return convVal, reflect.TypeOf(convVal) != refVal.Type() case reflect.String: convVal := refVal.String() return convVal, reflect.TypeOf(convVal) != refVal.Type() } return nil, false }
[ "func", "underlyingNumberType", "(", "val", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "refVal", ":=", "reflect", ".", "ValueOf", "(", "val", ")", "\n\n", "switch", "refVal", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Ptr", ":", "if", "refVal", ".", "IsNil", "(", ")", "{", "return", "nil", ",", "false", "\n", "}", "\n", "convVal", ":=", "refVal", ".", "Elem", "(", ")", ".", "Interface", "(", ")", "\n", "return", "convVal", ",", "true", "\n", "case", "reflect", ".", "Int", ":", "convVal", ":=", "int", "(", "refVal", ".", "Int", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Int8", ":", "convVal", ":=", "int8", "(", "refVal", ".", "Int", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Int16", ":", "convVal", ":=", "int16", "(", "refVal", ".", "Int", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Int32", ":", "convVal", ":=", "int32", "(", "refVal", ".", "Int", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Int64", ":", "convVal", ":=", "int64", "(", "refVal", ".", "Int", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Uint", ":", "convVal", ":=", "uint", "(", "refVal", ".", "Uint", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Uint8", ":", "convVal", ":=", "uint8", "(", "refVal", ".", "Uint", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Uint16", ":", "convVal", ":=", "uint16", "(", "refVal", ".", "Uint", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Uint32", ":", "convVal", ":=", "uint32", "(", "refVal", ".", "Uint", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Uint64", ":", "convVal", ":=", "uint64", "(", "refVal", ".", "Uint", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Float32", ":", "convVal", ":=", "float32", "(", "refVal", ".", "Float", "(", ")", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "Float64", ":", "convVal", ":=", "refVal", ".", "Float", "(", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "case", "reflect", ".", "String", ":", "convVal", ":=", "refVal", ".", "String", "(", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "}", "\n\n", "return", "nil", ",", "false", "\n", "}" ]
// underlyingNumberType gets the underlying type that can be converted to Int2, Int4, Int8, Float4, or Float8
[ "underlyingNumberType", "gets", "the", "underlying", "type", "that", "can", "be", "converted", "to", "Int2", "Int4", "Int8", "Float4", "or", "Float8" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/convert.go#L16-L68
146,826
jackc/pgx
pgtype/convert.go
underlyingBoolType
func underlyingBoolType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return nil, false } convVal := refVal.Elem().Interface() return convVal, true case reflect.Bool: convVal := refVal.Bool() return convVal, reflect.TypeOf(convVal) != refVal.Type() } return nil, false }
go
func underlyingBoolType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return nil, false } convVal := refVal.Elem().Interface() return convVal, true case reflect.Bool: convVal := refVal.Bool() return convVal, reflect.TypeOf(convVal) != refVal.Type() } return nil, false }
[ "func", "underlyingBoolType", "(", "val", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "refVal", ":=", "reflect", ".", "ValueOf", "(", "val", ")", "\n\n", "switch", "refVal", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Ptr", ":", "if", "refVal", ".", "IsNil", "(", ")", "{", "return", "nil", ",", "false", "\n", "}", "\n", "convVal", ":=", "refVal", ".", "Elem", "(", ")", ".", "Interface", "(", ")", "\n", "return", "convVal", ",", "true", "\n", "case", "reflect", ".", "Bool", ":", "convVal", ":=", "refVal", ".", "Bool", "(", ")", "\n", "return", "convVal", ",", "reflect", ".", "TypeOf", "(", "convVal", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "}", "\n\n", "return", "nil", ",", "false", "\n", "}" ]
// underlyingBoolType gets the underlying type that can be converted to Bool
[ "underlyingBoolType", "gets", "the", "underlying", "type", "that", "can", "be", "converted", "to", "Bool" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/convert.go#L71-L87
146,827
jackc/pgx
pgtype/convert.go
underlyingPtrType
func underlyingPtrType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return nil, false } convVal := refVal.Elem().Interface() return convVal, true } return nil, false }
go
func underlyingPtrType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return nil, false } convVal := refVal.Elem().Interface() return convVal, true } return nil, false }
[ "func", "underlyingPtrType", "(", "val", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "refVal", ":=", "reflect", ".", "ValueOf", "(", "val", ")", "\n\n", "switch", "refVal", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Ptr", ":", "if", "refVal", ".", "IsNil", "(", ")", "{", "return", "nil", ",", "false", "\n", "}", "\n", "convVal", ":=", "refVal", ".", "Elem", "(", ")", ".", "Interface", "(", ")", "\n", "return", "convVal", ",", "true", "\n", "}", "\n\n", "return", "nil", ",", "false", "\n", "}" ]
// underlyingPtrType dereferences a pointer
[ "underlyingPtrType", "dereferences", "a", "pointer" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/convert.go#L130-L143
146,828
jackc/pgx
pgtype/convert.go
underlyingTimeType
func underlyingTimeType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return time.Time{}, false } convVal := refVal.Elem().Interface() return convVal, true } timeType := reflect.TypeOf(time.Time{}) if refVal.Type().ConvertibleTo(timeType) { return refVal.Convert(timeType).Interface(), true } return time.Time{}, false }
go
func underlyingTimeType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return time.Time{}, false } convVal := refVal.Elem().Interface() return convVal, true } timeType := reflect.TypeOf(time.Time{}) if refVal.Type().ConvertibleTo(timeType) { return refVal.Convert(timeType).Interface(), true } return time.Time{}, false }
[ "func", "underlyingTimeType", "(", "val", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "refVal", ":=", "reflect", ".", "ValueOf", "(", "val", ")", "\n\n", "switch", "refVal", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Ptr", ":", "if", "refVal", ".", "IsNil", "(", ")", "{", "return", "time", ".", "Time", "{", "}", ",", "false", "\n", "}", "\n", "convVal", ":=", "refVal", ".", "Elem", "(", ")", ".", "Interface", "(", ")", "\n", "return", "convVal", ",", "true", "\n", "}", "\n\n", "timeType", ":=", "reflect", ".", "TypeOf", "(", "time", ".", "Time", "{", "}", ")", "\n", "if", "refVal", ".", "Type", "(", ")", ".", "ConvertibleTo", "(", "timeType", ")", "{", "return", "refVal", ".", "Convert", "(", "timeType", ")", ".", "Interface", "(", ")", ",", "true", "\n", "}", "\n\n", "return", "time", ".", "Time", "{", "}", ",", "false", "\n", "}" ]
// underlyingTimeType gets the underlying type that can be converted to time.Time
[ "underlyingTimeType", "gets", "the", "underlying", "type", "that", "can", "be", "converted", "to", "time", ".", "Time" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/convert.go#L146-L164
146,829
jackc/pgx
pgtype/convert.go
underlyingSliceType
func underlyingSliceType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return nil, false } convVal := refVal.Elem().Interface() return convVal, true case reflect.Slice: baseSliceType := reflect.SliceOf(refVal.Type().Elem()) if refVal.Type().ConvertibleTo(baseSliceType) { convVal := refVal.Convert(baseSliceType) return convVal.Interface(), reflect.TypeOf(convVal.Interface()) != refVal.Type() } } return nil, false }
go
func underlyingSliceType(val interface{}) (interface{}, bool) { refVal := reflect.ValueOf(val) switch refVal.Kind() { case reflect.Ptr: if refVal.IsNil() { return nil, false } convVal := refVal.Elem().Interface() return convVal, true case reflect.Slice: baseSliceType := reflect.SliceOf(refVal.Type().Elem()) if refVal.Type().ConvertibleTo(baseSliceType) { convVal := refVal.Convert(baseSliceType) return convVal.Interface(), reflect.TypeOf(convVal.Interface()) != refVal.Type() } } return nil, false }
[ "func", "underlyingSliceType", "(", "val", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "refVal", ":=", "reflect", ".", "ValueOf", "(", "val", ")", "\n\n", "switch", "refVal", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Ptr", ":", "if", "refVal", ".", "IsNil", "(", ")", "{", "return", "nil", ",", "false", "\n", "}", "\n", "convVal", ":=", "refVal", ".", "Elem", "(", ")", ".", "Interface", "(", ")", "\n", "return", "convVal", ",", "true", "\n", "case", "reflect", ".", "Slice", ":", "baseSliceType", ":=", "reflect", ".", "SliceOf", "(", "refVal", ".", "Type", "(", ")", ".", "Elem", "(", ")", ")", "\n", "if", "refVal", ".", "Type", "(", ")", ".", "ConvertibleTo", "(", "baseSliceType", ")", "{", "convVal", ":=", "refVal", ".", "Convert", "(", "baseSliceType", ")", "\n", "return", "convVal", ".", "Interface", "(", ")", ",", "reflect", ".", "TypeOf", "(", "convVal", ".", "Interface", "(", ")", ")", "!=", "refVal", ".", "Type", "(", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "false", "\n", "}" ]
// underlyingSliceType gets the underlying slice type
[ "underlyingSliceType", "gets", "the", "underlying", "slice", "type" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/convert.go#L167-L186
146,830
jackc/pgx
pgtype/bpchar.go
AssignTo
func (src *BPChar) AssignTo(dst interface{}) error { if src.Status == Present { switch v := dst.(type) { case *rune: runes := []rune(src.String) if len(runes) == 1 { *v = runes[0] return nil } } } return (*Text)(src).AssignTo(dst) }
go
func (src *BPChar) AssignTo(dst interface{}) error { if src.Status == Present { switch v := dst.(type) { case *rune: runes := []rune(src.String) if len(runes) == 1 { *v = runes[0] return nil } } } return (*Text)(src).AssignTo(dst) }
[ "func", "(", "src", "*", "BPChar", ")", "AssignTo", "(", "dst", "interface", "{", "}", ")", "error", "{", "if", "src", ".", "Status", "==", "Present", "{", "switch", "v", ":=", "dst", ".", "(", "type", ")", "{", "case", "*", "rune", ":", "runes", ":=", "[", "]", "rune", "(", "src", ".", "String", ")", "\n", "if", "len", "(", "runes", ")", "==", "1", "{", "*", "v", "=", "runes", "[", "0", "]", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "(", "*", "Text", ")", "(", "src", ")", ".", "AssignTo", "(", "dst", ")", "\n", "}" ]
// AssignTo assigns from src to dst.
[ "AssignTo", "assigns", "from", "src", "to", "dst", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/pgtype/bpchar.go#L22-L34
146,831
jackc/pgx
log/zerologadapter/adapter.go
NewLogger
func NewLogger(logger zerolog.Logger) *Logger { return &Logger{ logger: logger.With().Str("module", "pgx").Logger(), } }
go
func NewLogger(logger zerolog.Logger) *Logger { return &Logger{ logger: logger.With().Str("module", "pgx").Logger(), } }
[ "func", "NewLogger", "(", "logger", "zerolog", ".", "Logger", ")", "*", "Logger", "{", "return", "&", "Logger", "{", "logger", ":", "logger", ".", "With", "(", ")", ".", "Str", "(", "\"", "\"", ",", "\"", "\"", ")", ".", "Logger", "(", ")", ",", "}", "\n", "}" ]
// NewLogger accepts a zerolog.Logger as input and returns a new custom pgx // logging fascade as output.
[ "NewLogger", "accepts", "a", "zerolog", ".", "Logger", "as", "input", "and", "returns", "a", "new", "custom", "pgx", "logging", "fascade", "as", "output", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/log/zerologadapter/adapter.go#L15-L19
146,832
jackc/pgx
messages.go
appendParse
func appendParse(buf []byte, name string, query string, parameterOIDs []pgtype.OID) []byte { buf = append(buf, 'P') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, name...) buf = append(buf, 0) buf = append(buf, query...) buf = append(buf, 0) buf = pgio.AppendInt16(buf, int16(len(parameterOIDs))) for _, oid := range parameterOIDs { buf = pgio.AppendUint32(buf, uint32(oid)) } pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf }
go
func appendParse(buf []byte, name string, query string, parameterOIDs []pgtype.OID) []byte { buf = append(buf, 'P') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, name...) buf = append(buf, 0) buf = append(buf, query...) buf = append(buf, 0) buf = pgio.AppendInt16(buf, int16(len(parameterOIDs))) for _, oid := range parameterOIDs { buf = pgio.AppendUint32(buf, uint32(oid)) } pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf }
[ "func", "appendParse", "(", "buf", "[", "]", "byte", ",", "name", "string", ",", "query", "string", ",", "parameterOIDs", "[", "]", "pgtype", ".", "OID", ")", "[", "]", "byte", "{", "buf", "=", "append", "(", "buf", ",", "'P'", ")", "\n", "sp", ":=", "len", "(", "buf", ")", "\n", "buf", "=", "pgio", ".", "AppendInt32", "(", "buf", ",", "-", "1", ")", "\n", "buf", "=", "append", "(", "buf", ",", "name", "...", ")", "\n", "buf", "=", "append", "(", "buf", ",", "0", ")", "\n", "buf", "=", "append", "(", "buf", ",", "query", "...", ")", "\n", "buf", "=", "append", "(", "buf", ",", "0", ")", "\n\n", "buf", "=", "pgio", ".", "AppendInt16", "(", "buf", ",", "int16", "(", "len", "(", "parameterOIDs", ")", ")", ")", "\n", "for", "_", ",", "oid", ":=", "range", "parameterOIDs", "{", "buf", "=", "pgio", ".", "AppendUint32", "(", "buf", ",", "uint32", "(", "oid", ")", ")", "\n", "}", "\n", "pgio", ".", "SetInt32", "(", "buf", "[", "sp", ":", "]", ",", "int32", "(", "len", "(", "buf", "[", "sp", ":", "]", ")", ")", ")", "\n\n", "return", "buf", "\n", "}" ]
// appendParse appends a PostgreSQL wire protocol parse message to buf and returns it.
[ "appendParse", "appends", "a", "PostgreSQL", "wire", "protocol", "parse", "message", "to", "buf", "and", "returns", "it", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/messages.go#L113-L129
146,833
jackc/pgx
messages.go
appendDescribe
func appendDescribe(buf []byte, objectType byte, name string) []byte { buf = append(buf, 'D') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, objectType) buf = append(buf, name...) buf = append(buf, 0) pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf }
go
func appendDescribe(buf []byte, objectType byte, name string) []byte { buf = append(buf, 'D') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, objectType) buf = append(buf, name...) buf = append(buf, 0) pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf }
[ "func", "appendDescribe", "(", "buf", "[", "]", "byte", ",", "objectType", "byte", ",", "name", "string", ")", "[", "]", "byte", "{", "buf", "=", "append", "(", "buf", ",", "'D'", ")", "\n", "sp", ":=", "len", "(", "buf", ")", "\n", "buf", "=", "pgio", ".", "AppendInt32", "(", "buf", ",", "-", "1", ")", "\n", "buf", "=", "append", "(", "buf", ",", "objectType", ")", "\n", "buf", "=", "append", "(", "buf", ",", "name", "...", ")", "\n", "buf", "=", "append", "(", "buf", ",", "0", ")", "\n", "pgio", ".", "SetInt32", "(", "buf", "[", "sp", ":", "]", ",", "int32", "(", "len", "(", "buf", "[", "sp", ":", "]", ")", ")", ")", "\n\n", "return", "buf", "\n", "}" ]
// appendDescribe appends a PostgreSQL wire protocol describe message to buf and returns it.
[ "appendDescribe", "appends", "a", "PostgreSQL", "wire", "protocol", "describe", "message", "to", "buf", "and", "returns", "it", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/messages.go#L132-L142
146,834
jackc/pgx
messages.go
appendSync
func appendSync(buf []byte) []byte { buf = append(buf, 'S') buf = pgio.AppendInt32(buf, 4) return buf }
go
func appendSync(buf []byte) []byte { buf = append(buf, 'S') buf = pgio.AppendInt32(buf, 4) return buf }
[ "func", "appendSync", "(", "buf", "[", "]", "byte", ")", "[", "]", "byte", "{", "buf", "=", "append", "(", "buf", ",", "'S'", ")", "\n", "buf", "=", "pgio", ".", "AppendInt32", "(", "buf", ",", "4", ")", "\n\n", "return", "buf", "\n", "}" ]
// appendSync appends a PostgreSQL wire protocol sync message to buf and returns it.
[ "appendSync", "appends", "a", "PostgreSQL", "wire", "protocol", "sync", "message", "to", "buf", "and", "returns", "it", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/messages.go#L145-L150
146,835
jackc/pgx
messages.go
appendBind
func appendBind( buf []byte, destinationPortal, preparedStatement string, connInfo *pgtype.ConnInfo, parameterOIDs []pgtype.OID, arguments []interface{}, resultFormatCodes []int16, ) ([]byte, error) { buf = append(buf, 'B') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, destinationPortal...) buf = append(buf, 0) buf = append(buf, preparedStatement...) buf = append(buf, 0) var err error arguments, err = convertDriverValuers(arguments) if err != nil { return nil, err } buf = pgio.AppendInt16(buf, int16(len(parameterOIDs))) for i, oid := range parameterOIDs { buf = pgio.AppendInt16(buf, chooseParameterFormatCode(connInfo, oid, arguments[i])) } buf = pgio.AppendInt16(buf, int16(len(arguments))) for i, oid := range parameterOIDs { var err error buf, err = encodePreparedStatementArgument(connInfo, buf, oid, arguments[i]) if err != nil { return nil, err } } buf = pgio.AppendInt16(buf, int16(len(resultFormatCodes))) for _, fc := range resultFormatCodes { buf = pgio.AppendInt16(buf, fc) } pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf, nil }
go
func appendBind( buf []byte, destinationPortal, preparedStatement string, connInfo *pgtype.ConnInfo, parameterOIDs []pgtype.OID, arguments []interface{}, resultFormatCodes []int16, ) ([]byte, error) { buf = append(buf, 'B') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, destinationPortal...) buf = append(buf, 0) buf = append(buf, preparedStatement...) buf = append(buf, 0) var err error arguments, err = convertDriverValuers(arguments) if err != nil { return nil, err } buf = pgio.AppendInt16(buf, int16(len(parameterOIDs))) for i, oid := range parameterOIDs { buf = pgio.AppendInt16(buf, chooseParameterFormatCode(connInfo, oid, arguments[i])) } buf = pgio.AppendInt16(buf, int16(len(arguments))) for i, oid := range parameterOIDs { var err error buf, err = encodePreparedStatementArgument(connInfo, buf, oid, arguments[i]) if err != nil { return nil, err } } buf = pgio.AppendInt16(buf, int16(len(resultFormatCodes))) for _, fc := range resultFormatCodes { buf = pgio.AppendInt16(buf, fc) } pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf, nil }
[ "func", "appendBind", "(", "buf", "[", "]", "byte", ",", "destinationPortal", ",", "preparedStatement", "string", ",", "connInfo", "*", "pgtype", ".", "ConnInfo", ",", "parameterOIDs", "[", "]", "pgtype", ".", "OID", ",", "arguments", "[", "]", "interface", "{", "}", ",", "resultFormatCodes", "[", "]", "int16", ",", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "buf", "=", "append", "(", "buf", ",", "'B'", ")", "\n", "sp", ":=", "len", "(", "buf", ")", "\n", "buf", "=", "pgio", ".", "AppendInt32", "(", "buf", ",", "-", "1", ")", "\n", "buf", "=", "append", "(", "buf", ",", "destinationPortal", "...", ")", "\n", "buf", "=", "append", "(", "buf", ",", "0", ")", "\n", "buf", "=", "append", "(", "buf", ",", "preparedStatement", "...", ")", "\n", "buf", "=", "append", "(", "buf", ",", "0", ")", "\n\n", "var", "err", "error", "\n", "arguments", ",", "err", "=", "convertDriverValuers", "(", "arguments", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "buf", "=", "pgio", ".", "AppendInt16", "(", "buf", ",", "int16", "(", "len", "(", "parameterOIDs", ")", ")", ")", "\n", "for", "i", ",", "oid", ":=", "range", "parameterOIDs", "{", "buf", "=", "pgio", ".", "AppendInt16", "(", "buf", ",", "chooseParameterFormatCode", "(", "connInfo", ",", "oid", ",", "arguments", "[", "i", "]", ")", ")", "\n", "}", "\n\n", "buf", "=", "pgio", ".", "AppendInt16", "(", "buf", ",", "int16", "(", "len", "(", "arguments", ")", ")", ")", "\n", "for", "i", ",", "oid", ":=", "range", "parameterOIDs", "{", "var", "err", "error", "\n", "buf", ",", "err", "=", "encodePreparedStatementArgument", "(", "connInfo", ",", "buf", ",", "oid", ",", "arguments", "[", "i", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "buf", "=", "pgio", ".", "AppendInt16", "(", "buf", ",", "int16", "(", "len", "(", "resultFormatCodes", ")", ")", ")", "\n", "for", "_", ",", "fc", ":=", "range", "resultFormatCodes", "{", "buf", "=", "pgio", ".", "AppendInt16", "(", "buf", ",", "fc", ")", "\n", "}", "\n", "pgio", ".", "SetInt32", "(", "buf", "[", "sp", ":", "]", ",", "int32", "(", "len", "(", "buf", "[", "sp", ":", "]", ")", ")", ")", "\n\n", "return", "buf", ",", "nil", "\n", "}" ]
// appendBind appends a PostgreSQL wire protocol bind message to buf and returns it.
[ "appendBind", "appends", "a", "PostgreSQL", "wire", "protocol", "bind", "message", "to", "buf", "and", "returns", "it", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/messages.go#L153-L197
146,836
jackc/pgx
messages.go
appendExecute
func appendExecute(buf []byte, portal string, maxRows uint32) []byte { buf = append(buf, 'E') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, portal...) buf = append(buf, 0) buf = pgio.AppendUint32(buf, maxRows) pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf }
go
func appendExecute(buf []byte, portal string, maxRows uint32) []byte { buf = append(buf, 'E') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, portal...) buf = append(buf, 0) buf = pgio.AppendUint32(buf, maxRows) pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf }
[ "func", "appendExecute", "(", "buf", "[", "]", "byte", ",", "portal", "string", ",", "maxRows", "uint32", ")", "[", "]", "byte", "{", "buf", "=", "append", "(", "buf", ",", "'E'", ")", "\n", "sp", ":=", "len", "(", "buf", ")", "\n", "buf", "=", "pgio", ".", "AppendInt32", "(", "buf", ",", "-", "1", ")", "\n\n", "buf", "=", "append", "(", "buf", ",", "portal", "...", ")", "\n", "buf", "=", "append", "(", "buf", ",", "0", ")", "\n", "buf", "=", "pgio", ".", "AppendUint32", "(", "buf", ",", "maxRows", ")", "\n\n", "pgio", ".", "SetInt32", "(", "buf", "[", "sp", ":", "]", ",", "int32", "(", "len", "(", "buf", "[", "sp", ":", "]", ")", ")", ")", "\n\n", "return", "buf", "\n", "}" ]
// appendExecute appends a PostgreSQL wire protocol execute message to buf and returns it.
[ "appendExecute", "appends", "a", "PostgreSQL", "wire", "protocol", "execute", "message", "to", "buf", "and", "returns", "it", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/messages.go#L216-L228
146,837
jackc/pgx
messages.go
appendQuery
func appendQuery(buf []byte, query string) []byte { buf = append(buf, 'Q') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, query...) buf = append(buf, 0) pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf }
go
func appendQuery(buf []byte, query string) []byte { buf = append(buf, 'Q') sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, query...) buf = append(buf, 0) pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) return buf }
[ "func", "appendQuery", "(", "buf", "[", "]", "byte", ",", "query", "string", ")", "[", "]", "byte", "{", "buf", "=", "append", "(", "buf", ",", "'Q'", ")", "\n", "sp", ":=", "len", "(", "buf", ")", "\n", "buf", "=", "pgio", ".", "AppendInt32", "(", "buf", ",", "-", "1", ")", "\n", "buf", "=", "append", "(", "buf", ",", "query", "...", ")", "\n", "buf", "=", "append", "(", "buf", ",", "0", ")", "\n", "pgio", ".", "SetInt32", "(", "buf", "[", "sp", ":", "]", ",", "int32", "(", "len", "(", "buf", "[", "sp", ":", "]", ")", ")", ")", "\n\n", "return", "buf", "\n", "}" ]
// appendQuery appends a PostgreSQL wire protocol query message to buf and returns it.
[ "appendQuery", "appends", "a", "PostgreSQL", "wire", "protocol", "query", "message", "to", "buf", "and", "returns", "it", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/messages.go#L231-L240
146,838
jackc/pgx
stdlib/sql.go
ConnectionString
func (c *DriverConfig) ConnectionString(original string) string { if c.driver == nil { panic("DriverConfig must be registered before calling ConnectionString") } buf := make([]byte, 9) binary.BigEndian.PutUint64(buf[1:], uint64(c.id)) buf = append(buf, original...) return string(buf) }
go
func (c *DriverConfig) ConnectionString(original string) string { if c.driver == nil { panic("DriverConfig must be registered before calling ConnectionString") } buf := make([]byte, 9) binary.BigEndian.PutUint64(buf[1:], uint64(c.id)) buf = append(buf, original...) return string(buf) }
[ "func", "(", "c", "*", "DriverConfig", ")", "ConnectionString", "(", "original", "string", ")", "string", "{", "if", "c", ".", "driver", "==", "nil", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "9", ")", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "buf", "[", "1", ":", "]", ",", "uint64", "(", "c", ".", "id", ")", ")", "\n", "buf", "=", "append", "(", "buf", ",", "original", "...", ")", "\n", "return", "string", "(", "buf", ")", "\n", "}" ]
// ConnectionString encodes the DriverConfig into the original connection // string. DriverConfig must be registered before calling ConnectionString.
[ "ConnectionString", "encodes", "the", "DriverConfig", "into", "the", "original", "connection", "string", ".", "DriverConfig", "must", "be", "registered", "before", "calling", "ConnectionString", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/stdlib/sql.go#L188-L197
146,839
jackc/pgx
stdlib/sql.go
ColumnTypeDatabaseTypeName
func (r *Rows) ColumnTypeDatabaseTypeName(index int) string { return strings.ToUpper(r.rows.FieldDescriptions()[index].DataTypeName) }
go
func (r *Rows) ColumnTypeDatabaseTypeName(index int) string { return strings.ToUpper(r.rows.FieldDescriptions()[index].DataTypeName) }
[ "func", "(", "r", "*", "Rows", ")", "ColumnTypeDatabaseTypeName", "(", "index", "int", ")", "string", "{", "return", "strings", ".", "ToUpper", "(", "r", ".", "rows", ".", "FieldDescriptions", "(", ")", "[", "index", "]", ".", "DataTypeName", ")", "\n", "}" ]
// ColumnTypeDatabaseTypeName return the database system type name.
[ "ColumnTypeDatabaseTypeName", "return", "the", "database", "system", "type", "name", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/stdlib/sql.go#L491-L493
146,840
jackc/pgx
stdlib/sql.go
ColumnTypeLength
func (r *Rows) ColumnTypeLength(index int) (int64, bool) { return r.rows.FieldDescriptions()[index].Length() }
go
func (r *Rows) ColumnTypeLength(index int) (int64, bool) { return r.rows.FieldDescriptions()[index].Length() }
[ "func", "(", "r", "*", "Rows", ")", "ColumnTypeLength", "(", "index", "int", ")", "(", "int64", ",", "bool", ")", "{", "return", "r", ".", "rows", ".", "FieldDescriptions", "(", ")", "[", "index", "]", ".", "Length", "(", ")", "\n", "}" ]
// ColumnTypeLength returns the length of the column type if the column is a // variable length type. If the column is not a variable length type ok // should return false.
[ "ColumnTypeLength", "returns", "the", "length", "of", "the", "column", "type", "if", "the", "column", "is", "a", "variable", "length", "type", ".", "If", "the", "column", "is", "not", "a", "variable", "length", "type", "ok", "should", "return", "false", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/stdlib/sql.go#L498-L500
146,841
jackc/pgx
stdlib/sql.go
ColumnTypePrecisionScale
func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) { return r.rows.FieldDescriptions()[index].PrecisionScale() }
go
func (r *Rows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) { return r.rows.FieldDescriptions()[index].PrecisionScale() }
[ "func", "(", "r", "*", "Rows", ")", "ColumnTypePrecisionScale", "(", "index", "int", ")", "(", "precision", ",", "scale", "int64", ",", "ok", "bool", ")", "{", "return", "r", ".", "rows", ".", "FieldDescriptions", "(", ")", "[", "index", "]", ".", "PrecisionScale", "(", ")", "\n", "}" ]
// ColumnTypePrecisionScale should return the precision and scale for decimal // types. If not applicable, ok should be false.
[ "ColumnTypePrecisionScale", "should", "return", "the", "precision", "and", "scale", "for", "decimal", "types", ".", "If", "not", "applicable", "ok", "should", "be", "false", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/stdlib/sql.go#L504-L506
146,842
jackc/pgx
stdlib/sql.go
ColumnTypeScanType
func (r *Rows) ColumnTypeScanType(index int) reflect.Type { return r.rows.FieldDescriptions()[index].Type() }
go
func (r *Rows) ColumnTypeScanType(index int) reflect.Type { return r.rows.FieldDescriptions()[index].Type() }
[ "func", "(", "r", "*", "Rows", ")", "ColumnTypeScanType", "(", "index", "int", ")", "reflect", ".", "Type", "{", "return", "r", ".", "rows", ".", "FieldDescriptions", "(", ")", "[", "index", "]", ".", "Type", "(", ")", "\n", "}" ]
// ColumnTypeScanType returns the value type that can be used to scan types into.
[ "ColumnTypeScanType", "returns", "the", "value", "type", "that", "can", "be", "used", "to", "scan", "types", "into", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/stdlib/sql.go#L509-L511
146,843
jackc/pgx
examples/url_shortener/main.go
afterConnect
func afterConnect(conn *pgx.Conn) (err error) { _, err = conn.Prepare("getUrl", ` select url from shortened_urls where id=$1 `) if err != nil { return } _, err = conn.Prepare("deleteUrl", ` delete from shortened_urls where id=$1 `) if err != nil { return } _, err = conn.Prepare("putUrl", ` insert into shortened_urls(id, url) values ($1, $2) on conflict (id) do update set url=excluded.url `) return }
go
func afterConnect(conn *pgx.Conn) (err error) { _, err = conn.Prepare("getUrl", ` select url from shortened_urls where id=$1 `) if err != nil { return } _, err = conn.Prepare("deleteUrl", ` delete from shortened_urls where id=$1 `) if err != nil { return } _, err = conn.Prepare("putUrl", ` insert into shortened_urls(id, url) values ($1, $2) on conflict (id) do update set url=excluded.url `) return }
[ "func", "afterConnect", "(", "conn", "*", "pgx", ".", "Conn", ")", "(", "err", "error", ")", "{", "_", ",", "err", "=", "conn", ".", "Prepare", "(", "\"", "\"", ",", "`\n select url from shortened_urls where id=$1\n `", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "_", ",", "err", "=", "conn", ".", "Prepare", "(", "\"", "\"", ",", "`\n delete from shortened_urls where id=$1\n `", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "_", ",", "err", "=", "conn", ".", "Prepare", "(", "\"", "\"", ",", "`\n insert into shortened_urls(id, url) values ($1, $2)\n on conflict (id) do update set url=excluded.url\n `", ")", "\n", "return", "\n", "}" ]
// afterConnect creates the prepared statements that this application uses
[ "afterConnect", "creates", "the", "prepared", "statements", "that", "this", "application", "uses" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/examples/url_shortener/main.go#L16-L36
146,844
jackc/pgx
chunkreader/chunkreader.go
Next
func (r *ChunkReader) Next(n int) (buf []byte, err error) { // n bytes already in buf if (r.wp - r.rp) >= n { buf = r.buf[r.rp : r.rp+n] r.rp += n return buf, err } // available space in buf is less than n if len(r.buf) < n { r.copyBufContents(r.newBuf(n)) } // buf is large enough, but need to shift filled area to start to make enough contiguous space minReadCount := n - (r.wp - r.rp) if (len(r.buf) - r.wp) < minReadCount { newBuf := r.newBuf(n) r.copyBufContents(newBuf) } if err := r.appendAtLeast(minReadCount); err != nil { return nil, err } buf = r.buf[r.rp : r.rp+n] r.rp += n return buf, nil }
go
func (r *ChunkReader) Next(n int) (buf []byte, err error) { // n bytes already in buf if (r.wp - r.rp) >= n { buf = r.buf[r.rp : r.rp+n] r.rp += n return buf, err } // available space in buf is less than n if len(r.buf) < n { r.copyBufContents(r.newBuf(n)) } // buf is large enough, but need to shift filled area to start to make enough contiguous space minReadCount := n - (r.wp - r.rp) if (len(r.buf) - r.wp) < minReadCount { newBuf := r.newBuf(n) r.copyBufContents(newBuf) } if err := r.appendAtLeast(minReadCount); err != nil { return nil, err } buf = r.buf[r.rp : r.rp+n] r.rp += n return buf, nil }
[ "func", "(", "r", "*", "ChunkReader", ")", "Next", "(", "n", "int", ")", "(", "buf", "[", "]", "byte", ",", "err", "error", ")", "{", "// n bytes already in buf", "if", "(", "r", ".", "wp", "-", "r", ".", "rp", ")", ">=", "n", "{", "buf", "=", "r", ".", "buf", "[", "r", ".", "rp", ":", "r", ".", "rp", "+", "n", "]", "\n", "r", ".", "rp", "+=", "n", "\n", "return", "buf", ",", "err", "\n", "}", "\n\n", "// available space in buf is less than n", "if", "len", "(", "r", ".", "buf", ")", "<", "n", "{", "r", ".", "copyBufContents", "(", "r", ".", "newBuf", "(", "n", ")", ")", "\n", "}", "\n\n", "// buf is large enough, but need to shift filled area to start to make enough contiguous space", "minReadCount", ":=", "n", "-", "(", "r", ".", "wp", "-", "r", ".", "rp", ")", "\n", "if", "(", "len", "(", "r", ".", "buf", ")", "-", "r", ".", "wp", ")", "<", "minReadCount", "{", "newBuf", ":=", "r", ".", "newBuf", "(", "n", ")", "\n", "r", ".", "copyBufContents", "(", "newBuf", ")", "\n", "}", "\n\n", "if", "err", ":=", "r", ".", "appendAtLeast", "(", "minReadCount", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "buf", "=", "r", ".", "buf", "[", "r", ".", "rp", ":", "r", ".", "rp", "+", "n", "]", "\n", "r", ".", "rp", "+=", "n", "\n", "return", "buf", ",", "nil", "\n", "}" ]
// Next returns buf filled with the next n bytes. If an error occurs, buf will // be nil.
[ "Next", "returns", "buf", "filled", "with", "the", "next", "n", "bytes", ".", "If", "an", "error", "occurs", "buf", "will", "be", "nil", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/chunkreader/chunkreader.go#L43-L70
146,845
jackc/pgx
conn.go
Sanitize
func (ident Identifier) Sanitize() string { parts := make([]string, len(ident)) for i := range ident { parts[i] = `"` + strings.Replace(ident[i], `"`, `""`, -1) + `"` } return strings.Join(parts, ".") }
go
func (ident Identifier) Sanitize() string { parts := make([]string, len(ident)) for i := range ident { parts[i] = `"` + strings.Replace(ident[i], `"`, `""`, -1) + `"` } return strings.Join(parts, ".") }
[ "func", "(", "ident", "Identifier", ")", "Sanitize", "(", ")", "string", "{", "parts", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "ident", ")", ")", "\n", "for", "i", ":=", "range", "ident", "{", "parts", "[", "i", "]", "=", "`\"`", "+", "strings", ".", "Replace", "(", "ident", "[", "i", "]", ",", "`\"`", ",", "`\"\"`", ",", "-", "1", ")", "+", "`\"`", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "parts", ",", "\"", "\"", ")", "\n", "}" ]
// Sanitize returns a sanitized string safe for SQL interpolation.
[ "Sanitize", "returns", "a", "sanitized", "string", "safe", "for", "SQL", "interpolation", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L190-L196
146,846
jackc/pgx
conn.go
Connect
func Connect(config ConnConfig) (c *Conn, err error) { return connect(config, minimalConnInfo) }
go
func Connect(config ConnConfig) (c *Conn, err error) { return connect(config, minimalConnInfo) }
[ "func", "Connect", "(", "config", "ConnConfig", ")", "(", "c", "*", "Conn", ",", "err", "error", ")", "{", "return", "connect", "(", "config", ",", "minimalConnInfo", ")", "\n", "}" ]
// Connect establishes a connection with a PostgreSQL server using config. // config.Host must be specified. config.User will default to the OS user name. // Other config fields are optional.
[ "Connect", "establishes", "a", "connection", "with", "a", "PostgreSQL", "server", "using", "config", ".", "config", ".", "Host", "must", "be", "specified", ".", "config", ".", "User", "will", "default", "to", "the", "OS", "user", "name", ".", "Other", "config", "fields", "are", "optional", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L225-L227
146,847
jackc/pgx
conn.go
initConnInfoEnumArray
func (c *Conn) initConnInfoEnumArray(cinfo *pgtype.ConnInfo) error { nameOIDs := make(map[string]pgtype.OID, 16) rows, err := c.Query(`select t.oid, t.typname from pg_type t join pg_type base_type on t.typelem=base_type.oid where t.typtype = 'b' and base_type.typtype = 'e'`) if err != nil { return err } for rows.Next() { var oid pgtype.OID var name pgtype.Text if err := rows.Scan(&oid, &name); err != nil { return err } nameOIDs[name.String] = oid } if rows.Err() != nil { return rows.Err() } for name, oid := range nameOIDs { cinfo.RegisterDataType(pgtype.DataType{ Value: &pgtype.EnumArray{}, Name: name, OID: oid, }) } return nil }
go
func (c *Conn) initConnInfoEnumArray(cinfo *pgtype.ConnInfo) error { nameOIDs := make(map[string]pgtype.OID, 16) rows, err := c.Query(`select t.oid, t.typname from pg_type t join pg_type base_type on t.typelem=base_type.oid where t.typtype = 'b' and base_type.typtype = 'e'`) if err != nil { return err } for rows.Next() { var oid pgtype.OID var name pgtype.Text if err := rows.Scan(&oid, &name); err != nil { return err } nameOIDs[name.String] = oid } if rows.Err() != nil { return rows.Err() } for name, oid := range nameOIDs { cinfo.RegisterDataType(pgtype.DataType{ Value: &pgtype.EnumArray{}, Name: name, OID: oid, }) } return nil }
[ "func", "(", "c", "*", "Conn", ")", "initConnInfoEnumArray", "(", "cinfo", "*", "pgtype", ".", "ConnInfo", ")", "error", "{", "nameOIDs", ":=", "make", "(", "map", "[", "string", "]", "pgtype", ".", "OID", ",", "16", ")", "\n", "rows", ",", "err", ":=", "c", ".", "Query", "(", "`select t.oid, t.typname\nfrom pg_type t\n join pg_type base_type on t.typelem=base_type.oid\nwhere t.typtype = 'b'\n and base_type.typtype = 'e'`", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "rows", ".", "Next", "(", ")", "{", "var", "oid", "pgtype", ".", "OID", "\n", "var", "name", "pgtype", ".", "Text", "\n", "if", "err", ":=", "rows", ".", "Scan", "(", "&", "oid", ",", "&", "name", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "nameOIDs", "[", "name", ".", "String", "]", "=", "oid", "\n", "}", "\n\n", "if", "rows", ".", "Err", "(", ")", "!=", "nil", "{", "return", "rows", ".", "Err", "(", ")", "\n", "}", "\n\n", "for", "name", ",", "oid", ":=", "range", "nameOIDs", "{", "cinfo", ".", "RegisterDataType", "(", "pgtype", ".", "DataType", "{", "Value", ":", "&", "pgtype", ".", "EnumArray", "{", "}", ",", "Name", ":", "name", ",", "OID", ":", "oid", ",", "}", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// initConnInfoEnumArray introspects for arrays of enums and registers a data type for them.
[ "initConnInfoEnumArray", "introspects", "for", "arrays", "of", "enums", "and", "registers", "a", "data", "type", "for", "them", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L459-L493
146,848
jackc/pgx
conn.go
initConnInfoDomains
func (c *Conn) initConnInfoDomains(cinfo *pgtype.ConnInfo) error { type domain struct { oid pgtype.OID name pgtype.Text baseOID pgtype.OID } domains := make([]*domain, 0, 16) rows, err := c.Query(`select t.oid, t.typname, t.typbasetype from pg_type t join pg_type base_type on t.typbasetype=base_type.oid where t.typtype = 'd' and base_type.typtype = 'b'`) if err != nil { return err } for rows.Next() { var d domain if err := rows.Scan(&d.oid, &d.name, &d.baseOID); err != nil { return err } domains = append(domains, &d) } if rows.Err() != nil { return rows.Err() } for _, d := range domains { baseDataType, ok := cinfo.DataTypeForOID(d.baseOID) if ok { cinfo.RegisterDataType(pgtype.DataType{ Value: reflect.New(reflect.ValueOf(baseDataType.Value).Elem().Type()).Interface().(pgtype.Value), Name: d.name.String, OID: d.oid, }) } } return nil }
go
func (c *Conn) initConnInfoDomains(cinfo *pgtype.ConnInfo) error { type domain struct { oid pgtype.OID name pgtype.Text baseOID pgtype.OID } domains := make([]*domain, 0, 16) rows, err := c.Query(`select t.oid, t.typname, t.typbasetype from pg_type t join pg_type base_type on t.typbasetype=base_type.oid where t.typtype = 'd' and base_type.typtype = 'b'`) if err != nil { return err } for rows.Next() { var d domain if err := rows.Scan(&d.oid, &d.name, &d.baseOID); err != nil { return err } domains = append(domains, &d) } if rows.Err() != nil { return rows.Err() } for _, d := range domains { baseDataType, ok := cinfo.DataTypeForOID(d.baseOID) if ok { cinfo.RegisterDataType(pgtype.DataType{ Value: reflect.New(reflect.ValueOf(baseDataType.Value).Elem().Type()).Interface().(pgtype.Value), Name: d.name.String, OID: d.oid, }) } } return nil }
[ "func", "(", "c", "*", "Conn", ")", "initConnInfoDomains", "(", "cinfo", "*", "pgtype", ".", "ConnInfo", ")", "error", "{", "type", "domain", "struct", "{", "oid", "pgtype", ".", "OID", "\n", "name", "pgtype", ".", "Text", "\n", "baseOID", "pgtype", ".", "OID", "\n", "}", "\n\n", "domains", ":=", "make", "(", "[", "]", "*", "domain", ",", "0", ",", "16", ")", "\n\n", "rows", ",", "err", ":=", "c", ".", "Query", "(", "`select t.oid, t.typname, t.typbasetype\nfrom pg_type t\n join pg_type base_type on t.typbasetype=base_type.oid\nwhere t.typtype = 'd'\n and base_type.typtype = 'b'`", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "rows", ".", "Next", "(", ")", "{", "var", "d", "domain", "\n", "if", "err", ":=", "rows", ".", "Scan", "(", "&", "d", ".", "oid", ",", "&", "d", ".", "name", ",", "&", "d", ".", "baseOID", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "domains", "=", "append", "(", "domains", ",", "&", "d", ")", "\n", "}", "\n\n", "if", "rows", ".", "Err", "(", ")", "!=", "nil", "{", "return", "rows", ".", "Err", "(", ")", "\n", "}", "\n\n", "for", "_", ",", "d", ":=", "range", "domains", "{", "baseDataType", ",", "ok", ":=", "cinfo", ".", "DataTypeForOID", "(", "d", ".", "baseOID", ")", "\n", "if", "ok", "{", "cinfo", ".", "RegisterDataType", "(", "pgtype", ".", "DataType", "{", "Value", ":", "reflect", ".", "New", "(", "reflect", ".", "ValueOf", "(", "baseDataType", ".", "Value", ")", ".", "Elem", "(", ")", ".", "Type", "(", ")", ")", ".", "Interface", "(", ")", ".", "(", "pgtype", ".", "Value", ")", ",", "Name", ":", "d", ".", "name", ".", "String", ",", "OID", ":", "d", ".", "oid", ",", "}", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// initConnInfoDomains introspects for domains and registers a data type for them.
[ "initConnInfoDomains", "introspects", "for", "domains", "and", "registers", "a", "data", "type", "for", "them", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L496-L539
146,849
jackc/pgx
conn.go
crateDBTypesQuery
func (c *Conn) crateDBTypesQuery(err error) (*pgtype.ConnInfo, error) { // CrateDB 2.1.6 is a database that implements the PostgreSQL wire protocol, // but not perfectly. In particular, the pg_catalog schema containing the // pg_type table is not visible by default and the pg_type.typtype column is // not implemented. Therefor the query above currently returns the following // error: // // pgx.PgError{Severity:"ERROR", Code:"XX000", // Message:"TableUnknownException: Table 'test.pg_type' unknown", // Detail:"", Hint:"", Position:0, InternalPosition:0, InternalQuery:"", // Where:"", SchemaName:"", TableName:"", ColumnName:"", DataTypeName:"", // ConstraintName:"", File:"Schemas.java", Line:99, Routine:"getTableInfo"} // // If CrateDB was to fix the pg_type table visbility in the future, we'd // still get this error until typtype column is implemented: // // pgx.PgError{Severity:"ERROR", Code:"XX000", // Message:"ColumnUnknownException: Column typtype unknown", Detail:"", // Hint:"", Position:0, InternalPosition:0, InternalQuery:"", Where:"", // SchemaName:"", TableName:"", ColumnName:"", DataTypeName:"", // ConstraintName:"", File:"FullQualifiedNameFieldProvider.java", Line:132, // // Additionally CrateDB doesn't implement Postgres error codes [2], and // instead always returns "XX000" (internal_error). The code below uses all // of this knowledge as a heuristic to detect CrateDB. If CrateDB is // detected, a CrateDB specific pg_type query is executed instead. // // The heuristic is designed to still work even if CrateDB fixes [2] or // renames its internal exception names. If both are changed but pg_types // isn't fixed, this code will need to be changed. // // There is also a small chance the heuristic will yield a false positive for // non-CrateDB databases (e.g. if a real Postgres instance returns a XX000 // error), but hopefully there will be no harm in attempting the alternative // query in this case. // // CrateDB also uses the type varchar for the typname column which required // adding varchar to the minimalConnInfo init code. // // Also see the discussion here [3]. // // [1] https://crate.io/ // [2] https://github.com/crate/crate/issues/5027 // [3] https://github.com/jackc/pgx/issues/320 if pgErr, ok := err.(PgError); ok && (pgErr.Code == "XX000" || strings.Contains(pgErr.Message, "TableUnknownException") || strings.Contains(pgErr.Message, "ColumnUnknownException")) { var ( nameOIDs map[string]pgtype.OID ) if nameOIDs, err = connInfoFromRows(c.Query(`select oid, typname from pg_catalog.pg_type`)); err != nil { return nil, err } cinfo := pgtype.NewConnInfo() cinfo.InitializeDataTypes(nameOIDs) return cinfo, err } return nil, err }
go
func (c *Conn) crateDBTypesQuery(err error) (*pgtype.ConnInfo, error) { // CrateDB 2.1.6 is a database that implements the PostgreSQL wire protocol, // but not perfectly. In particular, the pg_catalog schema containing the // pg_type table is not visible by default and the pg_type.typtype column is // not implemented. Therefor the query above currently returns the following // error: // // pgx.PgError{Severity:"ERROR", Code:"XX000", // Message:"TableUnknownException: Table 'test.pg_type' unknown", // Detail:"", Hint:"", Position:0, InternalPosition:0, InternalQuery:"", // Where:"", SchemaName:"", TableName:"", ColumnName:"", DataTypeName:"", // ConstraintName:"", File:"Schemas.java", Line:99, Routine:"getTableInfo"} // // If CrateDB was to fix the pg_type table visbility in the future, we'd // still get this error until typtype column is implemented: // // pgx.PgError{Severity:"ERROR", Code:"XX000", // Message:"ColumnUnknownException: Column typtype unknown", Detail:"", // Hint:"", Position:0, InternalPosition:0, InternalQuery:"", Where:"", // SchemaName:"", TableName:"", ColumnName:"", DataTypeName:"", // ConstraintName:"", File:"FullQualifiedNameFieldProvider.java", Line:132, // // Additionally CrateDB doesn't implement Postgres error codes [2], and // instead always returns "XX000" (internal_error). The code below uses all // of this knowledge as a heuristic to detect CrateDB. If CrateDB is // detected, a CrateDB specific pg_type query is executed instead. // // The heuristic is designed to still work even if CrateDB fixes [2] or // renames its internal exception names. If both are changed but pg_types // isn't fixed, this code will need to be changed. // // There is also a small chance the heuristic will yield a false positive for // non-CrateDB databases (e.g. if a real Postgres instance returns a XX000 // error), but hopefully there will be no harm in attempting the alternative // query in this case. // // CrateDB also uses the type varchar for the typname column which required // adding varchar to the minimalConnInfo init code. // // Also see the discussion here [3]. // // [1] https://crate.io/ // [2] https://github.com/crate/crate/issues/5027 // [3] https://github.com/jackc/pgx/issues/320 if pgErr, ok := err.(PgError); ok && (pgErr.Code == "XX000" || strings.Contains(pgErr.Message, "TableUnknownException") || strings.Contains(pgErr.Message, "ColumnUnknownException")) { var ( nameOIDs map[string]pgtype.OID ) if nameOIDs, err = connInfoFromRows(c.Query(`select oid, typname from pg_catalog.pg_type`)); err != nil { return nil, err } cinfo := pgtype.NewConnInfo() cinfo.InitializeDataTypes(nameOIDs) return cinfo, err } return nil, err }
[ "func", "(", "c", "*", "Conn", ")", "crateDBTypesQuery", "(", "err", "error", ")", "(", "*", "pgtype", ".", "ConnInfo", ",", "error", ")", "{", "// CrateDB 2.1.6 is a database that implements the PostgreSQL wire protocol,", "// but not perfectly. In particular, the pg_catalog schema containing the", "// pg_type table is not visible by default and the pg_type.typtype column is", "// not implemented. Therefor the query above currently returns the following", "// error:", "//", "// pgx.PgError{Severity:\"ERROR\", Code:\"XX000\",", "// Message:\"TableUnknownException: Table 'test.pg_type' unknown\",", "// Detail:\"\", Hint:\"\", Position:0, InternalPosition:0, InternalQuery:\"\",", "// Where:\"\", SchemaName:\"\", TableName:\"\", ColumnName:\"\", DataTypeName:\"\",", "// ConstraintName:\"\", File:\"Schemas.java\", Line:99, Routine:\"getTableInfo\"}", "//", "// If CrateDB was to fix the pg_type table visbility in the future, we'd", "// still get this error until typtype column is implemented:", "//", "// pgx.PgError{Severity:\"ERROR\", Code:\"XX000\",", "// Message:\"ColumnUnknownException: Column typtype unknown\", Detail:\"\",", "// Hint:\"\", Position:0, InternalPosition:0, InternalQuery:\"\", Where:\"\",", "// SchemaName:\"\", TableName:\"\", ColumnName:\"\", DataTypeName:\"\",", "// ConstraintName:\"\", File:\"FullQualifiedNameFieldProvider.java\", Line:132,", "//", "// Additionally CrateDB doesn't implement Postgres error codes [2], and", "// instead always returns \"XX000\" (internal_error). The code below uses all", "// of this knowledge as a heuristic to detect CrateDB. If CrateDB is", "// detected, a CrateDB specific pg_type query is executed instead.", "//", "// The heuristic is designed to still work even if CrateDB fixes [2] or", "// renames its internal exception names. If both are changed but pg_types", "// isn't fixed, this code will need to be changed.", "//", "// There is also a small chance the heuristic will yield a false positive for", "// non-CrateDB databases (e.g. if a real Postgres instance returns a XX000", "// error), but hopefully there will be no harm in attempting the alternative", "// query in this case.", "//", "// CrateDB also uses the type varchar for the typname column which required", "// adding varchar to the minimalConnInfo init code.", "//", "// Also see the discussion here [3].", "//", "// [1] https://crate.io/", "// [2] https://github.com/crate/crate/issues/5027", "// [3] https://github.com/jackc/pgx/issues/320", "if", "pgErr", ",", "ok", ":=", "err", ".", "(", "PgError", ")", ";", "ok", "&&", "(", "pgErr", ".", "Code", "==", "\"", "\"", "||", "strings", ".", "Contains", "(", "pgErr", ".", "Message", ",", "\"", "\"", ")", "||", "strings", ".", "Contains", "(", "pgErr", ".", "Message", ",", "\"", "\"", ")", ")", "{", "var", "(", "nameOIDs", "map", "[", "string", "]", "pgtype", ".", "OID", "\n", ")", "\n\n", "if", "nameOIDs", ",", "err", "=", "connInfoFromRows", "(", "c", ".", "Query", "(", "`select oid, typname from pg_catalog.pg_type`", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "cinfo", ":=", "pgtype", ".", "NewConnInfo", "(", ")", "\n", "cinfo", ".", "InitializeDataTypes", "(", "nameOIDs", ")", "\n\n", "return", "cinfo", ",", "err", "\n", "}", "\n\n", "return", "nil", ",", "err", "\n", "}" ]
// crateDBTypesQuery checks if the given err is likely to be the result of // CrateDB not implementing the pg_types table correctly. If yes, a CrateDB // specific query against pg_types is executed and its results are returned. If // not, the original error is returned.
[ "crateDBTypesQuery", "checks", "if", "the", "given", "err", "is", "likely", "to", "be", "the", "result", "of", "CrateDB", "not", "implementing", "the", "pg_types", "table", "correctly", ".", "If", "yes", "a", "CrateDB", "specific", "query", "against", "pg_types", "is", "executed", "and", "its", "results", "are", "returned", ".", "If", "not", "the", "original", "error", "is", "returned", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L545-L609
146,850
jackc/pgx
conn.go
LocalAddr
func (c *Conn) LocalAddr() (net.Addr, error) { if !c.IsAlive() { return nil, errors.New("connection not ready") } return c.conn.LocalAddr(), nil }
go
func (c *Conn) LocalAddr() (net.Addr, error) { if !c.IsAlive() { return nil, errors.New("connection not ready") } return c.conn.LocalAddr(), nil }
[ "func", "(", "c", "*", "Conn", ")", "LocalAddr", "(", ")", "(", "net", ".", "Addr", ",", "error", ")", "{", "if", "!", "c", ".", "IsAlive", "(", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "c", ".", "conn", ".", "LocalAddr", "(", ")", ",", "nil", "\n", "}" ]
// LocalAddr returns the underlying connection's local address
[ "LocalAddr", "returns", "the", "underlying", "connection", "s", "local", "address" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L617-L622
146,851
jackc/pgx
conn.go
Close
func (c *Conn) Close() (err error) { c.mux.Lock() defer c.mux.Unlock() if c.status < connStatusIdle { return nil } c.status = connStatusClosed defer func() { c.conn.Close() c.causeOfDeath = errors.New("Closed") if c.shouldLog(LogLevelInfo) { c.log(LogLevelInfo, "closed connection", nil) } }() err = c.conn.SetDeadline(time.Time{}) if err != nil && c.shouldLog(LogLevelWarn) { c.log(LogLevelWarn, "failed to clear deadlines to send close message", map[string]interface{}{"err": err}) return err } _, err = c.conn.Write([]byte{'X', 0, 0, 0, 4}) if err != nil && c.shouldLog(LogLevelWarn) { c.log(LogLevelWarn, "failed to send terminate message", map[string]interface{}{"err": err}) return err } err = c.conn.SetReadDeadline(time.Now().Add(5 * time.Second)) if err != nil && c.shouldLog(LogLevelWarn) { c.log(LogLevelWarn, "failed to set read deadline to finish closing", map[string]interface{}{"err": err}) return err } _, err = c.conn.Read(make([]byte, 1)) if err != io.EOF { return err } return nil }
go
func (c *Conn) Close() (err error) { c.mux.Lock() defer c.mux.Unlock() if c.status < connStatusIdle { return nil } c.status = connStatusClosed defer func() { c.conn.Close() c.causeOfDeath = errors.New("Closed") if c.shouldLog(LogLevelInfo) { c.log(LogLevelInfo, "closed connection", nil) } }() err = c.conn.SetDeadline(time.Time{}) if err != nil && c.shouldLog(LogLevelWarn) { c.log(LogLevelWarn, "failed to clear deadlines to send close message", map[string]interface{}{"err": err}) return err } _, err = c.conn.Write([]byte{'X', 0, 0, 0, 4}) if err != nil && c.shouldLog(LogLevelWarn) { c.log(LogLevelWarn, "failed to send terminate message", map[string]interface{}{"err": err}) return err } err = c.conn.SetReadDeadline(time.Now().Add(5 * time.Second)) if err != nil && c.shouldLog(LogLevelWarn) { c.log(LogLevelWarn, "failed to set read deadline to finish closing", map[string]interface{}{"err": err}) return err } _, err = c.conn.Read(make([]byte, 1)) if err != io.EOF { return err } return nil }
[ "func", "(", "c", "*", "Conn", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "c", ".", "mux", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mux", ".", "Unlock", "(", ")", "\n\n", "if", "c", ".", "status", "<", "connStatusIdle", "{", "return", "nil", "\n", "}", "\n", "c", ".", "status", "=", "connStatusClosed", "\n\n", "defer", "func", "(", ")", "{", "c", ".", "conn", ".", "Close", "(", ")", "\n", "c", ".", "causeOfDeath", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "if", "c", ".", "shouldLog", "(", "LogLevelInfo", ")", "{", "c", ".", "log", "(", "LogLevelInfo", ",", "\"", "\"", ",", "nil", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "err", "=", "c", ".", "conn", ".", "SetDeadline", "(", "time", ".", "Time", "{", "}", ")", "\n", "if", "err", "!=", "nil", "&&", "c", ".", "shouldLog", "(", "LogLevelWarn", ")", "{", "c", ".", "log", "(", "LogLevelWarn", ",", "\"", "\"", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", "}", ")", "\n", "return", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "c", ".", "conn", ".", "Write", "(", "[", "]", "byte", "{", "'X'", ",", "0", ",", "0", ",", "0", ",", "4", "}", ")", "\n", "if", "err", "!=", "nil", "&&", "c", ".", "shouldLog", "(", "LogLevelWarn", ")", "{", "c", ".", "log", "(", "LogLevelWarn", ",", "\"", "\"", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", "}", ")", "\n", "return", "err", "\n", "}", "\n\n", "err", "=", "c", ".", "conn", ".", "SetReadDeadline", "(", "time", ".", "Now", "(", ")", ".", "Add", "(", "5", "*", "time", ".", "Second", ")", ")", "\n", "if", "err", "!=", "nil", "&&", "c", ".", "shouldLog", "(", "LogLevelWarn", ")", "{", "c", ".", "log", "(", "LogLevelWarn", ",", "\"", "\"", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", "}", ")", "\n", "return", "err", "\n", "}", "\n\n", "_", ",", "err", "=", "c", ".", "conn", ".", "Read", "(", "make", "(", "[", "]", "byte", ",", "1", ")", ")", "\n", "if", "err", "!=", "io", ".", "EOF", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Close closes a connection. It is safe to call Close on a already closed // connection.
[ "Close", "closes", "a", "connection", ".", "It", "is", "safe", "to", "call", "Close", "on", "a", "already", "closed", "connection", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L626-L667
146,852
jackc/pgx
conn.go
Merge
func (old ConnConfig) Merge(other ConnConfig) ConnConfig { cc := old if other.Host != "" { cc.Host = other.Host } if other.Port != 0 { cc.Port = other.Port } if other.Database != "" { cc.Database = other.Database } if other.User != "" { cc.User = other.User } if other.Password != "" { cc.Password = other.Password } if other.TLSConfig != nil { cc.TLSConfig = other.TLSConfig cc.UseFallbackTLS = other.UseFallbackTLS cc.FallbackTLSConfig = other.FallbackTLSConfig } if other.Logger != nil { cc.Logger = other.Logger } if other.LogLevel != 0 { cc.LogLevel = other.LogLevel } if other.Dial != nil { cc.Dial = other.Dial } cc.PreferSimpleProtocol = old.PreferSimpleProtocol || other.PreferSimpleProtocol cc.RuntimeParams = make(map[string]string) for k, v := range old.RuntimeParams { cc.RuntimeParams[k] = v } for k, v := range other.RuntimeParams { cc.RuntimeParams[k] = v } return cc }
go
func (old ConnConfig) Merge(other ConnConfig) ConnConfig { cc := old if other.Host != "" { cc.Host = other.Host } if other.Port != 0 { cc.Port = other.Port } if other.Database != "" { cc.Database = other.Database } if other.User != "" { cc.User = other.User } if other.Password != "" { cc.Password = other.Password } if other.TLSConfig != nil { cc.TLSConfig = other.TLSConfig cc.UseFallbackTLS = other.UseFallbackTLS cc.FallbackTLSConfig = other.FallbackTLSConfig } if other.Logger != nil { cc.Logger = other.Logger } if other.LogLevel != 0 { cc.LogLevel = other.LogLevel } if other.Dial != nil { cc.Dial = other.Dial } cc.PreferSimpleProtocol = old.PreferSimpleProtocol || other.PreferSimpleProtocol cc.RuntimeParams = make(map[string]string) for k, v := range old.RuntimeParams { cc.RuntimeParams[k] = v } for k, v := range other.RuntimeParams { cc.RuntimeParams[k] = v } return cc }
[ "func", "(", "old", "ConnConfig", ")", "Merge", "(", "other", "ConnConfig", ")", "ConnConfig", "{", "cc", ":=", "old", "\n\n", "if", "other", ".", "Host", "!=", "\"", "\"", "{", "cc", ".", "Host", "=", "other", ".", "Host", "\n", "}", "\n", "if", "other", ".", "Port", "!=", "0", "{", "cc", ".", "Port", "=", "other", ".", "Port", "\n", "}", "\n", "if", "other", ".", "Database", "!=", "\"", "\"", "{", "cc", ".", "Database", "=", "other", ".", "Database", "\n", "}", "\n", "if", "other", ".", "User", "!=", "\"", "\"", "{", "cc", ".", "User", "=", "other", ".", "User", "\n", "}", "\n", "if", "other", ".", "Password", "!=", "\"", "\"", "{", "cc", ".", "Password", "=", "other", ".", "Password", "\n", "}", "\n\n", "if", "other", ".", "TLSConfig", "!=", "nil", "{", "cc", ".", "TLSConfig", "=", "other", ".", "TLSConfig", "\n", "cc", ".", "UseFallbackTLS", "=", "other", ".", "UseFallbackTLS", "\n", "cc", ".", "FallbackTLSConfig", "=", "other", ".", "FallbackTLSConfig", "\n", "}", "\n\n", "if", "other", ".", "Logger", "!=", "nil", "{", "cc", ".", "Logger", "=", "other", ".", "Logger", "\n", "}", "\n", "if", "other", ".", "LogLevel", "!=", "0", "{", "cc", ".", "LogLevel", "=", "other", ".", "LogLevel", "\n", "}", "\n\n", "if", "other", ".", "Dial", "!=", "nil", "{", "cc", ".", "Dial", "=", "other", ".", "Dial", "\n", "}", "\n\n", "cc", ".", "PreferSimpleProtocol", "=", "old", ".", "PreferSimpleProtocol", "||", "other", ".", "PreferSimpleProtocol", "\n\n", "cc", ".", "RuntimeParams", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "k", ",", "v", ":=", "range", "old", ".", "RuntimeParams", "{", "cc", ".", "RuntimeParams", "[", "k", "]", "=", "v", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "other", ".", "RuntimeParams", "{", "cc", ".", "RuntimeParams", "[", "k", "]", "=", "v", "\n", "}", "\n\n", "return", "cc", "\n", "}" ]
// Merge returns a new ConnConfig with the attributes of old and other // combined. When an attribute is set on both, other takes precedence. // // As a security precaution, if the other TLSConfig is nil, all old TLS // attributes will be preserved.
[ "Merge", "returns", "a", "new", "ConnConfig", "with", "the", "attributes", "of", "old", "and", "other", "combined", ".", "When", "an", "attribute", "is", "set", "on", "both", "other", "takes", "precedence", ".", "As", "a", "security", "precaution", "if", "the", "other", "TLSConfig", "is", "nil", "all", "old", "TLS", "attributes", "will", "be", "preserved", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L674-L721
146,853
jackc/pgx
conn.go
ParseURI
func ParseURI(uri string) (ConnConfig, error) { var cp ConnConfig url, err := url.Parse(uri) if err != nil { return cp, err } if url.User != nil { cp.User = url.User.Username() cp.Password, _ = url.User.Password() } parts := strings.SplitN(url.Host, ":", 2) cp.Host = parts[0] if len(parts) == 2 { p, err := strconv.ParseUint(parts[1], 10, 16) if err != nil { return cp, err } cp.Port = uint16(p) } cp.Database = strings.TrimLeft(url.Path, "/") if pgtimeout := url.Query().Get("connect_timeout"); pgtimeout != "" { timeout, err := strconv.ParseInt(pgtimeout, 10, 64) if err != nil { return cp, err } d := defaultDialer() d.Timeout = time.Duration(timeout) * time.Second cp.Dial = d.Dial } tlsArgs := configTLSArgs{ sslCert: url.Query().Get("sslcert"), sslKey: url.Query().Get("sslkey"), sslMode: url.Query().Get("sslmode"), sslRootCert: url.Query().Get("sslrootcert"), } err = configTLS(tlsArgs, &cp) if err != nil { return cp, err } ignoreKeys := map[string]struct{}{ "connect_timeout": {}, "sslcert": {}, "sslkey": {}, "sslmode": {}, "sslrootcert": {}, } cp.RuntimeParams = make(map[string]string) for k, v := range url.Query() { if _, ok := ignoreKeys[k]; ok { continue } if k == "host" { cp.Host = v[0] continue } cp.RuntimeParams[k] = v[0] } if cp.Password == "" { pgpass(&cp) } return cp, nil }
go
func ParseURI(uri string) (ConnConfig, error) { var cp ConnConfig url, err := url.Parse(uri) if err != nil { return cp, err } if url.User != nil { cp.User = url.User.Username() cp.Password, _ = url.User.Password() } parts := strings.SplitN(url.Host, ":", 2) cp.Host = parts[0] if len(parts) == 2 { p, err := strconv.ParseUint(parts[1], 10, 16) if err != nil { return cp, err } cp.Port = uint16(p) } cp.Database = strings.TrimLeft(url.Path, "/") if pgtimeout := url.Query().Get("connect_timeout"); pgtimeout != "" { timeout, err := strconv.ParseInt(pgtimeout, 10, 64) if err != nil { return cp, err } d := defaultDialer() d.Timeout = time.Duration(timeout) * time.Second cp.Dial = d.Dial } tlsArgs := configTLSArgs{ sslCert: url.Query().Get("sslcert"), sslKey: url.Query().Get("sslkey"), sslMode: url.Query().Get("sslmode"), sslRootCert: url.Query().Get("sslrootcert"), } err = configTLS(tlsArgs, &cp) if err != nil { return cp, err } ignoreKeys := map[string]struct{}{ "connect_timeout": {}, "sslcert": {}, "sslkey": {}, "sslmode": {}, "sslrootcert": {}, } cp.RuntimeParams = make(map[string]string) for k, v := range url.Query() { if _, ok := ignoreKeys[k]; ok { continue } if k == "host" { cp.Host = v[0] continue } cp.RuntimeParams[k] = v[0] } if cp.Password == "" { pgpass(&cp) } return cp, nil }
[ "func", "ParseURI", "(", "uri", "string", ")", "(", "ConnConfig", ",", "error", ")", "{", "var", "cp", "ConnConfig", "\n\n", "url", ",", "err", ":=", "url", ".", "Parse", "(", "uri", ")", "\n", "if", "err", "!=", "nil", "{", "return", "cp", ",", "err", "\n", "}", "\n\n", "if", "url", ".", "User", "!=", "nil", "{", "cp", ".", "User", "=", "url", ".", "User", ".", "Username", "(", ")", "\n", "cp", ".", "Password", ",", "_", "=", "url", ".", "User", ".", "Password", "(", ")", "\n", "}", "\n\n", "parts", ":=", "strings", ".", "SplitN", "(", "url", ".", "Host", ",", "\"", "\"", ",", "2", ")", "\n", "cp", ".", "Host", "=", "parts", "[", "0", "]", "\n", "if", "len", "(", "parts", ")", "==", "2", "{", "p", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "parts", "[", "1", "]", ",", "10", ",", "16", ")", "\n", "if", "err", "!=", "nil", "{", "return", "cp", ",", "err", "\n", "}", "\n", "cp", ".", "Port", "=", "uint16", "(", "p", ")", "\n", "}", "\n", "cp", ".", "Database", "=", "strings", ".", "TrimLeft", "(", "url", ".", "Path", ",", "\"", "\"", ")", "\n\n", "if", "pgtimeout", ":=", "url", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ";", "pgtimeout", "!=", "\"", "\"", "{", "timeout", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "pgtimeout", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "cp", ",", "err", "\n", "}", "\n", "d", ":=", "defaultDialer", "(", ")", "\n", "d", ".", "Timeout", "=", "time", ".", "Duration", "(", "timeout", ")", "*", "time", ".", "Second", "\n", "cp", ".", "Dial", "=", "d", ".", "Dial", "\n", "}", "\n\n", "tlsArgs", ":=", "configTLSArgs", "{", "sslCert", ":", "url", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ",", "sslKey", ":", "url", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ",", "sslMode", ":", "url", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ",", "sslRootCert", ":", "url", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ",", "}", "\n", "err", "=", "configTLS", "(", "tlsArgs", ",", "&", "cp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "cp", ",", "err", "\n", "}", "\n\n", "ignoreKeys", ":=", "map", "[", "string", "]", "struct", "{", "}", "{", "\"", "\"", ":", "{", "}", ",", "\"", "\"", ":", "{", "}", ",", "\"", "\"", ":", "{", "}", ",", "\"", "\"", ":", "{", "}", ",", "\"", "\"", ":", "{", "}", ",", "}", "\n\n", "cp", ".", "RuntimeParams", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "url", ".", "Query", "(", ")", "{", "if", "_", ",", "ok", ":=", "ignoreKeys", "[", "k", "]", ";", "ok", "{", "continue", "\n", "}", "\n\n", "if", "k", "==", "\"", "\"", "{", "cp", ".", "Host", "=", "v", "[", "0", "]", "\n", "continue", "\n", "}", "\n\n", "cp", ".", "RuntimeParams", "[", "k", "]", "=", "v", "[", "0", "]", "\n", "}", "\n", "if", "cp", ".", "Password", "==", "\"", "\"", "{", "pgpass", "(", "&", "cp", ")", "\n", "}", "\n", "return", "cp", ",", "nil", "\n", "}" ]
// ParseURI parses a database URI into ConnConfig // // Query parameters not used by the connection process are parsed into ConnConfig.RuntimeParams.
[ "ParseURI", "parses", "a", "database", "URI", "into", "ConnConfig", "Query", "parameters", "not", "used", "by", "the", "connection", "process", "are", "parsed", "into", "ConnConfig", ".", "RuntimeParams", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L726-L797
146,854
jackc/pgx
conn.go
ParseConnectionString
func ParseConnectionString(s string) (ConnConfig, error) { if u, err := url.Parse(s); err == nil && u.Scheme != "" { return ParseURI(s) } return ParseDSN(s) }
go
func ParseConnectionString(s string) (ConnConfig, error) { if u, err := url.Parse(s); err == nil && u.Scheme != "" { return ParseURI(s) } return ParseDSN(s) }
[ "func", "ParseConnectionString", "(", "s", "string", ")", "(", "ConnConfig", ",", "error", ")", "{", "if", "u", ",", "err", ":=", "url", ".", "Parse", "(", "s", ")", ";", "err", "==", "nil", "&&", "u", ".", "Scheme", "!=", "\"", "\"", "{", "return", "ParseURI", "(", "s", ")", "\n", "}", "\n", "return", "ParseDSN", "(", "s", ")", "\n", "}" ]
// ParseConnectionString parses either a URI or a DSN connection string. // see ParseURI and ParseDSN for details.
[ "ParseConnectionString", "parses", "either", "a", "URI", "or", "a", "DSN", "connection", "string", ".", "see", "ParseURI", "and", "ParseDSN", "for", "details", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L870-L875
146,855
jackc/pgx
conn.go
Deallocate
func (c *Conn) Deallocate(name string) error { return c.deallocateContext(context.Background(), name) }
go
func (c *Conn) Deallocate(name string) error { return c.deallocateContext(context.Background(), name) }
[ "func", "(", "c", "*", "Conn", ")", "Deallocate", "(", "name", "string", ")", "error", "{", "return", "c", ".", "deallocateContext", "(", "context", ".", "Background", "(", ")", ",", "name", ")", "\n", "}" ]
// Deallocate released a prepared statement
[ "Deallocate", "released", "a", "prepared", "statement" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L1155-L1157
146,856
jackc/pgx
conn.go
Unlisten
func (c *Conn) Unlisten(channel string) error { _, err := c.Exec("unlisten " + quoteIdentifier(channel)) if err != nil { return err } delete(c.channels, channel) return nil }
go
func (c *Conn) Unlisten(channel string) error { _, err := c.Exec("unlisten " + quoteIdentifier(channel)) if err != nil { return err } delete(c.channels, channel) return nil }
[ "func", "(", "c", "*", "Conn", ")", "Unlisten", "(", "channel", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "Exec", "(", "\"", "\"", "+", "quoteIdentifier", "(", "channel", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "delete", "(", "c", ".", "channels", ",", "channel", ")", "\n", "return", "nil", "\n", "}" ]
// Unlisten unsubscribes from a listen channel
[ "Unlisten", "unsubscribes", "from", "a", "listen", "channel" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L1231-L1239
146,857
jackc/pgx
conn.go
WaitForNotification
func (c *Conn) WaitForNotification(ctx context.Context) (notification *Notification, err error) { // Return already received notification immediately if len(c.notifications) > 0 { notification := c.notifications[0] c.notifications = c.notifications[1:] return notification, nil } err = c.waitForPreviousCancelQuery(ctx) if err != nil { return nil, err } err = c.initContext(ctx) if err != nil { return nil, err } defer func() { err = c.termContext(err) }() if err = c.lock(); err != nil { return nil, err } defer func() { if unlockErr := c.unlock(); unlockErr != nil && err == nil { err = unlockErr } }() if err := c.ensureConnectionReadyForQuery(); err != nil { return nil, err } for { msg, err := c.rxMsg() if err != nil { return nil, err } err = c.processContextFreeMsg(msg) if err != nil { return nil, err } if len(c.notifications) > 0 { notification := c.notifications[0] c.notifications = c.notifications[1:] return notification, nil } } }
go
func (c *Conn) WaitForNotification(ctx context.Context) (notification *Notification, err error) { // Return already received notification immediately if len(c.notifications) > 0 { notification := c.notifications[0] c.notifications = c.notifications[1:] return notification, nil } err = c.waitForPreviousCancelQuery(ctx) if err != nil { return nil, err } err = c.initContext(ctx) if err != nil { return nil, err } defer func() { err = c.termContext(err) }() if err = c.lock(); err != nil { return nil, err } defer func() { if unlockErr := c.unlock(); unlockErr != nil && err == nil { err = unlockErr } }() if err := c.ensureConnectionReadyForQuery(); err != nil { return nil, err } for { msg, err := c.rxMsg() if err != nil { return nil, err } err = c.processContextFreeMsg(msg) if err != nil { return nil, err } if len(c.notifications) > 0 { notification := c.notifications[0] c.notifications = c.notifications[1:] return notification, nil } } }
[ "func", "(", "c", "*", "Conn", ")", "WaitForNotification", "(", "ctx", "context", ".", "Context", ")", "(", "notification", "*", "Notification", ",", "err", "error", ")", "{", "// Return already received notification immediately", "if", "len", "(", "c", ".", "notifications", ")", ">", "0", "{", "notification", ":=", "c", ".", "notifications", "[", "0", "]", "\n", "c", ".", "notifications", "=", "c", ".", "notifications", "[", "1", ":", "]", "\n", "return", "notification", ",", "nil", "\n", "}", "\n\n", "err", "=", "c", ".", "waitForPreviousCancelQuery", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "c", ".", "initContext", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "err", "=", "c", ".", "termContext", "(", "err", ")", "\n", "}", "(", ")", "\n\n", "if", "err", "=", "c", ".", "lock", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "func", "(", ")", "{", "if", "unlockErr", ":=", "c", ".", "unlock", "(", ")", ";", "unlockErr", "!=", "nil", "&&", "err", "==", "nil", "{", "err", "=", "unlockErr", "\n", "}", "\n", "}", "(", ")", "\n\n", "if", "err", ":=", "c", ".", "ensureConnectionReadyForQuery", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "{", "msg", ",", "err", ":=", "c", ".", "rxMsg", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "c", ".", "processContextFreeMsg", "(", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "c", ".", "notifications", ")", ">", "0", "{", "notification", ":=", "c", ".", "notifications", "[", "0", "]", "\n", "c", ".", "notifications", "=", "c", ".", "notifications", "[", "1", ":", "]", "\n", "return", "notification", ",", "nil", "\n", "}", "\n", "}", "\n", "}" ]
// WaitForNotification waits for a PostgreSQL notification.
[ "WaitForNotification", "waits", "for", "a", "PostgreSQL", "notification", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L1242-L1293
146,858
jackc/pgx
conn.go
processContextFreeMsg
func (c *Conn) processContextFreeMsg(msg pgproto3.BackendMessage) (err error) { switch msg := msg.(type) { case *pgproto3.ErrorResponse: return c.rxErrorResponse(msg) case *pgproto3.NoticeResponse: c.rxNoticeResponse(msg) case *pgproto3.NotificationResponse: c.rxNotificationResponse(msg) case *pgproto3.ReadyForQuery: c.rxReadyForQuery(msg) case *pgproto3.ParameterStatus: c.rxParameterStatus(msg) } return nil }
go
func (c *Conn) processContextFreeMsg(msg pgproto3.BackendMessage) (err error) { switch msg := msg.(type) { case *pgproto3.ErrorResponse: return c.rxErrorResponse(msg) case *pgproto3.NoticeResponse: c.rxNoticeResponse(msg) case *pgproto3.NotificationResponse: c.rxNotificationResponse(msg) case *pgproto3.ReadyForQuery: c.rxReadyForQuery(msg) case *pgproto3.ParameterStatus: c.rxParameterStatus(msg) } return nil }
[ "func", "(", "c", "*", "Conn", ")", "processContextFreeMsg", "(", "msg", "pgproto3", ".", "BackendMessage", ")", "(", "err", "error", ")", "{", "switch", "msg", ":=", "msg", ".", "(", "type", ")", "{", "case", "*", "pgproto3", ".", "ErrorResponse", ":", "return", "c", ".", "rxErrorResponse", "(", "msg", ")", "\n", "case", "*", "pgproto3", ".", "NoticeResponse", ":", "c", ".", "rxNoticeResponse", "(", "msg", ")", "\n", "case", "*", "pgproto3", ".", "NotificationResponse", ":", "c", ".", "rxNotificationResponse", "(", "msg", ")", "\n", "case", "*", "pgproto3", ".", "ReadyForQuery", ":", "c", ".", "rxReadyForQuery", "(", "msg", ")", "\n", "case", "*", "pgproto3", ".", "ParameterStatus", ":", "c", ".", "rxParameterStatus", "(", "msg", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Processes messages that are not exclusive to one context such as // authentication or query response. The response to these messages is the same // regardless of when they occur. It also ignores messages that are only // meaningful in a given context. These messages can occur due to a context // deadline interrupting message processing. For example, an interrupted query // may have left DataRow messages on the wire.
[ "Processes", "messages", "that", "are", "not", "exclusive", "to", "one", "context", "such", "as", "authentication", "or", "query", "response", ".", "The", "response", "to", "these", "messages", "is", "the", "same", "regardless", "of", "when", "they", "occur", ".", "It", "also", "ignores", "messages", "that", "are", "only", "meaningful", "in", "a", "given", "context", ".", "These", "messages", "can", "occur", "due", "to", "a", "context", "deadline", "interrupting", "message", "processing", ".", "For", "example", "an", "interrupted", "query", "may", "have", "left", "DataRow", "messages", "on", "the", "wire", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L1383-L1398
146,859
jackc/pgx
conn.go
SetLogger
func (c *Conn) SetLogger(logger Logger) Logger { oldLogger := c.logger c.logger = logger return oldLogger }
go
func (c *Conn) SetLogger(logger Logger) Logger { oldLogger := c.logger c.logger = logger return oldLogger }
[ "func", "(", "c", "*", "Conn", ")", "SetLogger", "(", "logger", "Logger", ")", "Logger", "{", "oldLogger", ":=", "c", ".", "logger", "\n", "c", ".", "logger", "=", "logger", "\n", "return", "oldLogger", "\n", "}" ]
// SetLogger replaces the current logger and returns the previous logger.
[ "SetLogger", "replaces", "the", "current", "logger", "and", "returns", "the", "previous", "logger", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L1630-L1634
146,860
jackc/pgx
conn.go
SetLogLevel
func (c *Conn) SetLogLevel(lvl LogLevel) (LogLevel, error) { oldLvl := c.logLevel if lvl < LogLevelNone || lvl > LogLevelTrace { return oldLvl, ErrInvalidLogLevel } c.logLevel = lvl return lvl, nil }
go
func (c *Conn) SetLogLevel(lvl LogLevel) (LogLevel, error) { oldLvl := c.logLevel if lvl < LogLevelNone || lvl > LogLevelTrace { return oldLvl, ErrInvalidLogLevel } c.logLevel = lvl return lvl, nil }
[ "func", "(", "c", "*", "Conn", ")", "SetLogLevel", "(", "lvl", "LogLevel", ")", "(", "LogLevel", ",", "error", ")", "{", "oldLvl", ":=", "c", ".", "logLevel", "\n\n", "if", "lvl", "<", "LogLevelNone", "||", "lvl", ">", "LogLevelTrace", "{", "return", "oldLvl", ",", "ErrInvalidLogLevel", "\n", "}", "\n\n", "c", ".", "logLevel", "=", "lvl", "\n", "return", "lvl", ",", "nil", "\n", "}" ]
// SetLogLevel replaces the current log level and returns the previous log // level.
[ "SetLogLevel", "replaces", "the", "current", "log", "level", "and", "returns", "the", "previous", "log", "level", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L1638-L1647
146,861
jackc/pgx
conn.go
WaitUntilReady
func (c *Conn) WaitUntilReady(ctx context.Context) error { err := c.waitForPreviousCancelQuery(ctx) if err != nil { return err } return c.ensureConnectionReadyForQuery() }
go
func (c *Conn) WaitUntilReady(ctx context.Context) error { err := c.waitForPreviousCancelQuery(ctx) if err != nil { return err } return c.ensureConnectionReadyForQuery() }
[ "func", "(", "c", "*", "Conn", ")", "WaitUntilReady", "(", "ctx", "context", ".", "Context", ")", "error", "{", "err", ":=", "c", ".", "waitForPreviousCancelQuery", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "c", ".", "ensureConnectionReadyForQuery", "(", ")", "\n", "}" ]
// WaitUntilReady will return when the connection is ready for another query
[ "WaitUntilReady", "will", "return", "when", "the", "connection", "is", "ready", "for", "another", "query" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn.go#L1904-L1910
146,862
jackc/pgx
replication.go
SendStandbyStatus
func (rc *ReplicationConn) SendStandbyStatus(k *StandbyStatus) (err error) { buf := rc.wbuf buf = append(buf, copyData) sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, standbyStatusUpdate) buf = pgio.AppendInt64(buf, int64(k.WalWritePosition)) buf = pgio.AppendInt64(buf, int64(k.WalFlushPosition)) buf = pgio.AppendInt64(buf, int64(k.WalApplyPosition)) buf = pgio.AppendInt64(buf, int64(k.ClientTime)) buf = append(buf, k.ReplyRequested) pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) _, err = rc.conn.Write(buf) if err != nil { rc.die(err) } return }
go
func (rc *ReplicationConn) SendStandbyStatus(k *StandbyStatus) (err error) { buf := rc.wbuf buf = append(buf, copyData) sp := len(buf) buf = pgio.AppendInt32(buf, -1) buf = append(buf, standbyStatusUpdate) buf = pgio.AppendInt64(buf, int64(k.WalWritePosition)) buf = pgio.AppendInt64(buf, int64(k.WalFlushPosition)) buf = pgio.AppendInt64(buf, int64(k.WalApplyPosition)) buf = pgio.AppendInt64(buf, int64(k.ClientTime)) buf = append(buf, k.ReplyRequested) pgio.SetInt32(buf[sp:], int32(len(buf[sp:]))) _, err = rc.conn.Write(buf) if err != nil { rc.die(err) } return }
[ "func", "(", "rc", "*", "ReplicationConn", ")", "SendStandbyStatus", "(", "k", "*", "StandbyStatus", ")", "(", "err", "error", ")", "{", "buf", ":=", "rc", ".", "wbuf", "\n", "buf", "=", "append", "(", "buf", ",", "copyData", ")", "\n", "sp", ":=", "len", "(", "buf", ")", "\n", "buf", "=", "pgio", ".", "AppendInt32", "(", "buf", ",", "-", "1", ")", "\n\n", "buf", "=", "append", "(", "buf", ",", "standbyStatusUpdate", ")", "\n", "buf", "=", "pgio", ".", "AppendInt64", "(", "buf", ",", "int64", "(", "k", ".", "WalWritePosition", ")", ")", "\n", "buf", "=", "pgio", ".", "AppendInt64", "(", "buf", ",", "int64", "(", "k", ".", "WalFlushPosition", ")", ")", "\n", "buf", "=", "pgio", ".", "AppendInt64", "(", "buf", ",", "int64", "(", "k", ".", "WalApplyPosition", ")", ")", "\n", "buf", "=", "pgio", ".", "AppendInt64", "(", "buf", ",", "int64", "(", "k", ".", "ClientTime", ")", ")", "\n", "buf", "=", "append", "(", "buf", ",", "k", ".", "ReplyRequested", ")", "\n\n", "pgio", ".", "SetInt32", "(", "buf", "[", "sp", ":", "]", ",", "int32", "(", "len", "(", "buf", "[", "sp", ":", "]", ")", ")", ")", "\n\n", "_", ",", "err", "=", "rc", ".", "conn", ".", "Write", "(", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "rc", ".", "die", "(", "err", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// Send standby status to the server, which both acts as a keepalive // message to the server, as well as carries the WAL position of the // client, which then updates the server's replication slot position.
[ "Send", "standby", "status", "to", "the", "server", "which", "both", "acts", "as", "a", "keepalive", "message", "to", "the", "server", "as", "well", "as", "carries", "the", "WAL", "position", "of", "the", "client", "which", "then", "updates", "the", "server", "s", "replication", "slot", "position", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/replication.go#L193-L214
146,863
jackc/pgx
replication.go
CreateReplicationSlot
func (rc *ReplicationConn) CreateReplicationSlot(slotName, outputPlugin string) (err error) { _, err = rc.Exec(fmt.Sprintf("CREATE_REPLICATION_SLOT %s LOGICAL %s NOEXPORT_SNAPSHOT", slotName, outputPlugin)) return }
go
func (rc *ReplicationConn) CreateReplicationSlot(slotName, outputPlugin string) (err error) { _, err = rc.Exec(fmt.Sprintf("CREATE_REPLICATION_SLOT %s LOGICAL %s NOEXPORT_SNAPSHOT", slotName, outputPlugin)) return }
[ "func", "(", "rc", "*", "ReplicationConn", ")", "CreateReplicationSlot", "(", "slotName", ",", "outputPlugin", "string", ")", "(", "err", "error", ")", "{", "_", ",", "err", "=", "rc", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "slotName", ",", "outputPlugin", ")", ")", "\n", "return", "\n", "}" ]
// Create the replication slot, using the given name and output plugin.
[ "Create", "the", "replication", "slot", "using", "the", "given", "name", "and", "output", "plugin", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/replication.go#L443-L446
146,864
jackc/pgx
replication.go
CreateReplicationSlotEx
func (rc *ReplicationConn) CreateReplicationSlotEx(slotName, outputPlugin string) (consistentPoint string, snapshotName string, err error) { var dummy string var rows *Rows rows, err = rc.sendReplicationModeQuery(fmt.Sprintf("CREATE_REPLICATION_SLOT %s LOGICAL %s", slotName, outputPlugin)) defer rows.Close() for rows.Next() { rows.Scan(&dummy, &consistentPoint, &snapshotName, &dummy) } return }
go
func (rc *ReplicationConn) CreateReplicationSlotEx(slotName, outputPlugin string) (consistentPoint string, snapshotName string, err error) { var dummy string var rows *Rows rows, err = rc.sendReplicationModeQuery(fmt.Sprintf("CREATE_REPLICATION_SLOT %s LOGICAL %s", slotName, outputPlugin)) defer rows.Close() for rows.Next() { rows.Scan(&dummy, &consistentPoint, &snapshotName, &dummy) } return }
[ "func", "(", "rc", "*", "ReplicationConn", ")", "CreateReplicationSlotEx", "(", "slotName", ",", "outputPlugin", "string", ")", "(", "consistentPoint", "string", ",", "snapshotName", "string", ",", "err", "error", ")", "{", "var", "dummy", "string", "\n", "var", "rows", "*", "Rows", "\n", "rows", ",", "err", "=", "rc", ".", "sendReplicationModeQuery", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "slotName", ",", "outputPlugin", ")", ")", "\n", "defer", "rows", ".", "Close", "(", ")", "\n", "for", "rows", ".", "Next", "(", ")", "{", "rows", ".", "Scan", "(", "&", "dummy", ",", "&", "consistentPoint", ",", "&", "snapshotName", ",", "&", "dummy", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Create the replication slot, using the given name and output plugin, and return the consistent_point and snapshot_name values.
[ "Create", "the", "replication", "slot", "using", "the", "given", "name", "and", "output", "plugin", "and", "return", "the", "consistent_point", "and", "snapshot_name", "values", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/replication.go#L449-L458
146,865
jackc/pgx
replication.go
DropReplicationSlot
func (rc *ReplicationConn) DropReplicationSlot(slotName string) (err error) { _, err = rc.Exec(fmt.Sprintf("DROP_REPLICATION_SLOT %s", slotName)) return }
go
func (rc *ReplicationConn) DropReplicationSlot(slotName string) (err error) { _, err = rc.Exec(fmt.Sprintf("DROP_REPLICATION_SLOT %s", slotName)) return }
[ "func", "(", "rc", "*", "ReplicationConn", ")", "DropReplicationSlot", "(", "slotName", "string", ")", "(", "err", "error", ")", "{", "_", ",", "err", "=", "rc", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "slotName", ")", ")", "\n", "return", "\n", "}" ]
// Drop the replication slot for the given name
[ "Drop", "the", "replication", "slot", "for", "the", "given", "name" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/replication.go#L461-L464
146,866
jackc/pgx
auth_scram.go
scramAuth
func (c *Conn) scramAuth(serverAuthMechanisms []string) error { sc, err := newScramClient(serverAuthMechanisms, c.config.Password) if err != nil { return err } // Send client-first-message in a SASLInitialResponse saslInitialResponse := &pgproto3.SASLInitialResponse{ AuthMechanism: "SCRAM-SHA-256", Data: sc.clientFirstMessage(), } _, err = c.conn.Write(saslInitialResponse.Encode(nil)) if err != nil { return err } // Receive server-first-message payload in a AuthenticationSASLContinue. authMsg, err := c.rxAuthMsg(pgproto3.AuthTypeSASLContinue) if err != nil { return err } err = sc.recvServerFirstMessage(authMsg.SASLData) if err != nil { return err } // Send client-final-message in a SASLResponse saslResponse := &pgproto3.SASLResponse{ Data: []byte(sc.clientFinalMessage()), } _, err = c.conn.Write(saslResponse.Encode(nil)) if err != nil { return err } // Receive server-final-message payload in a AuthenticationSASLFinal. authMsg, err = c.rxAuthMsg(pgproto3.AuthTypeSASLFinal) if err != nil { return err } return sc.recvServerFinalMessage(authMsg.SASLData) }
go
func (c *Conn) scramAuth(serverAuthMechanisms []string) error { sc, err := newScramClient(serverAuthMechanisms, c.config.Password) if err != nil { return err } // Send client-first-message in a SASLInitialResponse saslInitialResponse := &pgproto3.SASLInitialResponse{ AuthMechanism: "SCRAM-SHA-256", Data: sc.clientFirstMessage(), } _, err = c.conn.Write(saslInitialResponse.Encode(nil)) if err != nil { return err } // Receive server-first-message payload in a AuthenticationSASLContinue. authMsg, err := c.rxAuthMsg(pgproto3.AuthTypeSASLContinue) if err != nil { return err } err = sc.recvServerFirstMessage(authMsg.SASLData) if err != nil { return err } // Send client-final-message in a SASLResponse saslResponse := &pgproto3.SASLResponse{ Data: []byte(sc.clientFinalMessage()), } _, err = c.conn.Write(saslResponse.Encode(nil)) if err != nil { return err } // Receive server-final-message payload in a AuthenticationSASLFinal. authMsg, err = c.rxAuthMsg(pgproto3.AuthTypeSASLFinal) if err != nil { return err } return sc.recvServerFinalMessage(authMsg.SASLData) }
[ "func", "(", "c", "*", "Conn", ")", "scramAuth", "(", "serverAuthMechanisms", "[", "]", "string", ")", "error", "{", "sc", ",", "err", ":=", "newScramClient", "(", "serverAuthMechanisms", ",", "c", ".", "config", ".", "Password", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Send client-first-message in a SASLInitialResponse", "saslInitialResponse", ":=", "&", "pgproto3", ".", "SASLInitialResponse", "{", "AuthMechanism", ":", "\"", "\"", ",", "Data", ":", "sc", ".", "clientFirstMessage", "(", ")", ",", "}", "\n", "_", ",", "err", "=", "c", ".", "conn", ".", "Write", "(", "saslInitialResponse", ".", "Encode", "(", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Receive server-first-message payload in a AuthenticationSASLContinue.", "authMsg", ",", "err", ":=", "c", ".", "rxAuthMsg", "(", "pgproto3", ".", "AuthTypeSASLContinue", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "sc", ".", "recvServerFirstMessage", "(", "authMsg", ".", "SASLData", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Send client-final-message in a SASLResponse", "saslResponse", ":=", "&", "pgproto3", ".", "SASLResponse", "{", "Data", ":", "[", "]", "byte", "(", "sc", ".", "clientFinalMessage", "(", ")", ")", ",", "}", "\n", "_", ",", "err", "=", "c", ".", "conn", ".", "Write", "(", "saslResponse", ".", "Encode", "(", "nil", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Receive server-final-message payload in a AuthenticationSASLFinal.", "authMsg", ",", "err", "=", "c", ".", "rxAuthMsg", "(", "pgproto3", ".", "AuthTypeSASLFinal", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "sc", ".", "recvServerFinalMessage", "(", "authMsg", ".", "SASLData", ")", "\n", "}" ]
// Perform SCRAM authentication.
[ "Perform", "SCRAM", "authentication", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/auth_scram.go#L32-L73
146,867
jackc/pgx
copy_from.go
CopyFrom
func (c *Conn) CopyFrom(tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int, error) { ct := &copyFrom{ conn: c, tableName: tableName, columnNames: columnNames, rowSrc: rowSrc, readerErrChan: make(chan error), } return ct.run() }
go
func (c *Conn) CopyFrom(tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int, error) { ct := &copyFrom{ conn: c, tableName: tableName, columnNames: columnNames, rowSrc: rowSrc, readerErrChan: make(chan error), } return ct.run() }
[ "func", "(", "c", "*", "Conn", ")", "CopyFrom", "(", "tableName", "Identifier", ",", "columnNames", "[", "]", "string", ",", "rowSrc", "CopyFromSource", ")", "(", "int", ",", "error", ")", "{", "ct", ":=", "&", "copyFrom", "{", "conn", ":", "c", ",", "tableName", ":", "tableName", ",", "columnNames", ":", "columnNames", ",", "rowSrc", ":", "rowSrc", ",", "readerErrChan", ":", "make", "(", "chan", "error", ")", ",", "}", "\n\n", "return", "ct", ".", "run", "(", ")", "\n", "}" ]
// CopyFrom uses the PostgreSQL copy protocol to perform bulk data insertion. // It returns the number of rows copied and an error. // // CopyFrom requires all values use the binary format. Almost all types // implemented by pgx use the binary format by default. Types implementing // Encoder can only be used if they encode to the binary format.
[ "CopyFrom", "uses", "the", "PostgreSQL", "copy", "protocol", "to", "perform", "bulk", "data", "insertion", ".", "It", "returns", "the", "number", "of", "rows", "copied", "and", "an", "error", ".", "CopyFrom", "requires", "all", "values", "use", "the", "binary", "format", ".", "Almost", "all", "types", "implemented", "by", "pgx", "use", "the", "binary", "format", "by", "default", ".", "Types", "implementing", "Encoder", "can", "only", "be", "used", "if", "they", "encode", "to", "the", "binary", "format", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/copy_from.go#L274-L284
146,868
jackc/pgx
copy_from.go
CopyFromReader
func (c *Conn) CopyFromReader(r io.Reader, sql string) (CommandTag, error) { if err := c.sendSimpleQuery(sql); err != nil { return "", err } if err := c.readUntilCopyInResponse(); err != nil { return "", err } buf := c.wbuf buf = append(buf, copyData) sp := len(buf) for { n, err := r.Read(buf[5:cap(buf)]) if err == io.EOF && n == 0 { break } buf = buf[0 : n+5] pgio.SetInt32(buf[sp:], int32(n+4)) if _, err := c.conn.Write(buf); err != nil { return "", err } } buf = buf[:0] buf = append(buf, copyDone) buf = pgio.AppendInt32(buf, 4) if _, err := c.conn.Write(buf); err != nil { return "", err } for { msg, err := c.rxMsg() if err != nil { return "", err } switch msg := msg.(type) { case *pgproto3.ReadyForQuery: c.rxReadyForQuery(msg) return "", err case *pgproto3.CommandComplete: return CommandTag(msg.CommandTag), nil case *pgproto3.ErrorResponse: return "", c.rxErrorResponse(msg) default: return "", c.processContextFreeMsg(msg) } } }
go
func (c *Conn) CopyFromReader(r io.Reader, sql string) (CommandTag, error) { if err := c.sendSimpleQuery(sql); err != nil { return "", err } if err := c.readUntilCopyInResponse(); err != nil { return "", err } buf := c.wbuf buf = append(buf, copyData) sp := len(buf) for { n, err := r.Read(buf[5:cap(buf)]) if err == io.EOF && n == 0 { break } buf = buf[0 : n+5] pgio.SetInt32(buf[sp:], int32(n+4)) if _, err := c.conn.Write(buf); err != nil { return "", err } } buf = buf[:0] buf = append(buf, copyDone) buf = pgio.AppendInt32(buf, 4) if _, err := c.conn.Write(buf); err != nil { return "", err } for { msg, err := c.rxMsg() if err != nil { return "", err } switch msg := msg.(type) { case *pgproto3.ReadyForQuery: c.rxReadyForQuery(msg) return "", err case *pgproto3.CommandComplete: return CommandTag(msg.CommandTag), nil case *pgproto3.ErrorResponse: return "", c.rxErrorResponse(msg) default: return "", c.processContextFreeMsg(msg) } } }
[ "func", "(", "c", "*", "Conn", ")", "CopyFromReader", "(", "r", "io", ".", "Reader", ",", "sql", "string", ")", "(", "CommandTag", ",", "error", ")", "{", "if", "err", ":=", "c", ".", "sendSimpleQuery", "(", "sql", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "c", ".", "readUntilCopyInResponse", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "buf", ":=", "c", ".", "wbuf", "\n\n", "buf", "=", "append", "(", "buf", ",", "copyData", ")", "\n", "sp", ":=", "len", "(", "buf", ")", "\n", "for", "{", "n", ",", "err", ":=", "r", ".", "Read", "(", "buf", "[", "5", ":", "cap", "(", "buf", ")", "]", ")", "\n", "if", "err", "==", "io", ".", "EOF", "&&", "n", "==", "0", "{", "break", "\n", "}", "\n", "buf", "=", "buf", "[", "0", ":", "n", "+", "5", "]", "\n", "pgio", ".", "SetInt32", "(", "buf", "[", "sp", ":", "]", ",", "int32", "(", "n", "+", "4", ")", ")", "\n\n", "if", "_", ",", "err", ":=", "c", ".", "conn", ".", "Write", "(", "buf", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "}", "\n\n", "buf", "=", "buf", "[", ":", "0", "]", "\n", "buf", "=", "append", "(", "buf", ",", "copyDone", ")", "\n", "buf", "=", "pgio", ".", "AppendInt32", "(", "buf", ",", "4", ")", "\n\n", "if", "_", ",", "err", ":=", "c", ".", "conn", ".", "Write", "(", "buf", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "for", "{", "msg", ",", "err", ":=", "c", ".", "rxMsg", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "switch", "msg", ":=", "msg", ".", "(", "type", ")", "{", "case", "*", "pgproto3", ".", "ReadyForQuery", ":", "c", ".", "rxReadyForQuery", "(", "msg", ")", "\n", "return", "\"", "\"", ",", "err", "\n", "case", "*", "pgproto3", ".", "CommandComplete", ":", "return", "CommandTag", "(", "msg", ".", "CommandTag", ")", ",", "nil", "\n", "case", "*", "pgproto3", ".", "ErrorResponse", ":", "return", "\"", "\"", ",", "c", ".", "rxErrorResponse", "(", "msg", ")", "\n", "default", ":", "return", "\"", "\"", ",", "c", ".", "processContextFreeMsg", "(", "msg", ")", "\n", "}", "\n", "}", "\n", "}" ]
// CopyFromReader uses the PostgreSQL textual format of the copy protocol
[ "CopyFromReader", "uses", "the", "PostgreSQL", "textual", "format", "of", "the", "copy", "protocol" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/copy_from.go#L287-L338
146,869
jackc/pgx
query.go
Close
func (rows *Rows) Close() { if rows.closed { return } if rows.unlockConn { rows.conn.unlock() rows.unlockConn = false } rows.closed = true rows.err = rows.conn.termContext(rows.err) if rows.err == nil { if rows.conn.shouldLog(LogLevelInfo) { endTime := time.Now() rows.conn.log(LogLevelInfo, "Query", map[string]interface{}{"sql": rows.sql, "args": logQueryArgs(rows.args), "time": endTime.Sub(rows.startTime), "rowCount": rows.rowCount}) } } else if rows.conn.shouldLog(LogLevelError) { rows.conn.log(LogLevelError, "Query", map[string]interface{}{"sql": rows.sql, "args": logQueryArgs(rows.args)}) } if rows.batch != nil && rows.err != nil { rows.batch.die(rows.err) } if rows.connPool != nil { rows.connPool.Release(rows.conn) } }
go
func (rows *Rows) Close() { if rows.closed { return } if rows.unlockConn { rows.conn.unlock() rows.unlockConn = false } rows.closed = true rows.err = rows.conn.termContext(rows.err) if rows.err == nil { if rows.conn.shouldLog(LogLevelInfo) { endTime := time.Now() rows.conn.log(LogLevelInfo, "Query", map[string]interface{}{"sql": rows.sql, "args": logQueryArgs(rows.args), "time": endTime.Sub(rows.startTime), "rowCount": rows.rowCount}) } } else if rows.conn.shouldLog(LogLevelError) { rows.conn.log(LogLevelError, "Query", map[string]interface{}{"sql": rows.sql, "args": logQueryArgs(rows.args)}) } if rows.batch != nil && rows.err != nil { rows.batch.die(rows.err) } if rows.connPool != nil { rows.connPool.Release(rows.conn) } }
[ "func", "(", "rows", "*", "Rows", ")", "Close", "(", ")", "{", "if", "rows", ".", "closed", "{", "return", "\n", "}", "\n\n", "if", "rows", ".", "unlockConn", "{", "rows", ".", "conn", ".", "unlock", "(", ")", "\n", "rows", ".", "unlockConn", "=", "false", "\n", "}", "\n\n", "rows", ".", "closed", "=", "true", "\n\n", "rows", ".", "err", "=", "rows", ".", "conn", ".", "termContext", "(", "rows", ".", "err", ")", "\n\n", "if", "rows", ".", "err", "==", "nil", "{", "if", "rows", ".", "conn", ".", "shouldLog", "(", "LogLevelInfo", ")", "{", "endTime", ":=", "time", ".", "Now", "(", ")", "\n", "rows", ".", "conn", ".", "log", "(", "LogLevelInfo", ",", "\"", "\"", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "rows", ".", "sql", ",", "\"", "\"", ":", "logQueryArgs", "(", "rows", ".", "args", ")", ",", "\"", "\"", ":", "endTime", ".", "Sub", "(", "rows", ".", "startTime", ")", ",", "\"", "\"", ":", "rows", ".", "rowCount", "}", ")", "\n", "}", "\n", "}", "else", "if", "rows", ".", "conn", ".", "shouldLog", "(", "LogLevelError", ")", "{", "rows", ".", "conn", ".", "log", "(", "LogLevelError", ",", "\"", "\"", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "rows", ".", "sql", ",", "\"", "\"", ":", "logQueryArgs", "(", "rows", ".", "args", ")", "}", ")", "\n", "}", "\n\n", "if", "rows", ".", "batch", "!=", "nil", "&&", "rows", ".", "err", "!=", "nil", "{", "rows", ".", "batch", ".", "die", "(", "rows", ".", "err", ")", "\n", "}", "\n\n", "if", "rows", ".", "connPool", "!=", "nil", "{", "rows", ".", "connPool", ".", "Release", "(", "rows", ".", "conn", ")", "\n", "}", "\n", "}" ]
// Close closes the rows, making the connection ready for use again. It is safe // to call Close after rows is already closed.
[ "Close", "closes", "the", "rows", "making", "the", "connection", "ready", "for", "use", "again", ".", "It", "is", "safe", "to", "call", "Close", "after", "rows", "is", "already", "closed", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/query.go#L67-L97
146,870
jackc/pgx
query.go
fatal
func (rows *Rows) fatal(err error) { if rows.err != nil { return } rows.err = err rows.Close() }
go
func (rows *Rows) fatal(err error) { if rows.err != nil { return } rows.err = err rows.Close() }
[ "func", "(", "rows", "*", "Rows", ")", "fatal", "(", "err", "error", ")", "{", "if", "rows", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "rows", ".", "err", "=", "err", "\n", "rows", ".", "Close", "(", ")", "\n", "}" ]
// fatal signals an error occurred after the query was sent to the server. It // closes the rows automatically.
[ "fatal", "signals", "an", "error", "occurred", "after", "the", "query", "was", "sent", "to", "the", "server", ".", "It", "closes", "the", "rows", "automatically", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/query.go#L105-L112
146,871
jackc/pgx
query.go
Next
func (rows *Rows) Next() bool { if rows.closed { return false } rows.rowCount++ rows.columnIdx = 0 for { msg, err := rows.conn.rxMsg() if err != nil { rows.fatal(err) return false } switch msg := msg.(type) { case *pgproto3.RowDescription: rows.fields = rows.conn.rxRowDescription(msg) for i := range rows.fields { if dt, ok := rows.conn.ConnInfo.DataTypeForOID(rows.fields[i].DataType); ok { rows.fields[i].DataTypeName = dt.Name rows.fields[i].FormatCode = TextFormatCode } else { fd := rows.fields[i] rows.fatal(errors.Errorf("unknown oid: %d, name: %s", fd.DataType, fd.Name)) return false } } case *pgproto3.DataRow: if len(msg.Values) != len(rows.fields) { rows.fatal(ProtocolError(fmt.Sprintf("Row description field count (%v) and data row field count (%v) do not match", len(rows.fields), len(msg.Values)))) return false } rows.values = msg.Values return true case *pgproto3.CommandComplete: if rows.batch != nil { rows.batch.pendingCommandComplete = false } rows.Close() return false default: err = rows.conn.processContextFreeMsg(msg) if err != nil { rows.fatal(err) return false } } } }
go
func (rows *Rows) Next() bool { if rows.closed { return false } rows.rowCount++ rows.columnIdx = 0 for { msg, err := rows.conn.rxMsg() if err != nil { rows.fatal(err) return false } switch msg := msg.(type) { case *pgproto3.RowDescription: rows.fields = rows.conn.rxRowDescription(msg) for i := range rows.fields { if dt, ok := rows.conn.ConnInfo.DataTypeForOID(rows.fields[i].DataType); ok { rows.fields[i].DataTypeName = dt.Name rows.fields[i].FormatCode = TextFormatCode } else { fd := rows.fields[i] rows.fatal(errors.Errorf("unknown oid: %d, name: %s", fd.DataType, fd.Name)) return false } } case *pgproto3.DataRow: if len(msg.Values) != len(rows.fields) { rows.fatal(ProtocolError(fmt.Sprintf("Row description field count (%v) and data row field count (%v) do not match", len(rows.fields), len(msg.Values)))) return false } rows.values = msg.Values return true case *pgproto3.CommandComplete: if rows.batch != nil { rows.batch.pendingCommandComplete = false } rows.Close() return false default: err = rows.conn.processContextFreeMsg(msg) if err != nil { rows.fatal(err) return false } } } }
[ "func", "(", "rows", "*", "Rows", ")", "Next", "(", ")", "bool", "{", "if", "rows", ".", "closed", "{", "return", "false", "\n", "}", "\n\n", "rows", ".", "rowCount", "++", "\n", "rows", ".", "columnIdx", "=", "0", "\n\n", "for", "{", "msg", ",", "err", ":=", "rows", ".", "conn", ".", "rxMsg", "(", ")", "\n", "if", "err", "!=", "nil", "{", "rows", ".", "fatal", "(", "err", ")", "\n", "return", "false", "\n", "}", "\n\n", "switch", "msg", ":=", "msg", ".", "(", "type", ")", "{", "case", "*", "pgproto3", ".", "RowDescription", ":", "rows", ".", "fields", "=", "rows", ".", "conn", ".", "rxRowDescription", "(", "msg", ")", "\n", "for", "i", ":=", "range", "rows", ".", "fields", "{", "if", "dt", ",", "ok", ":=", "rows", ".", "conn", ".", "ConnInfo", ".", "DataTypeForOID", "(", "rows", ".", "fields", "[", "i", "]", ".", "DataType", ")", ";", "ok", "{", "rows", ".", "fields", "[", "i", "]", ".", "DataTypeName", "=", "dt", ".", "Name", "\n", "rows", ".", "fields", "[", "i", "]", ".", "FormatCode", "=", "TextFormatCode", "\n", "}", "else", "{", "fd", ":=", "rows", ".", "fields", "[", "i", "]", "\n", "rows", ".", "fatal", "(", "errors", ".", "Errorf", "(", "\"", "\"", ",", "fd", ".", "DataType", ",", "fd", ".", "Name", ")", ")", "\n", "return", "false", "\n", "}", "\n", "}", "\n", "case", "*", "pgproto3", ".", "DataRow", ":", "if", "len", "(", "msg", ".", "Values", ")", "!=", "len", "(", "rows", ".", "fields", ")", "{", "rows", ".", "fatal", "(", "ProtocolError", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "len", "(", "rows", ".", "fields", ")", ",", "len", "(", "msg", ".", "Values", ")", ")", ")", ")", "\n", "return", "false", "\n", "}", "\n\n", "rows", ".", "values", "=", "msg", ".", "Values", "\n", "return", "true", "\n", "case", "*", "pgproto3", ".", "CommandComplete", ":", "if", "rows", ".", "batch", "!=", "nil", "{", "rows", ".", "batch", ".", "pendingCommandComplete", "=", "false", "\n", "}", "\n", "rows", ".", "Close", "(", ")", "\n", "return", "false", "\n\n", "default", ":", "err", "=", "rows", ".", "conn", ".", "processContextFreeMsg", "(", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "rows", ".", "fatal", "(", "err", ")", "\n", "return", "false", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Next prepares the next row for reading. It returns true if there is another // row and false if no more rows are available. It automatically closes rows // when all rows are read.
[ "Next", "prepares", "the", "next", "row", "for", "reading", ".", "It", "returns", "true", "if", "there", "is", "another", "row", "and", "false", "if", "no", "more", "rows", "are", "available", ".", "It", "automatically", "closes", "rows", "when", "all", "rows", "are", "read", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/query.go#L117-L168
146,872
jackc/pgx
query.go
Values
func (rows *Rows) Values() ([]interface{}, error) { if rows.closed { return nil, errors.New("rows is closed") } values := make([]interface{}, 0, len(rows.fields)) for range rows.fields { buf, fd, _ := rows.nextColumn() if buf == nil { values = append(values, nil) continue } if dt, ok := rows.conn.ConnInfo.DataTypeForOID(fd.DataType); ok { value := reflect.New(reflect.ValueOf(dt.Value).Elem().Type()).Interface().(pgtype.Value) switch fd.FormatCode { case TextFormatCode: decoder := value.(pgtype.TextDecoder) if decoder == nil { decoder = &pgtype.GenericText{} } err := decoder.DecodeText(rows.conn.ConnInfo, buf) if err != nil { rows.fatal(err) } values = append(values, decoder.(pgtype.Value).Get()) case BinaryFormatCode: decoder := value.(pgtype.BinaryDecoder) if decoder == nil { decoder = &pgtype.GenericBinary{} } err := decoder.DecodeBinary(rows.conn.ConnInfo, buf) if err != nil { rows.fatal(err) } values = append(values, value.Get()) default: rows.fatal(errors.New("Unknown format code")) } } else { rows.fatal(errors.New("Unknown type")) } if rows.Err() != nil { return nil, rows.Err() } } return values, rows.Err() }
go
func (rows *Rows) Values() ([]interface{}, error) { if rows.closed { return nil, errors.New("rows is closed") } values := make([]interface{}, 0, len(rows.fields)) for range rows.fields { buf, fd, _ := rows.nextColumn() if buf == nil { values = append(values, nil) continue } if dt, ok := rows.conn.ConnInfo.DataTypeForOID(fd.DataType); ok { value := reflect.New(reflect.ValueOf(dt.Value).Elem().Type()).Interface().(pgtype.Value) switch fd.FormatCode { case TextFormatCode: decoder := value.(pgtype.TextDecoder) if decoder == nil { decoder = &pgtype.GenericText{} } err := decoder.DecodeText(rows.conn.ConnInfo, buf) if err != nil { rows.fatal(err) } values = append(values, decoder.(pgtype.Value).Get()) case BinaryFormatCode: decoder := value.(pgtype.BinaryDecoder) if decoder == nil { decoder = &pgtype.GenericBinary{} } err := decoder.DecodeBinary(rows.conn.ConnInfo, buf) if err != nil { rows.fatal(err) } values = append(values, value.Get()) default: rows.fatal(errors.New("Unknown format code")) } } else { rows.fatal(errors.New("Unknown type")) } if rows.Err() != nil { return nil, rows.Err() } } return values, rows.Err() }
[ "func", "(", "rows", "*", "Rows", ")", "Values", "(", ")", "(", "[", "]", "interface", "{", "}", ",", "error", ")", "{", "if", "rows", ".", "closed", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "values", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "0", ",", "len", "(", "rows", ".", "fields", ")", ")", "\n\n", "for", "range", "rows", ".", "fields", "{", "buf", ",", "fd", ",", "_", ":=", "rows", ".", "nextColumn", "(", ")", "\n\n", "if", "buf", "==", "nil", "{", "values", "=", "append", "(", "values", ",", "nil", ")", "\n", "continue", "\n", "}", "\n\n", "if", "dt", ",", "ok", ":=", "rows", ".", "conn", ".", "ConnInfo", ".", "DataTypeForOID", "(", "fd", ".", "DataType", ")", ";", "ok", "{", "value", ":=", "reflect", ".", "New", "(", "reflect", ".", "ValueOf", "(", "dt", ".", "Value", ")", ".", "Elem", "(", ")", ".", "Type", "(", ")", ")", ".", "Interface", "(", ")", ".", "(", "pgtype", ".", "Value", ")", "\n\n", "switch", "fd", ".", "FormatCode", "{", "case", "TextFormatCode", ":", "decoder", ":=", "value", ".", "(", "pgtype", ".", "TextDecoder", ")", "\n", "if", "decoder", "==", "nil", "{", "decoder", "=", "&", "pgtype", ".", "GenericText", "{", "}", "\n", "}", "\n", "err", ":=", "decoder", ".", "DecodeText", "(", "rows", ".", "conn", ".", "ConnInfo", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "rows", ".", "fatal", "(", "err", ")", "\n", "}", "\n", "values", "=", "append", "(", "values", ",", "decoder", ".", "(", "pgtype", ".", "Value", ")", ".", "Get", "(", ")", ")", "\n", "case", "BinaryFormatCode", ":", "decoder", ":=", "value", ".", "(", "pgtype", ".", "BinaryDecoder", ")", "\n", "if", "decoder", "==", "nil", "{", "decoder", "=", "&", "pgtype", ".", "GenericBinary", "{", "}", "\n", "}", "\n", "err", ":=", "decoder", ".", "DecodeBinary", "(", "rows", ".", "conn", ".", "ConnInfo", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "rows", ".", "fatal", "(", "err", ")", "\n", "}", "\n", "values", "=", "append", "(", "values", ",", "value", ".", "Get", "(", ")", ")", "\n", "default", ":", "rows", ".", "fatal", "(", "errors", ".", "New", "(", "\"", "\"", ")", ")", "\n", "}", "\n", "}", "else", "{", "rows", ".", "fatal", "(", "errors", ".", "New", "(", "\"", "\"", ")", ")", "\n", "}", "\n\n", "if", "rows", ".", "Err", "(", ")", "!=", "nil", "{", "return", "nil", ",", "rows", ".", "Err", "(", ")", "\n", "}", "\n", "}", "\n\n", "return", "values", ",", "rows", ".", "Err", "(", ")", "\n", "}" ]
// Values returns an array of the row values
[ "Values", "returns", "an", "array", "of", "the", "row", "values" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/query.go#L276-L328
146,873
jackc/pgx
large_objects.go
LargeObjects
func (tx *Tx) LargeObjects() (*LargeObjects, error) { if tx.conn.fp == nil { tx.conn.fp = newFastpath(tx.conn) } if _, exists := tx.conn.fp.fns["lo_open"]; !exists { res, err := tx.Query(largeObjectFns) if err != nil { return nil, err } if err := tx.conn.fp.addFunctions(res); err != nil { return nil, err } } lo := &LargeObjects{fp: tx.conn.fp} _, lo.Has64 = lo.fp.fns["lo_lseek64"] return lo, nil }
go
func (tx *Tx) LargeObjects() (*LargeObjects, error) { if tx.conn.fp == nil { tx.conn.fp = newFastpath(tx.conn) } if _, exists := tx.conn.fp.fns["lo_open"]; !exists { res, err := tx.Query(largeObjectFns) if err != nil { return nil, err } if err := tx.conn.fp.addFunctions(res); err != nil { return nil, err } } lo := &LargeObjects{fp: tx.conn.fp} _, lo.Has64 = lo.fp.fns["lo_lseek64"] return lo, nil }
[ "func", "(", "tx", "*", "Tx", ")", "LargeObjects", "(", ")", "(", "*", "LargeObjects", ",", "error", ")", "{", "if", "tx", ".", "conn", ".", "fp", "==", "nil", "{", "tx", ".", "conn", ".", "fp", "=", "newFastpath", "(", "tx", ".", "conn", ")", "\n", "}", "\n", "if", "_", ",", "exists", ":=", "tx", ".", "conn", ".", "fp", ".", "fns", "[", "\"", "\"", "]", ";", "!", "exists", "{", "res", ",", "err", ":=", "tx", ".", "Query", "(", "largeObjectFns", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "tx", ".", "conn", ".", "fp", ".", "addFunctions", "(", "res", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "lo", ":=", "&", "LargeObjects", "{", "fp", ":", "tx", ".", "conn", ".", "fp", "}", "\n", "_", ",", "lo", ".", "Has64", "=", "lo", ".", "fp", ".", "fns", "[", "\"", "\"", "]", "\n\n", "return", "lo", ",", "nil", "\n", "}" ]
// LargeObjects returns a LargeObjects instance for the transaction.
[ "LargeObjects", "returns", "a", "LargeObjects", "instance", "for", "the", "transaction", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L36-L54
146,874
jackc/pgx
large_objects.go
Create
func (o *LargeObjects) Create(id pgtype.OID) (pgtype.OID, error) { newOID, err := fpInt32(o.fp.CallFn("lo_create", []fpArg{fpIntArg(int32(id))})) return pgtype.OID(newOID), err }
go
func (o *LargeObjects) Create(id pgtype.OID) (pgtype.OID, error) { newOID, err := fpInt32(o.fp.CallFn("lo_create", []fpArg{fpIntArg(int32(id))})) return pgtype.OID(newOID), err }
[ "func", "(", "o", "*", "LargeObjects", ")", "Create", "(", "id", "pgtype", ".", "OID", ")", "(", "pgtype", ".", "OID", ",", "error", ")", "{", "newOID", ",", "err", ":=", "fpInt32", "(", "o", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "int32", "(", "id", ")", ")", "}", ")", ")", "\n", "return", "pgtype", ".", "OID", "(", "newOID", ")", ",", "err", "\n", "}" ]
// Create creates a new large object. If id is zero, the server assigns an // unused OID.
[ "Create", "creates", "a", "new", "large", "object", ".", "If", "id", "is", "zero", "the", "server", "assigns", "an", "unused", "OID", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L65-L68
146,875
jackc/pgx
large_objects.go
Open
func (o *LargeObjects) Open(oid pgtype.OID, mode LargeObjectMode) (*LargeObject, error) { fd, err := fpInt32(o.fp.CallFn("lo_open", []fpArg{fpIntArg(int32(oid)), fpIntArg(int32(mode))})) return &LargeObject{fd: fd, lo: o}, err }
go
func (o *LargeObjects) Open(oid pgtype.OID, mode LargeObjectMode) (*LargeObject, error) { fd, err := fpInt32(o.fp.CallFn("lo_open", []fpArg{fpIntArg(int32(oid)), fpIntArg(int32(mode))})) return &LargeObject{fd: fd, lo: o}, err }
[ "func", "(", "o", "*", "LargeObjects", ")", "Open", "(", "oid", "pgtype", ".", "OID", ",", "mode", "LargeObjectMode", ")", "(", "*", "LargeObject", ",", "error", ")", "{", "fd", ",", "err", ":=", "fpInt32", "(", "o", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "int32", "(", "oid", ")", ")", ",", "fpIntArg", "(", "int32", "(", "mode", ")", ")", "}", ")", ")", "\n", "return", "&", "LargeObject", "{", "fd", ":", "fd", ",", "lo", ":", "o", "}", ",", "err", "\n", "}" ]
// Open opens an existing large object with the given mode.
[ "Open", "opens", "an", "existing", "large", "object", "with", "the", "given", "mode", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L71-L74
146,876
jackc/pgx
large_objects.go
Unlink
func (o *LargeObjects) Unlink(oid pgtype.OID) error { _, err := o.fp.CallFn("lo_unlink", []fpArg{fpIntArg(int32(oid))}) return err }
go
func (o *LargeObjects) Unlink(oid pgtype.OID) error { _, err := o.fp.CallFn("lo_unlink", []fpArg{fpIntArg(int32(oid))}) return err }
[ "func", "(", "o", "*", "LargeObjects", ")", "Unlink", "(", "oid", "pgtype", ".", "OID", ")", "error", "{", "_", ",", "err", ":=", "o", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "int32", "(", "oid", ")", ")", "}", ")", "\n", "return", "err", "\n", "}" ]
// Unlink removes a large object from the database.
[ "Unlink", "removes", "a", "large", "object", "from", "the", "database", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L77-L80
146,877
jackc/pgx
large_objects.go
Write
func (o *LargeObject) Write(p []byte) (int, error) { n, err := fpInt32(o.lo.fp.CallFn("lowrite", []fpArg{fpIntArg(o.fd), p})) return int(n), err }
go
func (o *LargeObject) Write(p []byte) (int, error) { n, err := fpInt32(o.lo.fp.CallFn("lowrite", []fpArg{fpIntArg(o.fd), p})) return int(n), err }
[ "func", "(", "o", "*", "LargeObject", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "n", ",", "err", ":=", "fpInt32", "(", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", ",", "p", "}", ")", ")", "\n", "return", "int", "(", "n", ")", ",", "err", "\n", "}" ]
// Write writes p to the large object and returns the number of bytes written // and an error if not all of p was written.
[ "Write", "writes", "p", "to", "the", "large", "object", "and", "returns", "the", "number", "of", "bytes", "written", "and", "an", "error", "if", "not", "all", "of", "p", "was", "written", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L96-L99
146,878
jackc/pgx
large_objects.go
Seek
func (o *LargeObject) Seek(offset int64, whence int) (n int64, err error) { if o.lo.Has64 { n, err = fpInt64(o.lo.fp.CallFn("lo_lseek64", []fpArg{fpIntArg(o.fd), fpInt64Arg(offset), fpIntArg(int32(whence))})) } else { var n32 int32 n32, err = fpInt32(o.lo.fp.CallFn("lo_lseek", []fpArg{fpIntArg(o.fd), fpIntArg(int32(offset)), fpIntArg(int32(whence))})) n = int64(n32) } return }
go
func (o *LargeObject) Seek(offset int64, whence int) (n int64, err error) { if o.lo.Has64 { n, err = fpInt64(o.lo.fp.CallFn("lo_lseek64", []fpArg{fpIntArg(o.fd), fpInt64Arg(offset), fpIntArg(int32(whence))})) } else { var n32 int32 n32, err = fpInt32(o.lo.fp.CallFn("lo_lseek", []fpArg{fpIntArg(o.fd), fpIntArg(int32(offset)), fpIntArg(int32(whence))})) n = int64(n32) } return }
[ "func", "(", "o", "*", "LargeObject", ")", "Seek", "(", "offset", "int64", ",", "whence", "int", ")", "(", "n", "int64", ",", "err", "error", ")", "{", "if", "o", ".", "lo", ".", "Has64", "{", "n", ",", "err", "=", "fpInt64", "(", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", ",", "fpInt64Arg", "(", "offset", ")", ",", "fpIntArg", "(", "int32", "(", "whence", ")", ")", "}", ")", ")", "\n", "}", "else", "{", "var", "n32", "int32", "\n", "n32", ",", "err", "=", "fpInt32", "(", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", ",", "fpIntArg", "(", "int32", "(", "offset", ")", ")", ",", "fpIntArg", "(", "int32", "(", "whence", ")", ")", "}", ")", ")", "\n", "n", "=", "int64", "(", "n32", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Seek moves the current location pointer to the new location specified by offset.
[ "Seek", "moves", "the", "current", "location", "pointer", "to", "the", "new", "location", "specified", "by", "offset", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L111-L120
146,879
jackc/pgx
large_objects.go
Tell
func (o *LargeObject) Tell() (n int64, err error) { if o.lo.Has64 { n, err = fpInt64(o.lo.fp.CallFn("lo_tell64", []fpArg{fpIntArg(o.fd)})) } else { var n32 int32 n32, err = fpInt32(o.lo.fp.CallFn("lo_tell", []fpArg{fpIntArg(o.fd)})) n = int64(n32) } return }
go
func (o *LargeObject) Tell() (n int64, err error) { if o.lo.Has64 { n, err = fpInt64(o.lo.fp.CallFn("lo_tell64", []fpArg{fpIntArg(o.fd)})) } else { var n32 int32 n32, err = fpInt32(o.lo.fp.CallFn("lo_tell", []fpArg{fpIntArg(o.fd)})) n = int64(n32) } return }
[ "func", "(", "o", "*", "LargeObject", ")", "Tell", "(", ")", "(", "n", "int64", ",", "err", "error", ")", "{", "if", "o", ".", "lo", ".", "Has64", "{", "n", ",", "err", "=", "fpInt64", "(", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", "}", ")", ")", "\n", "}", "else", "{", "var", "n32", "int32", "\n", "n32", ",", "err", "=", "fpInt32", "(", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", "}", ")", ")", "\n", "n", "=", "int64", "(", "n32", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Tell returns the current read or write location of the large object // descriptor.
[ "Tell", "returns", "the", "current", "read", "or", "write", "location", "of", "the", "large", "object", "descriptor", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L124-L133
146,880
jackc/pgx
large_objects.go
Truncate
func (o *LargeObject) Truncate(size int64) (err error) { if o.lo.Has64 { _, err = o.lo.fp.CallFn("lo_truncate64", []fpArg{fpIntArg(o.fd), fpInt64Arg(size)}) } else { _, err = o.lo.fp.CallFn("lo_truncate", []fpArg{fpIntArg(o.fd), fpIntArg(int32(size))}) } return }
go
func (o *LargeObject) Truncate(size int64) (err error) { if o.lo.Has64 { _, err = o.lo.fp.CallFn("lo_truncate64", []fpArg{fpIntArg(o.fd), fpInt64Arg(size)}) } else { _, err = o.lo.fp.CallFn("lo_truncate", []fpArg{fpIntArg(o.fd), fpIntArg(int32(size))}) } return }
[ "func", "(", "o", "*", "LargeObject", ")", "Truncate", "(", "size", "int64", ")", "(", "err", "error", ")", "{", "if", "o", ".", "lo", ".", "Has64", "{", "_", ",", "err", "=", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", ",", "fpInt64Arg", "(", "size", ")", "}", ")", "\n", "}", "else", "{", "_", ",", "err", "=", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", ",", "fpIntArg", "(", "int32", "(", "size", ")", ")", "}", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Trunctes the large object to size.
[ "Trunctes", "the", "large", "object", "to", "size", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L136-L143
146,881
jackc/pgx
large_objects.go
Close
func (o *LargeObject) Close() error { _, err := o.lo.fp.CallFn("lo_close", []fpArg{fpIntArg(o.fd)}) return err }
go
func (o *LargeObject) Close() error { _, err := o.lo.fp.CallFn("lo_close", []fpArg{fpIntArg(o.fd)}) return err }
[ "func", "(", "o", "*", "LargeObject", ")", "Close", "(", ")", "error", "{", "_", ",", "err", ":=", "o", ".", "lo", ".", "fp", ".", "CallFn", "(", "\"", "\"", ",", "[", "]", "fpArg", "{", "fpIntArg", "(", "o", ".", "fd", ")", "}", ")", "\n", "return", "err", "\n", "}" ]
// Close closees the large object descriptor.
[ "Close", "closees", "the", "large", "object", "descriptor", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/large_objects.go#L146-L149
146,882
jackc/pgx
values.go
chooseParameterFormatCode
func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid pgtype.OID, arg interface{}) int16 { switch arg.(type) { case pgtype.BinaryEncoder: return BinaryFormatCode case string, *string, pgtype.TextEncoder: return TextFormatCode } if dt, ok := ci.DataTypeForOID(oid); ok { if _, ok := dt.Value.(pgtype.BinaryEncoder); ok { return BinaryFormatCode } } return TextFormatCode }
go
func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid pgtype.OID, arg interface{}) int16 { switch arg.(type) { case pgtype.BinaryEncoder: return BinaryFormatCode case string, *string, pgtype.TextEncoder: return TextFormatCode } if dt, ok := ci.DataTypeForOID(oid); ok { if _, ok := dt.Value.(pgtype.BinaryEncoder); ok { return BinaryFormatCode } } return TextFormatCode }
[ "func", "chooseParameterFormatCode", "(", "ci", "*", "pgtype", ".", "ConnInfo", ",", "oid", "pgtype", ".", "OID", ",", "arg", "interface", "{", "}", ")", "int16", "{", "switch", "arg", ".", "(", "type", ")", "{", "case", "pgtype", ".", "BinaryEncoder", ":", "return", "BinaryFormatCode", "\n", "case", "string", ",", "*", "string", ",", "pgtype", ".", "TextEncoder", ":", "return", "TextFormatCode", "\n", "}", "\n\n", "if", "dt", ",", "ok", ":=", "ci", ".", "DataTypeForOID", "(", "oid", ")", ";", "ok", "{", "if", "_", ",", "ok", ":=", "dt", ".", "Value", ".", "(", "pgtype", ".", "BinaryEncoder", ")", ";", "ok", "{", "return", "BinaryFormatCode", "\n", "}", "\n", "}", "\n\n", "return", "TextFormatCode", "\n", "}" ]
// chooseParameterFormatCode determines the correct format code for an // argument to a prepared statement. It defaults to TextFormatCode if no // determination can be made.
[ "chooseParameterFormatCode", "determines", "the", "correct", "format", "code", "for", "an", "argument", "to", "a", "prepared", "statement", ".", "It", "defaults", "to", "TextFormatCode", "if", "no", "determination", "can", "be", "made", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/values.go#L220-L235
146,883
jackc/pgx
internal/sanitize/sanitize.go
SanitizeSQL
func SanitizeSQL(sql string, args ...interface{}) (string, error) { query, err := NewQuery(sql) if err != nil { return "", err } return query.Sanitize(args...) }
go
func SanitizeSQL(sql string, args ...interface{}) (string, error) { query, err := NewQuery(sql) if err != nil { return "", err } return query.Sanitize(args...) }
[ "func", "SanitizeSQL", "(", "sql", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "query", ",", "err", ":=", "NewQuery", "(", "sql", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "query", ".", "Sanitize", "(", "args", "...", ")", "\n", "}" ]
// SanitizeSQL replaces placeholder values with args. It quotes and escapes args // as necessary. This function is only safe when standard_conforming_strings is // on.
[ "SanitizeSQL", "replaces", "placeholder", "values", "with", "args", ".", "It", "quotes", "and", "escapes", "args", "as", "necessary", ".", "This", "function", "is", "only", "safe", "when", "standard_conforming_strings", "is", "on", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/internal/sanitize/sanitize.go#L231-L237
146,884
jackc/pgx
conn_pool.go
NewConnPool
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) { p = new(ConnPool) p.config = config.ConnConfig p.connInfo = minimalConnInfo p.maxConnections = config.MaxConnections if p.maxConnections == 0 { p.maxConnections = 5 } if p.maxConnections < 1 { return nil, errors.New("MaxConnections must be at least 1") } p.acquireTimeout = config.AcquireTimeout if p.acquireTimeout < 0 { return nil, errors.New("AcquireTimeout must be equal to or greater than 0") } p.afterConnect = config.AfterConnect if config.LogLevel != 0 { p.logLevel = config.LogLevel } else { // Preserve pre-LogLevel behavior by defaulting to LogLevelDebug p.logLevel = LogLevelDebug } p.logger = config.Logger if p.logger == nil { p.logLevel = LogLevelNone } p.allConnections = make([]*Conn, 0, p.maxConnections) p.availableConnections = make([]*Conn, 0, p.maxConnections) p.preparedStatements = make(map[string]*PreparedStatement) p.cond = sync.NewCond(new(sync.Mutex)) // Initially establish one connection var c *Conn c, err = p.createConnection() if err != nil { return } p.allConnections = append(p.allConnections, c) p.availableConnections = append(p.availableConnections, c) p.connInfo = c.ConnInfo.DeepCopy() return }
go
func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) { p = new(ConnPool) p.config = config.ConnConfig p.connInfo = minimalConnInfo p.maxConnections = config.MaxConnections if p.maxConnections == 0 { p.maxConnections = 5 } if p.maxConnections < 1 { return nil, errors.New("MaxConnections must be at least 1") } p.acquireTimeout = config.AcquireTimeout if p.acquireTimeout < 0 { return nil, errors.New("AcquireTimeout must be equal to or greater than 0") } p.afterConnect = config.AfterConnect if config.LogLevel != 0 { p.logLevel = config.LogLevel } else { // Preserve pre-LogLevel behavior by defaulting to LogLevelDebug p.logLevel = LogLevelDebug } p.logger = config.Logger if p.logger == nil { p.logLevel = LogLevelNone } p.allConnections = make([]*Conn, 0, p.maxConnections) p.availableConnections = make([]*Conn, 0, p.maxConnections) p.preparedStatements = make(map[string]*PreparedStatement) p.cond = sync.NewCond(new(sync.Mutex)) // Initially establish one connection var c *Conn c, err = p.createConnection() if err != nil { return } p.allConnections = append(p.allConnections, c) p.availableConnections = append(p.availableConnections, c) p.connInfo = c.ConnInfo.DeepCopy() return }
[ "func", "NewConnPool", "(", "config", "ConnPoolConfig", ")", "(", "p", "*", "ConnPool", ",", "err", "error", ")", "{", "p", "=", "new", "(", "ConnPool", ")", "\n", "p", ".", "config", "=", "config", ".", "ConnConfig", "\n", "p", ".", "connInfo", "=", "minimalConnInfo", "\n", "p", ".", "maxConnections", "=", "config", ".", "MaxConnections", "\n", "if", "p", ".", "maxConnections", "==", "0", "{", "p", ".", "maxConnections", "=", "5", "\n", "}", "\n", "if", "p", ".", "maxConnections", "<", "1", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "p", ".", "acquireTimeout", "=", "config", ".", "AcquireTimeout", "\n", "if", "p", ".", "acquireTimeout", "<", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "p", ".", "afterConnect", "=", "config", ".", "AfterConnect", "\n\n", "if", "config", ".", "LogLevel", "!=", "0", "{", "p", ".", "logLevel", "=", "config", ".", "LogLevel", "\n", "}", "else", "{", "// Preserve pre-LogLevel behavior by defaulting to LogLevelDebug", "p", ".", "logLevel", "=", "LogLevelDebug", "\n", "}", "\n", "p", ".", "logger", "=", "config", ".", "Logger", "\n", "if", "p", ".", "logger", "==", "nil", "{", "p", ".", "logLevel", "=", "LogLevelNone", "\n", "}", "\n\n", "p", ".", "allConnections", "=", "make", "(", "[", "]", "*", "Conn", ",", "0", ",", "p", ".", "maxConnections", ")", "\n", "p", ".", "availableConnections", "=", "make", "(", "[", "]", "*", "Conn", ",", "0", ",", "p", ".", "maxConnections", ")", "\n", "p", ".", "preparedStatements", "=", "make", "(", "map", "[", "string", "]", "*", "PreparedStatement", ")", "\n", "p", ".", "cond", "=", "sync", ".", "NewCond", "(", "new", "(", "sync", ".", "Mutex", ")", ")", "\n\n", "// Initially establish one connection", "var", "c", "*", "Conn", "\n", "c", ",", "err", "=", "p", ".", "createConnection", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "p", ".", "allConnections", "=", "append", "(", "p", ".", "allConnections", ",", "c", ")", "\n", "p", ".", "availableConnections", "=", "append", "(", "p", ".", "availableConnections", ",", "c", ")", "\n", "p", ".", "connInfo", "=", "c", ".", "ConnInfo", ".", "DeepCopy", "(", ")", "\n\n", "return", "\n", "}" ]
// NewConnPool creates a new ConnPool. config.ConnConfig is passed through to // Connect directly.
[ "NewConnPool", "creates", "a", "new", "ConnPool", ".", "config", ".", "ConnConfig", "is", "passed", "through", "to", "Connect", "directly", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L58-L103
146,885
jackc/pgx
conn_pool.go
Acquire
func (p *ConnPool) Acquire() (*Conn, error) { p.cond.L.Lock() c, err := p.acquire(nil) p.cond.L.Unlock() return c, err }
go
func (p *ConnPool) Acquire() (*Conn, error) { p.cond.L.Lock() c, err := p.acquire(nil) p.cond.L.Unlock() return c, err }
[ "func", "(", "p", "*", "ConnPool", ")", "Acquire", "(", ")", "(", "*", "Conn", ",", "error", ")", "{", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "c", ",", "err", ":=", "p", ".", "acquire", "(", "nil", ")", "\n", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n", "return", "c", ",", "err", "\n", "}" ]
// Acquire takes exclusive use of a connection until it is released.
[ "Acquire", "takes", "exclusive", "use", "of", "a", "connection", "until", "it", "is", "released", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L106-L111
146,886
jackc/pgx
conn_pool.go
deadlinePassed
func (p *ConnPool) deadlinePassed(deadline *time.Time) bool { return deadline != nil && time.Now().After(*deadline) }
go
func (p *ConnPool) deadlinePassed(deadline *time.Time) bool { return deadline != nil && time.Now().After(*deadline) }
[ "func", "(", "p", "*", "ConnPool", ")", "deadlinePassed", "(", "deadline", "*", "time", ".", "Time", ")", "bool", "{", "return", "deadline", "!=", "nil", "&&", "time", ".", "Now", "(", ")", ".", "After", "(", "*", "deadline", ")", "\n", "}" ]
// deadlinePassed returns true if the given deadline has passed.
[ "deadlinePassed", "returns", "true", "if", "the", "given", "deadline", "has", "passed", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L114-L116
146,887
jackc/pgx
conn_pool.go
acquire
func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) { if p.closed { return nil, ErrClosedPool } // A connection is available // The pool works like a queue. Available connection will be returned // from the head. A new connection will be added to the tail. numAvailable := len(p.availableConnections) if numAvailable > 0 { c := p.availableConnections[0] c.poolResetCount = p.resetCount copy(p.availableConnections, p.availableConnections[1:]) p.availableConnections = p.availableConnections[:numAvailable-1] return c, nil } // Set initial timeout/deadline value. If the method (acquire) happens to // recursively call itself the deadline should retain its value. if deadline == nil && p.acquireTimeout > 0 { tmp := time.Now().Add(p.acquireTimeout) deadline = &tmp } // Make sure the deadline (if it is) has not passed yet if p.deadlinePassed(deadline) { return nil, ErrAcquireTimeout } // If there is a deadline then start a timeout timer var timer *time.Timer if deadline != nil { timer = time.AfterFunc(deadline.Sub(time.Now()), func() { p.cond.Broadcast() }) defer timer.Stop() } // No connections are available, but we can create more if len(p.allConnections)+p.inProgressConnects < p.maxConnections { // Create a new connection. // Careful here: createConnectionUnlocked() removes the current lock, // creates a connection and then locks it back. c, err := p.createConnectionUnlocked() if err != nil { return nil, err } c.poolResetCount = p.resetCount p.allConnections = append(p.allConnections, c) return c, nil } // All connections are in use and we cannot create more if p.logLevel >= LogLevelWarn { p.logger.Log(LogLevelWarn, "waiting for available connection", nil) } // Wait until there is an available connection OR room to create a new connection for len(p.availableConnections) == 0 && len(p.allConnections)+p.inProgressConnects == p.maxConnections { if p.deadlinePassed(deadline) { return nil, ErrAcquireTimeout } p.cond.Wait() } // Stop the timer so that we do not spawn it on every acquire call. if timer != nil { timer.Stop() } return p.acquire(deadline) }
go
func (p *ConnPool) acquire(deadline *time.Time) (*Conn, error) { if p.closed { return nil, ErrClosedPool } // A connection is available // The pool works like a queue. Available connection will be returned // from the head. A new connection will be added to the tail. numAvailable := len(p.availableConnections) if numAvailable > 0 { c := p.availableConnections[0] c.poolResetCount = p.resetCount copy(p.availableConnections, p.availableConnections[1:]) p.availableConnections = p.availableConnections[:numAvailable-1] return c, nil } // Set initial timeout/deadline value. If the method (acquire) happens to // recursively call itself the deadline should retain its value. if deadline == nil && p.acquireTimeout > 0 { tmp := time.Now().Add(p.acquireTimeout) deadline = &tmp } // Make sure the deadline (if it is) has not passed yet if p.deadlinePassed(deadline) { return nil, ErrAcquireTimeout } // If there is a deadline then start a timeout timer var timer *time.Timer if deadline != nil { timer = time.AfterFunc(deadline.Sub(time.Now()), func() { p.cond.Broadcast() }) defer timer.Stop() } // No connections are available, but we can create more if len(p.allConnections)+p.inProgressConnects < p.maxConnections { // Create a new connection. // Careful here: createConnectionUnlocked() removes the current lock, // creates a connection and then locks it back. c, err := p.createConnectionUnlocked() if err != nil { return nil, err } c.poolResetCount = p.resetCount p.allConnections = append(p.allConnections, c) return c, nil } // All connections are in use and we cannot create more if p.logLevel >= LogLevelWarn { p.logger.Log(LogLevelWarn, "waiting for available connection", nil) } // Wait until there is an available connection OR room to create a new connection for len(p.availableConnections) == 0 && len(p.allConnections)+p.inProgressConnects == p.maxConnections { if p.deadlinePassed(deadline) { return nil, ErrAcquireTimeout } p.cond.Wait() } // Stop the timer so that we do not spawn it on every acquire call. if timer != nil { timer.Stop() } return p.acquire(deadline) }
[ "func", "(", "p", "*", "ConnPool", ")", "acquire", "(", "deadline", "*", "time", ".", "Time", ")", "(", "*", "Conn", ",", "error", ")", "{", "if", "p", ".", "closed", "{", "return", "nil", ",", "ErrClosedPool", "\n", "}", "\n\n", "// A connection is available", "// The pool works like a queue. Available connection will be returned", "// from the head. A new connection will be added to the tail.", "numAvailable", ":=", "len", "(", "p", ".", "availableConnections", ")", "\n", "if", "numAvailable", ">", "0", "{", "c", ":=", "p", ".", "availableConnections", "[", "0", "]", "\n", "c", ".", "poolResetCount", "=", "p", ".", "resetCount", "\n", "copy", "(", "p", ".", "availableConnections", ",", "p", ".", "availableConnections", "[", "1", ":", "]", ")", "\n", "p", ".", "availableConnections", "=", "p", ".", "availableConnections", "[", ":", "numAvailable", "-", "1", "]", "\n", "return", "c", ",", "nil", "\n", "}", "\n\n", "// Set initial timeout/deadline value. If the method (acquire) happens to", "// recursively call itself the deadline should retain its value.", "if", "deadline", "==", "nil", "&&", "p", ".", "acquireTimeout", ">", "0", "{", "tmp", ":=", "time", ".", "Now", "(", ")", ".", "Add", "(", "p", ".", "acquireTimeout", ")", "\n", "deadline", "=", "&", "tmp", "\n", "}", "\n\n", "// Make sure the deadline (if it is) has not passed yet", "if", "p", ".", "deadlinePassed", "(", "deadline", ")", "{", "return", "nil", ",", "ErrAcquireTimeout", "\n", "}", "\n\n", "// If there is a deadline then start a timeout timer", "var", "timer", "*", "time", ".", "Timer", "\n", "if", "deadline", "!=", "nil", "{", "timer", "=", "time", ".", "AfterFunc", "(", "deadline", ".", "Sub", "(", "time", ".", "Now", "(", ")", ")", ",", "func", "(", ")", "{", "p", ".", "cond", ".", "Broadcast", "(", ")", "\n", "}", ")", "\n", "defer", "timer", ".", "Stop", "(", ")", "\n", "}", "\n\n", "// No connections are available, but we can create more", "if", "len", "(", "p", ".", "allConnections", ")", "+", "p", ".", "inProgressConnects", "<", "p", ".", "maxConnections", "{", "// Create a new connection.", "// Careful here: createConnectionUnlocked() removes the current lock,", "// creates a connection and then locks it back.", "c", ",", "err", ":=", "p", ".", "createConnectionUnlocked", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "poolResetCount", "=", "p", ".", "resetCount", "\n", "p", ".", "allConnections", "=", "append", "(", "p", ".", "allConnections", ",", "c", ")", "\n", "return", "c", ",", "nil", "\n", "}", "\n", "// All connections are in use and we cannot create more", "if", "p", ".", "logLevel", ">=", "LogLevelWarn", "{", "p", ".", "logger", ".", "Log", "(", "LogLevelWarn", ",", "\"", "\"", ",", "nil", ")", "\n", "}", "\n\n", "// Wait until there is an available connection OR room to create a new connection", "for", "len", "(", "p", ".", "availableConnections", ")", "==", "0", "&&", "len", "(", "p", ".", "allConnections", ")", "+", "p", ".", "inProgressConnects", "==", "p", ".", "maxConnections", "{", "if", "p", ".", "deadlinePassed", "(", "deadline", ")", "{", "return", "nil", ",", "ErrAcquireTimeout", "\n", "}", "\n", "p", ".", "cond", ".", "Wait", "(", ")", "\n", "}", "\n\n", "// Stop the timer so that we do not spawn it on every acquire call.", "if", "timer", "!=", "nil", "{", "timer", ".", "Stop", "(", ")", "\n", "}", "\n", "return", "p", ".", "acquire", "(", "deadline", ")", "\n", "}" ]
// acquire performs acquision assuming pool is already locked
[ "acquire", "performs", "acquision", "assuming", "pool", "is", "already", "locked" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L119-L188
146,888
jackc/pgx
conn_pool.go
Release
func (p *ConnPool) Release(conn *Conn) { if conn.ctxInProgress { panic("should never release when context is in progress") } if conn.txStatus != 'I' { conn.Exec("rollback") } if len(conn.channels) > 0 { if err := conn.Unlisten("*"); err != nil { conn.die(err) } conn.channels = make(map[string]struct{}) } conn.notifications = nil p.cond.L.Lock() if conn.poolResetCount != p.resetCount { conn.Close() p.cond.L.Unlock() p.cond.Signal() return } if conn.IsAlive() { p.availableConnections = append(p.availableConnections, conn) } else { p.removeFromAllConnections(conn) } p.cond.L.Unlock() p.cond.Signal() }
go
func (p *ConnPool) Release(conn *Conn) { if conn.ctxInProgress { panic("should never release when context is in progress") } if conn.txStatus != 'I' { conn.Exec("rollback") } if len(conn.channels) > 0 { if err := conn.Unlisten("*"); err != nil { conn.die(err) } conn.channels = make(map[string]struct{}) } conn.notifications = nil p.cond.L.Lock() if conn.poolResetCount != p.resetCount { conn.Close() p.cond.L.Unlock() p.cond.Signal() return } if conn.IsAlive() { p.availableConnections = append(p.availableConnections, conn) } else { p.removeFromAllConnections(conn) } p.cond.L.Unlock() p.cond.Signal() }
[ "func", "(", "p", "*", "ConnPool", ")", "Release", "(", "conn", "*", "Conn", ")", "{", "if", "conn", ".", "ctxInProgress", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "conn", ".", "txStatus", "!=", "'I'", "{", "conn", ".", "Exec", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "conn", ".", "channels", ")", ">", "0", "{", "if", "err", ":=", "conn", ".", "Unlisten", "(", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "conn", ".", "die", "(", "err", ")", "\n", "}", "\n", "conn", ".", "channels", "=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ")", "\n", "}", "\n", "conn", ".", "notifications", "=", "nil", "\n\n", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n\n", "if", "conn", ".", "poolResetCount", "!=", "p", ".", "resetCount", "{", "conn", ".", "Close", "(", ")", "\n", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n", "p", ".", "cond", ".", "Signal", "(", ")", "\n", "return", "\n", "}", "\n\n", "if", "conn", ".", "IsAlive", "(", ")", "{", "p", ".", "availableConnections", "=", "append", "(", "p", ".", "availableConnections", ",", "conn", ")", "\n", "}", "else", "{", "p", ".", "removeFromAllConnections", "(", "conn", ")", "\n", "}", "\n", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n", "p", ".", "cond", ".", "Signal", "(", ")", "\n", "}" ]
// Release gives up use of a connection.
[ "Release", "gives", "up", "use", "of", "a", "connection", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L191-L224
146,889
jackc/pgx
conn_pool.go
removeFromAllConnections
func (p *ConnPool) removeFromAllConnections(conn *Conn) bool { for i, c := range p.allConnections { if conn == c { p.allConnections = append(p.allConnections[:i], p.allConnections[i+1:]...) return true } } return false }
go
func (p *ConnPool) removeFromAllConnections(conn *Conn) bool { for i, c := range p.allConnections { if conn == c { p.allConnections = append(p.allConnections[:i], p.allConnections[i+1:]...) return true } } return false }
[ "func", "(", "p", "*", "ConnPool", ")", "removeFromAllConnections", "(", "conn", "*", "Conn", ")", "bool", "{", "for", "i", ",", "c", ":=", "range", "p", ".", "allConnections", "{", "if", "conn", "==", "c", "{", "p", ".", "allConnections", "=", "append", "(", "p", ".", "allConnections", "[", ":", "i", "]", ",", "p", ".", "allConnections", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// removeFromAllConnections Removes the given connection from the list. // It returns true if the connection was found and removed or false otherwise.
[ "removeFromAllConnections", "Removes", "the", "given", "connection", "from", "the", "list", ".", "It", "returns", "true", "if", "the", "connection", "was", "found", "and", "removed", "or", "false", "otherwise", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L228-L236
146,890
jackc/pgx
conn_pool.go
Close
func (p *ConnPool) Close() { p.cond.L.Lock() defer p.cond.L.Unlock() p.closed = true for _, c := range p.availableConnections { _ = c.Close() } // This will cause any checked out connections to be closed on release p.resetCount++ }
go
func (p *ConnPool) Close() { p.cond.L.Lock() defer p.cond.L.Unlock() p.closed = true for _, c := range p.availableConnections { _ = c.Close() } // This will cause any checked out connections to be closed on release p.resetCount++ }
[ "func", "(", "p", "*", "ConnPool", ")", "Close", "(", ")", "{", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "p", ".", "closed", "=", "true", "\n\n", "for", "_", ",", "c", ":=", "range", "p", ".", "availableConnections", "{", "_", "=", "c", ".", "Close", "(", ")", "\n", "}", "\n\n", "// This will cause any checked out connections to be closed on release", "p", ".", "resetCount", "++", "\n", "}" ]
// Close ends the use of a connection pool. It prevents any new connections from // being acquired and closes available underlying connections. Any acquired // connections will be closed when they are released.
[ "Close", "ends", "the", "use", "of", "a", "connection", "pool", ".", "It", "prevents", "any", "new", "connections", "from", "being", "acquired", "and", "closes", "available", "underlying", "connections", ".", "Any", "acquired", "connections", "will", "be", "closed", "when", "they", "are", "released", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L241-L253
146,891
jackc/pgx
conn_pool.go
invalidateAcquired
func (p *ConnPool) invalidateAcquired() { p.resetCount++ for _, c := range p.availableConnections { c.poolResetCount = p.resetCount } p.allConnections = p.allConnections[:len(p.availableConnections)] copy(p.allConnections, p.availableConnections) }
go
func (p *ConnPool) invalidateAcquired() { p.resetCount++ for _, c := range p.availableConnections { c.poolResetCount = p.resetCount } p.allConnections = p.allConnections[:len(p.availableConnections)] copy(p.allConnections, p.availableConnections) }
[ "func", "(", "p", "*", "ConnPool", ")", "invalidateAcquired", "(", ")", "{", "p", ".", "resetCount", "++", "\n\n", "for", "_", ",", "c", ":=", "range", "p", ".", "availableConnections", "{", "c", ".", "poolResetCount", "=", "p", ".", "resetCount", "\n", "}", "\n\n", "p", ".", "allConnections", "=", "p", ".", "allConnections", "[", ":", "len", "(", "p", ".", "availableConnections", ")", "]", "\n", "copy", "(", "p", ".", "allConnections", ",", "p", ".", "availableConnections", ")", "\n", "}" ]
// invalidateAcquired causes all acquired connections to be closed when released. // The pool must already be locked.
[ "invalidateAcquired", "causes", "all", "acquired", "connections", "to", "be", "closed", "when", "released", ".", "The", "pool", "must", "already", "be", "locked", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L277-L286
146,892
jackc/pgx
conn_pool.go
Stat
func (p *ConnPool) Stat() (s ConnPoolStat) { p.cond.L.Lock() defer p.cond.L.Unlock() s.MaxConnections = p.maxConnections s.CurrentConnections = len(p.allConnections) s.AvailableConnections = len(p.availableConnections) return }
go
func (p *ConnPool) Stat() (s ConnPoolStat) { p.cond.L.Lock() defer p.cond.L.Unlock() s.MaxConnections = p.maxConnections s.CurrentConnections = len(p.allConnections) s.AvailableConnections = len(p.availableConnections) return }
[ "func", "(", "p", "*", "ConnPool", ")", "Stat", "(", ")", "(", "s", "ConnPoolStat", ")", "{", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "s", ".", "MaxConnections", "=", "p", ".", "maxConnections", "\n", "s", ".", "CurrentConnections", "=", "len", "(", "p", ".", "allConnections", ")", "\n", "s", ".", "AvailableConnections", "=", "len", "(", "p", ".", "availableConnections", ")", "\n", "return", "\n", "}" ]
// Stat returns connection pool statistics
[ "Stat", "returns", "connection", "pool", "statistics" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L289-L297
146,893
jackc/pgx
conn_pool.go
Exec
func (p *ConnPool) Exec(sql string, arguments ...interface{}) (commandTag CommandTag, err error) { var c *Conn if c, err = p.Acquire(); err != nil { return } defer p.Release(c) return c.Exec(sql, arguments...) }
go
func (p *ConnPool) Exec(sql string, arguments ...interface{}) (commandTag CommandTag, err error) { var c *Conn if c, err = p.Acquire(); err != nil { return } defer p.Release(c) return c.Exec(sql, arguments...) }
[ "func", "(", "p", "*", "ConnPool", ")", "Exec", "(", "sql", "string", ",", "arguments", "...", "interface", "{", "}", ")", "(", "commandTag", "CommandTag", ",", "err", "error", ")", "{", "var", "c", "*", "Conn", "\n", "if", "c", ",", "err", "=", "p", ".", "Acquire", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "defer", "p", ".", "Release", "(", "c", ")", "\n\n", "return", "c", ".", "Exec", "(", "sql", ",", "arguments", "...", ")", "\n", "}" ]
// Exec acquires a connection, delegates the call to that connection, and releases the connection
[ "Exec", "acquires", "a", "connection", "delegates", "the", "call", "to", "that", "connection", "and", "releases", "the", "connection" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L354-L362
146,894
jackc/pgx
conn_pool.go
Begin
func (p *ConnPool) Begin() (*Tx, error) { return p.BeginEx(context.Background(), nil) }
go
func (p *ConnPool) Begin() (*Tx, error) { return p.BeginEx(context.Background(), nil) }
[ "func", "(", "p", "*", "ConnPool", ")", "Begin", "(", ")", "(", "*", "Tx", ",", "error", ")", "{", "return", "p", ".", "BeginEx", "(", "context", ".", "Background", "(", ")", ",", "nil", ")", "\n", "}" ]
// Begin acquires a connection and begins a transaction on it. When the // transaction is closed the connection will be automatically released.
[ "Begin", "acquires", "a", "connection", "and", "begins", "a", "transaction", "on", "it", ".", "When", "the", "transaction", "is", "closed", "the", "connection", "will", "be", "automatically", "released", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L427-L429
146,895
jackc/pgx
conn_pool.go
Deallocate
func (p *ConnPool) Deallocate(name string) (err error) { p.cond.L.Lock() defer p.cond.L.Unlock() for _, c := range p.availableConnections { if err := c.Deallocate(name); err != nil { return err } } p.invalidateAcquired() delete(p.preparedStatements, name) return nil }
go
func (p *ConnPool) Deallocate(name string) (err error) { p.cond.L.Lock() defer p.cond.L.Unlock() for _, c := range p.availableConnections { if err := c.Deallocate(name); err != nil { return err } } p.invalidateAcquired() delete(p.preparedStatements, name) return nil }
[ "func", "(", "p", "*", "ConnPool", ")", "Deallocate", "(", "name", "string", ")", "(", "err", "error", ")", "{", "p", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "c", ":=", "range", "p", ".", "availableConnections", "{", "if", "err", ":=", "c", ".", "Deallocate", "(", "name", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "p", ".", "invalidateAcquired", "(", ")", "\n", "delete", "(", "p", ".", "preparedStatements", ",", "name", ")", "\n\n", "return", "nil", "\n", "}" ]
// Deallocate releases a prepared statement from all connections in the pool.
[ "Deallocate", "releases", "a", "prepared", "statement", "from", "all", "connections", "in", "the", "pool", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L498-L512
146,896
jackc/pgx
conn_pool.go
BeginEx
func (p *ConnPool) BeginEx(ctx context.Context, txOptions *TxOptions) (*Tx, error) { for { c, err := p.Acquire() if err != nil { return nil, err } tx, err := c.BeginEx(ctx, txOptions) if err != nil { alive := c.IsAlive() p.Release(c) // If connection is still alive then the error is not something trying // again on a new connection would fix, so just return the error. But // if the connection is dead try to acquire a new connection and try // again. if alive || ctx.Err() != nil { return nil, err } continue } tx.connPool = p return tx, nil } }
go
func (p *ConnPool) BeginEx(ctx context.Context, txOptions *TxOptions) (*Tx, error) { for { c, err := p.Acquire() if err != nil { return nil, err } tx, err := c.BeginEx(ctx, txOptions) if err != nil { alive := c.IsAlive() p.Release(c) // If connection is still alive then the error is not something trying // again on a new connection would fix, so just return the error. But // if the connection is dead try to acquire a new connection and try // again. if alive || ctx.Err() != nil { return nil, err } continue } tx.connPool = p return tx, nil } }
[ "func", "(", "p", "*", "ConnPool", ")", "BeginEx", "(", "ctx", "context", ".", "Context", ",", "txOptions", "*", "TxOptions", ")", "(", "*", "Tx", ",", "error", ")", "{", "for", "{", "c", ",", "err", ":=", "p", ".", "Acquire", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "tx", ",", "err", ":=", "c", ".", "BeginEx", "(", "ctx", ",", "txOptions", ")", "\n", "if", "err", "!=", "nil", "{", "alive", ":=", "c", ".", "IsAlive", "(", ")", "\n", "p", ".", "Release", "(", "c", ")", "\n\n", "// If connection is still alive then the error is not something trying", "// again on a new connection would fix, so just return the error. But", "// if the connection is dead try to acquire a new connection and try", "// again.", "if", "alive", "||", "ctx", ".", "Err", "(", ")", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "continue", "\n", "}", "\n\n", "tx", ".", "connPool", "=", "p", "\n", "return", "tx", ",", "nil", "\n", "}", "\n", "}" ]
// BeginEx acquires a connection and starts a transaction with txOptions // determining the transaction mode. When the transaction is closed the // connection will be automatically released.
[ "BeginEx", "acquires", "a", "connection", "and", "starts", "a", "transaction", "with", "txOptions", "determining", "the", "transaction", "mode", ".", "When", "the", "transaction", "is", "closed", "the", "connection", "will", "be", "automatically", "released", "." ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L517-L542
146,897
jackc/pgx
conn_pool.go
CopyFrom
func (p *ConnPool) CopyFrom(tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int, error) { c, err := p.Acquire() if err != nil { return 0, err } defer p.Release(c) return c.CopyFrom(tableName, columnNames, rowSrc) }
go
func (p *ConnPool) CopyFrom(tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int, error) { c, err := p.Acquire() if err != nil { return 0, err } defer p.Release(c) return c.CopyFrom(tableName, columnNames, rowSrc) }
[ "func", "(", "p", "*", "ConnPool", ")", "CopyFrom", "(", "tableName", "Identifier", ",", "columnNames", "[", "]", "string", ",", "rowSrc", "CopyFromSource", ")", "(", "int", ",", "error", ")", "{", "c", ",", "err", ":=", "p", ".", "Acquire", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "defer", "p", ".", "Release", "(", "c", ")", "\n\n", "return", "c", ".", "CopyFrom", "(", "tableName", ",", "columnNames", ",", "rowSrc", ")", "\n", "}" ]
// CopyFrom acquires a connection, delegates the call to that connection, and releases the connection
[ "CopyFrom", "acquires", "a", "connection", "delegates", "the", "call", "to", "that", "connection", "and", "releases", "the", "connection" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L545-L553
146,898
jackc/pgx
conn_pool.go
CopyFromReader
func (p *ConnPool) CopyFromReader(r io.Reader, sql string) (CommandTag, error) { c, err := p.Acquire() if err != nil { return "", err } defer p.Release(c) return c.CopyFromReader(r, sql) }
go
func (p *ConnPool) CopyFromReader(r io.Reader, sql string) (CommandTag, error) { c, err := p.Acquire() if err != nil { return "", err } defer p.Release(c) return c.CopyFromReader(r, sql) }
[ "func", "(", "p", "*", "ConnPool", ")", "CopyFromReader", "(", "r", "io", ".", "Reader", ",", "sql", "string", ")", "(", "CommandTag", ",", "error", ")", "{", "c", ",", "err", ":=", "p", ".", "Acquire", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "defer", "p", ".", "Release", "(", "c", ")", "\n\n", "return", "c", ".", "CopyFromReader", "(", "r", ",", "sql", ")", "\n", "}" ]
// CopyFromReader acquires a connection, delegates the call to that connection, and releases the connection
[ "CopyFromReader", "acquires", "a", "connection", "delegates", "the", "call", "to", "that", "connection", "and", "releases", "the", "connection" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L556-L564
146,899
jackc/pgx
conn_pool.go
CopyToWriter
func (p *ConnPool) CopyToWriter(w io.Writer, sql string, args ...interface{}) (CommandTag, error) { c, err := p.Acquire() if err != nil { return "", err } defer p.Release(c) return c.CopyToWriter(w, sql, args...) }
go
func (p *ConnPool) CopyToWriter(w io.Writer, sql string, args ...interface{}) (CommandTag, error) { c, err := p.Acquire() if err != nil { return "", err } defer p.Release(c) return c.CopyToWriter(w, sql, args...) }
[ "func", "(", "p", "*", "ConnPool", ")", "CopyToWriter", "(", "w", "io", ".", "Writer", ",", "sql", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "CommandTag", ",", "error", ")", "{", "c", ",", "err", ":=", "p", ".", "Acquire", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "defer", "p", ".", "Release", "(", "c", ")", "\n\n", "return", "c", ".", "CopyToWriter", "(", "w", ",", "sql", ",", "args", "...", ")", "\n", "}" ]
// CopyToWriter acquires a connection, delegates the call to that connection, and releases the connection
[ "CopyToWriter", "acquires", "a", "connection", "delegates", "the", "call", "to", "that", "connection", "and", "releases", "the", "connection" ]
25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc
https://github.com/jackc/pgx/blob/25c2375fd84652ac32aa0ecc9a6b872a4ab25cdc/conn_pool.go#L567-L575