Skip to content

Commit

Permalink
Move types.Result to orm.Result.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 11, 2017
1 parent 2d0d5f3 commit c23ec76
Show file tree
Hide file tree
Showing 69 changed files with 318 additions and 292 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@ install:
- go get gopkg.in/check.v1
- go get github.com/onsi/ginkgo
- go get github.com/onsi/gomega
- mkdir -p $HOME/gopath/src/gopkg.in
- mv `pwd` $HOME/gopath/src/gopkg.in/pg.v5
4 changes: 2 additions & 2 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"testing"
"time"

"gopkg.in/pg.v5"
"gopkg.in/pg.v5/orm"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
)

func benchmarkDB() *pg.DB {
Expand Down
6 changes: 3 additions & 3 deletions conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"testing"
"time"

"gopkg.in/pg.v5"
"gopkg.in/pg.v5/orm"
"gopkg.in/pg.v5/types"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
"github.com/go-pg/pg/types"
)

type JSONMap map[string]interface{}
Expand Down
48 changes: 28 additions & 20 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"io"
"time"

"gopkg.in/pg.v5/internal"
"gopkg.in/pg.v5/internal/pool"
"gopkg.in/pg.v5/orm"
"gopkg.in/pg.v5/types"
"github.com/go-pg/pg/internal"
"github.com/go-pg/pg/internal/pool"
"github.com/go-pg/pg/orm"
)

