mirror of https://github.com/jackc/pgx.git
Remove another allocation
parent
c067c970cf
commit
b12b579814
|
@ -73,6 +73,8 @@ type PgConn struct {
|
||||||
pendingReadyForQueryCount int32
|
pendingReadyForQueryCount int32
|
||||||
|
|
||||||
closed bool
|
closed bool
|
||||||
|
|
||||||
|
resultReader PgResultReader
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect establishes a connection to a PostgreSQL server using the environment and connString (in URL or DSN format)
|
// Connect establishes a connection to a PostgreSQL server using the environment and connString (in URL or DSN format)
|
||||||
|
@ -536,9 +538,9 @@ type PgResultReader struct {
|
||||||
cleanupContext func()
|
cleanupContext func()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetResult returns a PgResultReader for the next result. If all results are
|
// GetResult returns a PgResultReader for the next result. If all results are consumed it returns nil. If an error
|
||||||
// consumed it returns nil. If an error occurs it will be reported on the
|
// occurs it will be reported on the returned PgResultReader. Returned PgResultReader is only valid until next call of
|
||||||
// returned PgResultReader.
|
// GetResult.
|
||||||
func (pgConn *PgConn) GetResult(ctx context.Context) *PgResultReader {
|
func (pgConn *PgConn) GetResult(ctx context.Context) *PgResultReader {
|
||||||
cleanupContext := contextDoneToConnDeadline(ctx, pgConn.conn)
|
cleanupContext := contextDoneToConnDeadline(ctx, pgConn.conn)
|
||||||
|
|
||||||
|
@ -546,20 +548,25 @@ func (pgConn *PgConn) GetResult(ctx context.Context) *PgResultReader {
|
||||||
msg, err := pgConn.ReceiveMessage()
|
msg, err := pgConn.ReceiveMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cleanupContext()
|
cleanupContext()
|
||||||
return &PgResultReader{pgConn: pgConn, ctx: ctx, err: preferContextOverNetTimeoutError(ctx, err), complete: true}
|
pgConn.resultReader = PgResultReader{pgConn: pgConn, ctx: ctx, err: preferContextOverNetTimeoutError(ctx, err), complete: true}
|
||||||
|
return &pgConn.resultReader
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *pgproto3.RowDescription:
|
case *pgproto3.RowDescription:
|
||||||
return &PgResultReader{pgConn: pgConn, ctx: ctx, cleanupContext: cleanupContext, fieldDescriptions: msg.Fields}
|
pgConn.resultReader = PgResultReader{pgConn: pgConn, ctx: ctx, cleanupContext: cleanupContext, fieldDescriptions: msg.Fields}
|
||||||
|
return &pgConn.resultReader
|
||||||
case *pgproto3.DataRow:
|
case *pgproto3.DataRow:
|
||||||
return &PgResultReader{pgConn: pgConn, ctx: ctx, cleanupContext: cleanupContext, rowValues: msg.Values, preloadedRowValues: true}
|
pgConn.resultReader = PgResultReader{pgConn: pgConn, ctx: ctx, cleanupContext: cleanupContext, rowValues: msg.Values, preloadedRowValues: true}
|
||||||
|
return &pgConn.resultReader
|
||||||
case *pgproto3.CommandComplete:
|
case *pgproto3.CommandComplete:
|
||||||
cleanupContext()
|
cleanupContext()
|
||||||
return &PgResultReader{pgConn: pgConn, ctx: ctx, commandTag: CommandTag(msg.CommandTag), complete: true}
|
pgConn.resultReader = PgResultReader{pgConn: pgConn, ctx: ctx, commandTag: CommandTag(msg.CommandTag), complete: true}
|
||||||
|
return &pgConn.resultReader
|
||||||
case *pgproto3.ErrorResponse:
|
case *pgproto3.ErrorResponse:
|
||||||
cleanupContext()
|
cleanupContext()
|
||||||
return &PgResultReader{pgConn: pgConn, ctx: ctx, err: errorResponseToPgError(msg), complete: true}
|
pgConn.resultReader = PgResultReader{pgConn: pgConn, ctx: ctx, err: errorResponseToPgError(msg), complete: true}
|
||||||
|
return &pgConn.resultReader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue