From 841f1fd07456fa1b723a4b48127839262e90770b Mon Sep 17 00:00:00 2001 From: Philipp Seitz <44158030+PhilippSeitz@users.noreply.github.com> Date: Sat, 4 Jul 2020 14:06:06 +0200 Subject: [PATCH] update readme --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 5916b28..7745c41 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,31 @@ func main() { } ``` +## Custom DB Connection + +You can provide a custom table or database name with `pgadapter.NewAdapterByDB` + +```go +package main + +import ( + "github.com/casbin/casbin/v2" + pgadapter "github.com/casbin/casbin-pg-adapter" + "github.com/go-pg/pg/v9" +) + +func main() { + opts, _ := pg.ParseURL("postgresql://pguser:pgpassword@localhost:5432/pgdb?sslmode=disable") + + db := pg.Connect(opts) + defer db.Close() + + a, _ := pgadapter.NewAdapterByDB(db, pgadapter.WithTableName("custom_table")) + e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a) + ... +} +``` + ## Run all tests docker-compose run --rm go