Skip to content

Commit

Permalink
Renamed db packahe to pg (preparing to add mysql package)
Browse files Browse the repository at this point in the history
  • Loading branch information
evt committed Oct 7, 2020
1 parent 17a5f74 commit d3f9fbe
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/api/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export GC_BUCKET=my-cool-bucket

# Local postgres
export PG_URL=postgres://postgres:postgres@localhost/test?sslmode=disable
export PG_MIGRATIONS_PATH=file://../../db//migrations
export PG_MIGRATIONS_PATH=file://../../pg/migrations

# Logger settings
export LOG_LEVEL=debug
10 changes: 5 additions & 5 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

"github.com/evt/rest-api-example/config"
"github.com/evt/rest-api-example/controller"
"github.com/evt/rest-api-example/db"
libError "github.com/evt/rest-api-example/lib/error"
"github.com/evt/rest-api-example/lib/validator"
"github.com/evt/rest-api-example/logger"
"github.com/evt/rest-api-example/repository/pg"
"github.com/evt/rest-api-example/pg"
pgrepo "github.com/evt/rest-api-example/repository/pg"
"github.com/evt/rest-api-example/service/web"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
Expand Down Expand Up @@ -45,7 +45,7 @@ func run() error {
l := logger.Get()

// connect to Postgres
pgDB, err := db.Dial(cfg)
pgDB, err := pg.Dial(cfg)
if err != nil {
log.Fatal(err)
}
Expand All @@ -63,8 +63,8 @@ func run() error {
}

// Init repositories
userRepo := pg.NewUserRepo(pgDB)
fileRepo := pg.NewFileRepo(pgDB)
userRepo := pgrepo.NewUserRepo(pgDB)
fileRepo := pgrepo.NewFileRepo(pgDB)
fileContentRepo := gcloudRepo.NewFileRepo(cloudStorage, cfg.GCBucket)

// Init services
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion db/pg.go → pg/pg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db
package pg

import (
"time"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"info": {
"_postman_id": "8e87341e-2892-494b-a0e9-8ff700847a2e",
"name": "Simple Web Server",
"name": "REST API Example",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
Expand Down
14 changes: 14 additions & 0 deletions postman/REST API Server Local.postman_environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "33494e3e-f94d-41f2-9035-566955b2ffd2",
"name": "REST API Server Local",
"values": [
{
"key": "rest_api_addr",
"value": "http://127.0.0.1:8080",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2020-10-07T17:49:31.940Z",
"_postman_exported_using": "Postman/7.33.1"
}
14 changes: 7 additions & 7 deletions repository/pg/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (

"github.com/google/uuid"

"github.com/evt/rest-api-example/db"
"github.com/evt/rest-api-example/model"
"github.com/go-pg/pg/v10"
"github.com/evt/rest-api-example/pg"
gopg "github.com/go-pg/pg/v10"
)

// FilePgRepo ...
type FilePgRepo struct {
db *db.PgDB
db *pg.PgDB
}

// NewFileRepo ...
func NewFileRepo(db *db.PgDB) *FilePgRepo {
func NewFileRepo(db *pg.PgDB) *FilePgRepo {
return &FilePgRepo{db: db}
}

Expand All @@ -27,7 +27,7 @@ func (repo *FilePgRepo) Get(ctx context.Context, id uuid.UUID) (*model.DBFile, e
Where("id = ?", id).
Select()
if err != nil {
if err == pg.ErrNoRows { //not found
if err == gopg.ErrNoRows { //not found
return nil, nil
}
return nil, err
Expand All @@ -53,7 +53,7 @@ func (repo *FilePgRepo) Update(ctx context.Context, user *model.DBFile) (*model.
Returning("*").
Update()
if err != nil {
if err == pg.ErrNoRows { //not found
if err == gopg.ErrNoRows { //not found
return nil, nil
}
return nil, err
Expand All @@ -68,7 +68,7 @@ func (repo *FilePgRepo) Delete(ctx context.Context, id uuid.UUID) error {
Where("id = ?", id).
Delete()
if err != nil {
if err == pg.ErrNoRows {
if err == gopg.ErrNoRows {
return nil
}
return err
Expand Down
14 changes: 7 additions & 7 deletions repository/pg/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (

"github.com/google/uuid"

"github.com/evt/rest-api-example/db"
"github.com/evt/rest-api-example/model"
"github.com/go-pg/pg/v10"
"github.com/evt/rest-api-example/pg"
gopg "github.com/go-pg/pg/v10"
)

// UserPgRepo ...
type UserPgRepo struct {
db *db.PgDB
db *pg.PgDB
}

// NewUserRepo ...
func NewUserRepo(db *db.PgDB) *UserPgRepo {
func NewUserRepo(db *pg.PgDB) *UserPgRepo {
return &UserPgRepo{db: db}
}

Expand All @@ -27,7 +27,7 @@ func (repo *UserPgRepo) GetUser(ctx context.Context, id uuid.UUID) (*model.DBUse
Where("id = ?", id).
Select()
if err != nil {
if err == pg.ErrNoRows { //not found
if err == gopg.ErrNoRows { //not found
return nil, nil
}
return nil, err
Expand All @@ -53,7 +53,7 @@ func (repo *UserPgRepo) UpdateUser(ctx context.Context, user *model.DBUser) (*mo
Returning("*").
Update()
if err != nil {
if err == pg.ErrNoRows { //not found
if err == gopg.ErrNoRows { //not found
return nil, nil
}
return nil, err
Expand All @@ -68,7 +68,7 @@ func (repo *UserPgRepo) DeleteUser(ctx context.Context, id uuid.UUID) error {
Where("id = ?", id).
Delete()
if err != nil {
if err == pg.ErrNoRows {
if err == gopg.ErrNoRows {
return nil
}
return err
Expand Down

0 comments on commit d3f9fbe

Please sign in to comment.