Skip to content

Commit

Permalink
update README and format codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blank committed Sep 2, 2020
1 parent b9117fb commit 2dde88a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
---

sqlx-adapter is a [Sqlx](https://github.com/jmoiron/sqlx) Adapter for [Casbin V2](https://github.com/casbin/casbin/v2).
sqlx-adapter is a [Sqlx](https://github.com/jmoiron/sqlx) Adapter for [Casbin V2](https://github.com/casbin/casbin).

With this library, Casbin can load policy lines from Sqlx supported databases or save policy lines.

Expand All @@ -30,7 +30,7 @@ With this library, Casbin can load policy lines from Sqlx supported databases or


## Simple Examples
### Sqlite3
### SQLite3
```go
package main

Expand Down Expand Up @@ -90,7 +90,7 @@ func main() {
```


### Mysql
### MySQL

```go
package main
Expand Down
4 changes: 2 additions & 2 deletions adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ ROLLBACK:
// selectRows select eligible data by args from the table.
func (p *Adapter) selectRows(query string, args ...interface{}) ([]*CasbinRule, error) {
// make a slice with capacity
lines := make([]*CasbinRule, 0, 32)
lines := make([]*CasbinRule, 0, 64)

if len(args) == 0 {
return lines, p.db.Select(&lines, query)
Expand Down Expand Up @@ -318,7 +318,7 @@ func (p *Adapter) LoadPolicy(model model.Model) error {

// SavePolicy save policy rules to the storage.
func (p *Adapter) SavePolicy(model model.Model) error {
args := make([][]interface{}, 0, 32)
args := make([][]interface{}, 0, 64)

for ptype, ast := range model["p"] {
for _, rule := range ast.Policy {
Expand Down
18 changes: 9 additions & 9 deletions adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func testTableName(t *testing.T, db *sqlx.DB) {

func testSQL(t *testing.T, db *sqlx.DB, tableName string) {
var err error
logSQLErr := func(action string) {
logErr := func(action string) {
if err != nil {
t.Fatalf("%s test failed, err: %v", action, err)
}
Expand All @@ -124,10 +124,10 @@ func testSQL(t *testing.T, db *sqlx.DB, tableName string) {

var a *Adapter
a, err = NewAdapter(db, tableName)
logSQLErr("NewAdapter")
logErr("NewAdapter")

// createTable test has passed when adapter create
// logSQLErr("createTable", a.createTable())
// logErr("createTable", a.createTable())

if b := a.isTableExist(); b == false {
t.Fatal("isTableExist test failed")
Expand All @@ -140,18 +140,18 @@ func testSQL(t *testing.T, db *sqlx.DB, tableName string) {
}

err = a.truncateAndInsertRows(rules)
logSQLErr("truncateAndInsertRows")
logErr("truncateAndInsertRows")

err = a.deleteRows(a.sqlDeleteByArgs, "g")
logSQLErr("deleteRows sqlDeleteByArgs g")
logErr("deleteRows sqlDeleteByArgs g")

err = a.deleteRows(a.sqlDeleteAll)
logSQLErr("deleteRows sqlDeleteAll")
logErr("deleteRows sqlDeleteAll")

_ = a.truncateAndInsertRows(rules)

records, err := a.selectRows(a.sqlSelectAll)
logSQLErr("selectRows sqlSelectAll")
logErr("selectRows sqlSelectAll")
for idx, record := range records {
line := lines[idx]
if !equalValue(*record, line) {
Expand All @@ -160,7 +160,7 @@ func testSQL(t *testing.T, db *sqlx.DB, tableName string) {
}

records, err = a.selectWhereIn(&filter)
logSQLErr("selectWhereIn")
logErr("selectWhereIn")
i := 3
for _, record := range records {
line := lines[i]
Expand All @@ -171,7 +171,7 @@ func testSQL(t *testing.T, db *sqlx.DB, tableName string) {
}

err = a.truncateTable()
logSQLErr("truncateTable")
logErr("truncateTable")
}

func initPolicy(t *testing.T, db *sqlx.DB, tableName string) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/Blank-Xu/sqlx-adapter
go 1.11

require (
github.com/casbin/casbin/v2 v2.11.1
github.com/casbin/casbin/v2 v2.11.2
github.com/jmoiron/sqlx v1.2.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/casbin/casbin/v2 v2.11.1 h1:gMv/ZC5Ao5FkYXrphMCSEh8kOU2nevRVG3VhGtPOgMk=
github.com/casbin/casbin/v2 v2.11.1/go.mod h1:XXtYGrs/0zlOsJMeRteEdVi/FsB0ph7KgNfjoCoJUD8=
github.com/casbin/casbin/v2 v2.11.2 h1:kdJ3ZMfPtz6uzKwAaW4G4NIld0U2KeHrgFcEhi40evc=
github.com/casbin/casbin/v2 v2.11.2/go.mod h1:XXtYGrs/0zlOsJMeRteEdVi/FsB0ph7KgNfjoCoJUD8=
github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=

0 comments on commit 2dde88a

Please sign in to comment.