From ba8ac974aaa16ebcf00f17c653d131a3b6d74a30 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Wed, 13 Apr 2022 12:46:09 +0800 Subject: [PATCH] refactor: move postgres to pg package (#1781) --- core/collection/timingwheel.go | 4 ++-- core/stores/pg/postgresql.go | 14 ++++++++++++++ core/stores/pg/postgresql_test.go | 11 +++++++++++ core/stores/postgres/postgresql.go | 15 ++++----------- 4 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 core/stores/pg/postgresql.go create mode 100644 core/stores/pg/postgresql_test.go diff --git a/core/collection/timingwheel.go b/core/collection/timingwheel.go index 38953c8bf..d1f1ea330 100644 --- a/core/collection/timingwheel.go +++ b/core/collection/timingwheel.go @@ -71,8 +71,8 @@ func NewTimingWheel(interval time.Duration, numSlots int, execute Execute) (*Tim return newTimingWheelWithClock(interval, numSlots, execute, timex.NewTicker(interval)) } -func newTimingWheelWithClock(interval time.Duration, numSlots int, execute Execute, ticker timex.Ticker) ( - *TimingWheel, error) { +func newTimingWheelWithClock(interval time.Duration, numSlots int, execute Execute, + ticker timex.Ticker) (*TimingWheel, error) { tw := &TimingWheel{ interval: interval, ticker: ticker, diff --git a/core/stores/pg/postgresql.go b/core/stores/pg/postgresql.go new file mode 100644 index 000000000..f813836f8 --- /dev/null +++ b/core/stores/pg/postgresql.go @@ -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...) +} diff --git a/core/stores/pg/postgresql_test.go b/core/stores/pg/postgresql_test.go new file mode 100644 index 000000000..15628ec95 --- /dev/null +++ b/core/stores/pg/postgresql_test.go @@ -0,0 +1,11 @@ +package pg + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestPostgreSql(t *testing.T) { + assert.NotNil(t, New("postgre")) +} diff --git a/core/stores/postgres/postgresql.go b/core/stores/postgres/postgresql.go index 48d6e3a00..4aee19337 100644 --- a/core/stores/postgres/postgresql.go +++ b/core/stores/postgres/postgresql.go @@ -1,14 +1,7 @@ package postgres -import ( - // imports the driver, don't remove this comment, golint requires. - _ "github.com/lib/pq" - "github.com/zeromicro/go-zero/core/stores/sqlx" -) +import "github.com/zeromicro/go-zero/core/stores/pg" -const postgresDriverName = "postgres" - -// New returns a postgres connection. -func New(datasource string, opts ...sqlx.SqlOption) sqlx.SqlConn { - return sqlx.NewSqlConn(postgresDriverName, datasource, opts...) -} +// New creates a new postgresql store. +// Deprecated: use pg.New instead. +var New = pg.New