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