Skip to content

Commit

Permalink
Merge pull request #2 from Dasio/master
Browse files Browse the repository at this point in the history
Add option to create adapter directly from *pg.DB
  • Loading branch information
hsluoyz authored Feb 15, 2020
2 parents b176188 + 91dd054 commit 4b984d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
10 changes: 10 additions & 0 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ func NewAdapter(arg interface{}) (*Adapter, error) {
return a, nil
}

// NewAdapterByDB creates new Adapter by using existing DB connection
// creates table from CasbinRule struct if it doesn't exist
func NewAdapterByDB(db *pg.DB) (*Adapter, error) {
a := &Adapter{db: db}
if err := a.createTable(); err != nil {
return nil, fmt.Errorf("pgadapter.NewAdapter: %v", err)
}
return a, nil
}

func createCasbinDatabase(arg interface{}) (*pg.DB, error) {
var opts *pg.Options
var err error
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/casbin/casbin-pg-adapter
go 1.12

require (
github.com/casbin/casbin v1.9.1
github.com/casbin/casbin/v2 v2.1.2
github.com/go-pg/pg/v9 v9.1.0
github.com/mmcloughlin/meow v0.0.0-20181112033425-871e50784daf
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/casbin/casbin v1.9.1 h1:ucjbS5zTrmSLtH4XogqOG920Poe6QatdXtz1FEbApeM=
github.com/casbin/casbin v1.9.1/go.mod h1:z8uPsfBJGUsnkagrt3G8QvjgTKFMBJ32UP8HpZllfog=
github.com/casbin/casbin/v2 v2.1.2 h1:bTwon/ECRx9dwBy2ewRVr5OiqjeXSGiTUY74sDPQi/g=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/codemodus/kace v0.5.1 h1:4OCsBlE2c/rSJo375ggfnucv9eRzge/U5LrrOZd47HA=
Expand Down

0 comments on commit 4b984d2

Please sign in to comment.