2
0

Rename PreparedStatementDescription to StatementDescription

PreparedStatementDescription was too long. It also no longer entirely
represents its purpose now that it is also intended for use with
described statements.
This commit is contained in:
Jack Christensen
2019-08-24 20:39:01 -05:00
parent 78abbdf1d7
commit da9fc85c44
3 changed files with 10 additions and 9 deletions
+5 -4
View File
@@ -517,15 +517,16 @@ func (ct CommandTag) String() string {
return string(ct)
}
type PreparedStatementDescription struct {
type StatementDescription struct {
Name string
SQL string
ParamOIDs []uint32
Fields []pgproto3.FieldDescription
}
// Prepare creates a prepared statement.
func (pgConn *PgConn) Prepare(ctx context.Context, name, sql string, paramOIDs []uint32) (*PreparedStatementDescription, error) {
// Prepare creates a prepared statement. If the name is empty, the anonymous prepared statement will be used. This
// allows Prepare to also to describe statements without creating a server-side prepared statement.
func (pgConn *PgConn) Prepare(ctx context.Context, name, sql string, paramOIDs []uint32) (*StatementDescription, error) {
if err := pgConn.lock(); err != nil {
return nil, linkErrors(err, ErrNoBytesSent)
}
@@ -553,7 +554,7 @@ func (pgConn *PgConn) Prepare(ctx context.Context, name, sql string, paramOIDs [
return nil, linkErrors(ctx.Err(), err)
}
psd := &PreparedStatementDescription{Name: name, SQL: sql}
psd := &StatementDescription{Name: name, SQL: sql}
var parseErr error
+4 -4
View File
@@ -40,10 +40,10 @@ func NewLRU(conn *pgconn.PgConn, mode int, cap int) *LRU {
}
// Get returns the prepared statement description for sql preparing or describing the sql on the server as needed.
func (c *LRU) Get(ctx context.Context, sql string) (*pgconn.PreparedStatementDescription, error) {
func (c *LRU) Get(ctx context.Context, sql string) (*pgconn.StatementDescription, error) {
if el, ok := c.m[sql]; ok {
c.l.MoveToFront(el)
return el.Value.(*pgconn.PreparedStatementDescription), nil
return el.Value.(*pgconn.StatementDescription), nil
}
if c.l.Len() == c.cap {
@@ -91,7 +91,7 @@ func (c *LRU) Mode() int {
return c.mode
}
func (c *LRU) prepare(ctx context.Context, sql string) (*pgconn.PreparedStatementDescription, error) {
func (c *LRU) prepare(ctx context.Context, sql string) (*pgconn.StatementDescription, error) {
var name string
if c.mode == ModePrepare {
name = fmt.Sprintf("%s_%d", c.psNamePrefix, c.prepareCount)
@@ -105,7 +105,7 @@ func (c *LRU) removeOldest(ctx context.Context) error {
oldest := c.l.Back()
c.l.Remove(oldest)
if c.mode == ModePrepare {
return c.conn.Exec(ctx, fmt.Sprintf("deallocate %s", oldest.Value.(*pgconn.PreparedStatementDescription).Name)).Close()
return c.conn.Exec(ctx, fmt.Sprintf("deallocate %s", oldest.Value.(*pgconn.StatementDescription).Name)).Close()
}
return nil
}
+1 -1
View File
@@ -15,7 +15,7 @@ const (
// Cache prepares and caches prepared statement descriptions.
type Cache interface {
// Get returns the prepared statement description for sql preparing or describing the sql on the server as needed.
Get(ctx context.Context, sql string) (*pgconn.PreparedStatementDescription, error)
Get(ctx context.Context, sql string) (*pgconn.StatementDescription, error)
// Clear removes all entries in the cache. Any prepared statements will be deallocated from the PostgreSQL session.
Clear(ctx context.Context) error