mirror of https://github.com/jackc/pgx.git
Merge branch 'master' into v5-dev
commit
4b6d527b0b
20
README.md
20
README.md
|
@ -98,26 +98,6 @@ There are three areas in particular where pgx can provide a significant performa
|
||||||
perform nearly 3x the number of queries per second.
|
perform nearly 3x the number of queries per second.
|
||||||
3. Batched queries - Multiple queries can be batched together to minimize network round trips.
|
3. Batched queries - Multiple queries can be batched together to minimize network round trips.
|
||||||
|
|
||||||
## Comparison with Alternatives
|
|
||||||
|
|
||||||
* [pq](http://godoc.org/github.com/lib/pq)
|
|
||||||
* [go-pg](https://github.com/go-pg/pg)
|
|
||||||
|
|
||||||
For prepared queries with small sets of simple data types, all drivers will have have similar performance. However, if prepared statements aren't being explicitly used, pgx can have a significant performance advantage due to automatic statement preparation.
|
|
||||||
pgx also can perform better when using PostgreSQL-specific data types or query batching. See
|
|
||||||
[go_db_bench](https://github.com/jackc/go_db_bench) for some database driver benchmarks.
|
|
||||||
|
|
||||||
### Compatibility with `database/sql`
|
|
||||||
|
|
||||||
pq is exclusively used with `database/sql`. go-pg does not use `database/sql` at all. pgx supports `database/sql` as well as
|
|
||||||
its own interface.
|
|
||||||
|
|
||||||
### Level of access, ORM
|
|
||||||
|
|
||||||
go-pg is a PostgreSQL client and ORM. It includes many features that traditionally sit above the database driver, such as ORM, struct mapping, soft deletes, schema migrations, and sharding support.
|
|
||||||
|
|
||||||
pgx is "closer to the metal" and such abstractions are beyond the scope of the pgx project, which first and foremost, aims to be a performant driver and toolkit.
|
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
pgx tests naturally require a PostgreSQL database. It will connect to the database specified in the `PGX_TEST_DATABASE` environment
|
pgx tests naturally require a PostgreSQL database. It will connect to the database specified in the `PGX_TEST_DATABASE` environment
|
||||||
|
|
24
conn.go
24
conn.go
|
@ -366,30 +366,6 @@ func (c *Conn) Ping(ctx context.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func connInfoFromRows(rows Rows, err error) (map[string]uint32, error) {
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
nameOIDs := make(map[string]uint32, 256)
|
|
||||||
for rows.Next() {
|
|
||||||
var oid uint32
|
|
||||||
var name pgtype.Text
|
|
||||||
if err = rows.Scan(&oid, &name); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
nameOIDs[name.String] = oid
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nameOIDs, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// PgConn returns the underlying *pgconn.PgConn. This is an escape hatch method that allows lower level access to the
|
// PgConn returns the underlying *pgconn.PgConn. This is an escape hatch method that allows lower level access to the
|
||||||
// PostgreSQL connection than pgx exposes.
|
// PostgreSQL connection than pgx exposes.
|
||||||
//
|
//
|
||||||
|
|
|
@ -108,13 +108,13 @@ func (o *LargeObject) Tell() (n int64, err error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trunctes the large object to size.
|
// Truncate the large object to size.
|
||||||
func (o *LargeObject) Truncate(size int64) (err error) {
|
func (o *LargeObject) Truncate(size int64) (err error) {
|
||||||
_, err = o.tx.Exec(o.ctx, "select lo_truncate64($1, $2)", o.fd, size)
|
_, err = o.tx.Exec(o.ctx, "select lo_truncate64($1, $2)", o.fd, size)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closees the large object descriptor.
|
// Close the large object descriptor.
|
||||||
func (o *LargeObject) Close() error {
|
func (o *LargeObject) Close() error {
|
||||||
_, err := o.tx.Exec(o.ctx, "select lo_close($1)", o.fd)
|
_, err := o.tx.Exec(o.ctx, "select lo_close($1)", o.fd)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -163,7 +163,7 @@ func RandomizeHostOrderFunc(ctx context.Context, connConfig *pgx.ConnConfig) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func OpenDB(config pgx.ConnConfig, opts ...OptionOpenDB) *sql.DB {
|
func GetConnector(config pgx.ConnConfig, opts ...OptionOpenDB) driver.Connector {
|
||||||
c := connector{
|
c := connector{
|
||||||
ConnConfig: config,
|
ConnConfig: config,
|
||||||
BeforeConnect: func(context.Context, *pgx.ConnConfig) error { return nil }, // noop before connect by default
|
BeforeConnect: func(context.Context, *pgx.ConnConfig) error { return nil }, // noop before connect by default
|
||||||
|
@ -175,7 +175,11 @@ func OpenDB(config pgx.ConnConfig, opts ...OptionOpenDB) *sql.DB {
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(&c)
|
opt(&c)
|
||||||
}
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpenDB(config pgx.ConnConfig, opts ...OptionOpenDB) *sql.DB {
|
||||||
|
c := GetConnector(config, opts...)
|
||||||
return sql.OpenDB(c)
|
return sql.OpenDB(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue