refactor: move postgres to pg package (#1781)
This commit is contained in:
@@ -71,8 +71,8 @@ func NewTimingWheel(interval time.Duration, numSlots int, execute Execute) (*Tim
|
|||||||
return newTimingWheelWithClock(interval, numSlots, execute, timex.NewTicker(interval))
|
return newTimingWheelWithClock(interval, numSlots, execute, timex.NewTicker(interval))
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTimingWheelWithClock(interval time.Duration, numSlots int, execute Execute, ticker timex.Ticker) (
|
func newTimingWheelWithClock(interval time.Duration, numSlots int, execute Execute,
|
||||||
*TimingWheel, error) {
|
ticker timex.Ticker) (*TimingWheel, error) {
|
||||||
tw := &TimingWheel{
|
tw := &TimingWheel{
|
||||||
interval: interval,
|
interval: interval,
|
||||||
ticker: ticker,
|
ticker: ticker,
|
||||||
|
|||||||
14
core/stores/pg/postgresql.go
Normal file
14
core/stores/pg/postgresql.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package pg
|
||||||
|
|
||||||
|
import (
|
||||||
|
// imports the driver, don't remove this comment, golint requires.
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
const postgresDriverName = "postgres"
|
||||||
|
|
||||||
|
// New returns a postgres connection.
|
||||||
|
func New(datasource string, opts ...sqlx.SqlOption) sqlx.SqlConn {
|
||||||
|
return sqlx.NewSqlConn(postgresDriverName, datasource, opts...)
|
||||||
|
}
|
||||||
11
core/stores/pg/postgresql_test.go
Normal file
11
core/stores/pg/postgresql_test.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package pg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPostgreSql(t *testing.T) {
|
||||||
|
assert.NotNil(t, New("postgre"))
|
||||||
|
}
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
package postgres
|
package postgres
|
||||||
|
|
||||||
import (
|
import "github.com/zeromicro/go-zero/core/stores/pg"
|
||||||
// imports the driver, don't remove this comment, golint requires.
|
|
||||||
_ "github.com/lib/pq"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
|
|
||||||
const postgresDriverName = "postgres"
|
// New creates a new postgresql store.
|
||||||
|
// Deprecated: use pg.New instead.
|
||||||
// New returns a postgres connection.
|
var New = pg.New
|
||||||
func New(datasource string, opts ...sqlx.SqlOption) sqlx.SqlConn {
|
|
||||||
return sqlx.NewSqlConn(postgresDriverName, datasource, opts...)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user