deprecated.go (3030B)
1 package pq 2 3 import ( 4 "bytes" 5 "database/sql" 6 7 "github.com/lib/pq/pqerror" 8 ) 9 10 // [pq.Error.Severity] values. 11 // 12 // Deprecated: use pqerror.Severity[..] values. 13 // 14 //go:fix inline 15 const ( 16 Efatal = pqerror.SeverityFatal 17 Epanic = pqerror.SeverityPanic 18 Ewarning = pqerror.SeverityWarning 19 Enotice = pqerror.SeverityNotice 20 Edebug = pqerror.SeverityDebug 21 Einfo = pqerror.SeverityInfo 22 Elog = pqerror.SeverityLog 23 ) 24 25 // PGError is an interface used by previous versions of pq. 26 // 27 // Deprecated: use the Error type. This is never used. 28 type PGError interface { 29 Error() string 30 Fatal() bool 31 Get(k byte) (v string) 32 } 33 34 // Get implements the legacy PGError interface. 35 // 36 // Deprecated: new code should use the fields of the Error struct directly. 37 func (e *Error) Get(k byte) (v string) { 38 switch k { 39 case 'S': 40 return e.Severity 41 case 'C': 42 return string(e.Code) 43 case 'M': 44 return e.Message 45 case 'D': 46 return e.Detail 47 case 'H': 48 return e.Hint 49 case 'P': 50 return e.Position 51 case 'p': 52 return e.InternalPosition 53 case 'q': 54 return e.InternalQuery 55 case 'W': 56 return e.Where 57 case 's': 58 return e.Schema 59 case 't': 60 return e.Table 61 case 'c': 62 return e.Column 63 case 'd': 64 return e.DataTypeName 65 case 'n': 66 return e.Constraint 67 case 'F': 68 return e.File 69 case 'L': 70 return e.Line 71 case 'R': 72 return e.Routine 73 } 74 return "" 75 } 76 77 // ParseURL converts a url to a connection string for driver.Open. 78 // 79 // Deprecated: directly passing an URL to sql.Open("postgres", "postgres://...") 80 // now works, and calling this manually is no longer required. 81 func ParseURL(url string) (string, error) { return convertURL(url) } 82 83 // NullTime represents a [time.Time] that may be null. 84 // 85 // Deprecated: this is an alias for [sql.NullTime]. 86 // 87 //go:fix inline 88 type NullTime = sql.NullTime 89 90 // CopyIn creates a COPY FROM statement which can be prepared with Tx.Prepare(). 91 // The target table should be visible in search_path. 92 // 93 // It copies all columns if the list of columns is empty. 94 // 95 // Deprecated: there is no need to use this query builder, you can use: 96 // 97 // tx.Prepare("copy tbl (col1, col2) from stdin") 98 func CopyIn(table string, columns ...string) string { 99 b := bytes.NewBufferString("COPY ") 100 BufferQuoteIdentifier(table, b) 101 makeStmt(b, columns...) 102 return b.String() 103 } 104 105 // CopyInSchema creates a COPY FROM statement which can be prepared with 106 // Tx.Prepare(). 107 // 108 // Deprecated: there is no need to use this query builder, you can use: 109 // 110 // tx.Prepare("copy schema.tbl (col1, col2) from stdin") 111 func CopyInSchema(schema, table string, columns ...string) string { 112 b := bytes.NewBufferString("COPY ") 113 BufferQuoteIdentifier(schema, b) 114 b.WriteRune('.') 115 BufferQuoteIdentifier(table, b) 116 makeStmt(b, columns...) 117 return b.String() 118 } 119 120 func makeStmt(b *bytes.Buffer, columns ...string) { 121 if len(columns) == 0 { 122 b.WriteString(" FROM STDIN") 123 return 124 } 125 b.WriteString(" (") 126 for i, col := range columns { 127 if i != 0 { 128 b.WriteString(", ") 129 } 130 BufferQuoteIdentifier(col, b) 131 } 132 b.WriteString(") FROM STDIN") 133 }