// Connect connects to a database using provided options.
Expand Down Expand Up @@ -141,7 +140,7 @@ func (db *DB) Close() error {

// Exec executes a query ignoring returned rows. The params are for any
// placeholders in the query.
func (db *DB) Exec(query interface{}, params ...interface{}) (res *types.Result, err error) {
func (db *DB) Exec(query interface{}, params ...interface{}) (res orm.Result, err error) {
for i := 0; ; i++ {
var cn *pool.Conn

Expand All @@ -168,7 +167,7 @@ func (db *DB) Exec(query interface{}, params ...interface{}) (res *types.Result,
// ExecOne acts like Exec, but query must affect only one row. It
// returns ErrNoRows error when query returns zero rows or
// ErrMultiRows when query returns multiple rows.
func (db *DB) ExecOne(query interface{}, params ...interface{}) (*types.Result, error) {
func (db *DB) ExecOne(query interface{}, params ...interface{}) (orm.Result, error) {
res, err := db.Exec(query, params...)
if err != nil {
return nil, err
Expand All @@ -182,8 +181,7 @@ func (db *DB) ExecOne(query interface{}, params ...interface{}) (*types.Result,

// Query executes a query that returns rows, typically a SELECT.
// The params are for any placeholders in the query.
func (db *DB) Query(model, query interface{}, params ...interface{}) (res *types.Result, err error) {
var mod orm.Model
func (db *DB) Query(model, query interface{}, params ...interface{}) (res orm.Result, err error) {
for i := 0; i < 3; i++ {
var cn *pool.Conn

Expand All @@ -192,7 +190,7 @@ func (db *DB) Query(model, query interface{}, params ...interface{}) (res *types
return nil, err
}

res, mod, err = db.simpleQueryData(cn, model, query, params...)
res, err = db.simpleQueryData(cn, model, query, params...)
db.freeConn(cn, err)

if i >= db.opt.MaxRetries {
Expand All @@ -208,7 +206,7 @@ func (db *DB) Query(model, query interface{}, params ...interface{}) (res *types
return nil, err
}

if res.RowsReturned() > 0 && mod != nil {
if mod := res.Model(); mod != nil && res.RowsReturned() > 0 {
if err = mod.AfterQuery(db); err != nil {
return res, err
}
Expand All @@ -220,7 +218,7 @@ func (db *DB) Query(model, query interface{}, params ...interface{}) (res *types
// QueryOne acts like Query, but query must return only one row. It
// returns ErrNoRows error when query returns zero rows or
// ErrMultiRows when query returns multiple rows.
func (db *DB) QueryOne(model, query interface{}, params ...interface{}) (*types.Result, error) {
func (db *DB) QueryOne(model, query interface{}, params ...interface{}) (orm.Result, error) {
mod, err := orm.NewModel(model)
if err != nil {
return nil, err
Expand All @@ -247,7 +245,7 @@ func (db *DB) Listen(channels ...string) *Listener {
}

// CopyFrom copies data from reader to a table.
func (db *DB) CopyFrom(reader io.Reader, query interface{}, params ...interface{}) (*types.Result, error) {
func (db *DB) CopyFrom(reader io.Reader, query interface{}, params ...interface{}) (orm.Result, error) {
cn, err := db.conn()
if err != nil {
return nil, err
Expand All @@ -259,7 +257,7 @@ func (db *DB) CopyFrom(reader io.Reader, query interface{}, params ...interface{
}

// CopyTo copies data from a table to writer.
func (db *DB) CopyTo(writer io.Writer, query interface{}, params ...interface{}) (*types.Result, error) {
func (db *DB) CopyTo(writer io.Writer, query interface{}, params ...interface{}) (orm.Result, error) {
cn, err := db.conn()
if err != nil {
return nil, err
Expand Down Expand Up @@ -344,7 +342,7 @@ func (db *DB) cancelRequest(processId, secretKey int32) error {

func (db *DB) simpleQuery(
cn *pool.Conn, query interface{}, params ...interface{},
) (*types.Result, error) {
) (orm.Result, error) {
if err := writeQueryMsg(cn.Wr, db, query, params...); err != nil {
return nil, err
}
Expand All @@ -353,24 +351,34 @@ func (db *DB) simpleQuery(
return nil, err
}

return readSimpleQuery(cn)
res, err := readSimpleQuery(cn)
if err != nil {
return nil, err
}

return res, nil
}

func (db *DB) simpleQueryData(
cn *pool.Conn, model, query interface{}, params ...interface{},
) (*types.Result, orm.Model, error) {
) (orm.Result, error) {
if err := writeQueryMsg(cn.Wr, db, query, params...); err != nil {
return nil, nil, err
return nil, err
}

if err := cn.FlushWriter(); err != nil {
return nil, nil, err
return nil, err
}

res, err := readSimpleQueryData(cn, model)
if err != nil {
return nil, err
}

return readSimpleQueryData(cn, model)
return res, nil
}

func (db *DB) copyFrom(cn *pool.Conn, r io.Reader, query interface{}, params ...interface{}) (*types.Result, error) {
func (db *DB) copyFrom(cn *pool.Conn, r io.Reader, query interface{}, params ...interface{}) (orm.Result, error) {
if err := writeQueryMsg(cn.Wr, db, query, params...); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
"time"

"gopkg.in/pg.v5"
"gopkg.in/pg.v5/orm"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
Package gopkg.in/pg.v5 implements a PostgreSQL client.
Package github.com/go-pg/pg implements a PostgreSQL client.
*/
package pg
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io"
"net"

"gopkg.in/pg.v5/internal"
"github.com/go-pg/pg/internal"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion example_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pg_test
import (
"fmt"

"gopkg.in/pg.v5"
"github.com/go-pg/pg"
)

func ExampleDB_Model_postgresArrayStructTag() {
Expand Down
2 changes: 1 addition & 1 deletion example_hstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pg_test
import (
"fmt"

"gopkg.in/pg.v5"
"github.com/go-pg/pg"
)

func ExampleDB_Model_hstoreStructTag() {
Expand Down
4 changes: 2 additions & 2 deletions example_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

"gopkg.in/pg.v5"
"gopkg.in/pg.v5/orm"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
)

func modelDB() *pg.DB {
Expand Down
2 changes: 1 addition & 1 deletion example_placeholders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pg_test
import (
"fmt"

"gopkg.in/pg.v5"
"github.com/go-pg/pg"
)

type Params struct {
Expand Down
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"time"

"gopkg.in/pg.v5"
"gopkg.in/pg.v5/orm"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
)

var db *pg.DB
Expand Down
4 changes: 2 additions & 2 deletions exampledb_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package pg_test
import (
"fmt"

"gopkg.in/pg.v5"
"gopkg.in/pg.v5/orm"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"
)

type User struct {
Expand Down
2 changes: 1 addition & 1 deletion exampledb_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pg_test
import (
"fmt"

"gopkg.in/pg.v5"
"github.com/go-pg/pg"
)

func CreateUser(db *pg.DB, user *User) error {
Expand Down
2 changes: 1 addition & 1 deletion export_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pg

import "gopkg.in/pg.v5/internal/pool"
import "github.com/go-pg/pg/internal/pool"

func (db *DB) Pool() *pool.ConnPool {
return db.pool
Expand Down
4 changes: 2 additions & 2 deletions hook_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pg_test

import (
"gopkg.in/pg.v5"
"gopkg.in/pg.v5/orm"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
2 changes: 1 addition & 1 deletion internal/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func LogQuery(query string) {
QueryLogger.Printf("%s:%d: %s", file, line, strings.TrimRight(query, "\t\n"))
}

const packageName = "gopkg.in/pg.v5"
const packageName = "github.com/go-pg/pg"

func fileLine(depth int) (string, int) {
for i := depth; ; i++ {
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/array_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parser_test
import (
"testing"

"gopkg.in/pg.v5/internal/parser"
"github.com/go-pg/pg/internal/parser"
)

var arrayTests = []struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/hstore_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parser_test
import (
"testing"

"gopkg.in/pg.v5/internal/parser"
"github.com/go-pg/pg/internal/parser"
)

var hstoreTests = []struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"strconv"

"gopkg.in/pg.v5/internal"
"github.com/go-pg/pg/internal"
)

type Parser struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/pool/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"gopkg.in/pg.v5/internal/pool"
"github.com/go-pg/pg/internal/pool"
)

func benchmarkPoolGetPut(b *testing.B, poolSize int) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync/atomic"
"time"

"gopkg.in/pg.v5/internal"
"github.com/go-pg/pg/internal"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion internal/pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"gopkg.in/pg.v5/internal/pool"
"github.com/go-pg/pg/internal/pool"
)

var _ = Describe("ConnPool", func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/underscore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package internal_test
import (
"testing"

"gopkg.in/pg.v5/internal"
"github.com/go-pg/pg/internal"
)

func TestUnderscore(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"sync"
"time"

"gopkg.in/pg.v5/internal"
"gopkg.in/pg.v5/internal/pool"
"github.com/go-pg/pg/internal"
"github.com/go-pg/pg/internal/pool"
)

// A notification received with LISTEN command.
Expand Down
2 changes: 1 addition & 1 deletion listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net"
"time"

"gopkg.in/pg.v5"
"github.com/go-pg/pg"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
4 changes: 2 additions & 2 deletions loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package pg_test
import (
"errors"

"gopkg.in/pg.v5"
"gopkg.in/pg.v5/orm"
"github.com/go-pg/pg"
"github.com/go-pg/pg/orm"

. "gopkg.in/check.v1"
)
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"gopkg.in/pg.v5"
"github.com/go-pg/pg"

. "github.com/onsi/ginkgo"
. "gopkg.in/check.v1"
Expand Down
Loading

0 comments on commit c23ec76

Please sign in to comment.