Skip to content

Commit

Permalink
Remove some now unused pgtype code
Browse files Browse the repository at this point in the history
Most of this is in conversion, and I assume it became unused with some
of the v5 changes and refactors to a codec-based approach.

There are likely a few more cleanups to be made, but these ones seemed
easy and safe to start with.
  • Loading branch information
danmcgee-soda authored and jackc committed Jul 11, 2023
1 parent 0328d31 commit 507a9e9
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 440 deletions.
4 changes: 2 additions & 2 deletions examples/url_shortener/main.go
Expand Up @@ -2,7 +2,7 @@ package main

import (
"context"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand All @@ -29,7 +29,7 @@ func getUrlHandler(w http.ResponseWriter, req *http.Request) {
func putUrlHandler(w http.ResponseWriter, req *http.Request) {
id := req.URL.Path
var url string
if body, err := ioutil.ReadAll(req.Body); err == nil {
if body, err := io.ReadAll(req.Body); err == nil {
url = string(body)
} else {
http.Error(w, "Internal server error", http.StatusInternalServerError)
Expand Down
22 changes: 0 additions & 22 deletions pgtype/array.go
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"fmt"
"io"
"reflect"
"strconv"
"strings"
"unicode"
Expand Down Expand Up @@ -375,27 +374,6 @@ func quoteArrayElementIfNeeded(src string) string {
return src
}

func findDimensionsFromValue(value reflect.Value, dimensions []ArrayDimension, elementsLength int) ([]ArrayDimension, int, bool) {
switch value.Kind() {
case reflect.Array:
fallthrough
case reflect.Slice:
length := value.Len()
if 0 == elementsLength {
elementsLength = length
} else {
elementsLength *= length
}
dimensions = append(dimensions, ArrayDimension{Length: int32(length), LowerBound: 1})
for i := 0; i < length; i++ {
if d, l, ok := findDimensionsFromValue(value.Index(i), dimensions, elementsLength); ok {
return d, l, true
}
}
}
return dimensions, elementsLength, true
}

// Array represents a PostgreSQL array for T. It implements the ArrayGetter and ArraySetter interfaces. It preserves
// PostgreSQL dimensions and custom lower bounds. Use FlatArray if these are not needed.
type Array[T any] struct {
Expand Down

0 comments on commit 507a9e9

Please sign in to comment.