Skip to content

Commit fc569f3

Browse files
authored
fix: ptype column name (#36)
Signed-off-by: abingcbc <abingcbc626@gmail.com>
1 parent 8d6c19e commit fc569f3

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

adapter.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const DefaultTableName = "casbin_rule"
1818
type CasbinRule struct {
1919
tableName struct{} `pg:"_"`
2020
ID string
21-
PType string
21+
Ptype string
2222
V0 string
2323
V1 string
2424
V2 string
@@ -142,12 +142,12 @@ func (r *CasbinRule) String() string {
142142
var sb strings.Builder
143143

144144
sb.Grow(
145-
len(r.PType) +
145+
len(r.Ptype) +
146146
len(r.V0) + len(r.V1) + len(r.V2) +
147147
len(r.V3) + len(r.V4) + len(r.V5),
148148
)
149149

150-
sb.WriteString(r.PType)
150+
sb.WriteString(r.Ptype)
151151
if len(r.V0) > 0 {
152152
sb.WriteString(prefixLine)
153153
sb.WriteString(r.V0)
@@ -200,7 +200,7 @@ func policyID(ptype string, rule []string) string {
200200
}
201201

202202
func savePolicyLine(ptype string, rule []string) *CasbinRule {
203-
line := &CasbinRule{PType: ptype}
203+
line := &CasbinRule{Ptype: ptype}
204204

205205
l := len(rule)
206206
if l > 0 {
@@ -337,7 +337,7 @@ func (a *Adapter) RemovePolicies(sec string, ptype string, rules [][]string) err
337337

338338
// RemoveFilteredPolicy removes policy rules that match the filter from the storage.
339339
func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error {
340-
query := a.db.Model((*CasbinRule)(nil)).Table(a.tableName).Where("p_type = ?", ptype)
340+
query := a.db.Model((*CasbinRule)(nil)).Table(a.tableName).Where("ptype = ?", ptype)
341341

342342
idx := fieldIndex + len(fieldValues)
343343
if fieldIndex <= 0 && idx > 0 && fieldValues[0-fieldIndex] != "" {
@@ -413,7 +413,7 @@ func (a *Adapter) loadFilteredPolicy(model model.Model, filter *Filter, handler
413413
if filter.P != nil {
414414
lines := []*CasbinRule{}
415415

416-
query := a.db.Model(&lines).Table(a.tableName).Where("p_type = 'p'")
416+
query := a.db.Model(&lines).Table(a.tableName).Where("ptype = 'p'")
417417
query, err := buildQuery(query, filter.P)
418418
if err != nil {
419419
return err
@@ -430,7 +430,7 @@ func (a *Adapter) loadFilteredPolicy(model model.Model, filter *Filter, handler
430430
if filter.G != nil {
431431
lines := []*CasbinRule{}
432432

433-
query := a.db.Model(&lines).Table(a.tableName).Where("p_type = 'g'")
433+
query := a.db.Model(&lines).Table(a.tableName).Where("ptype = 'g'")
434434
query, err := buildQuery(query, filter.G)
435435
if err != nil {
436436
return err
@@ -474,7 +474,7 @@ func (a *Adapter) UpdatePolicies(sec string, ptype string, oldRules, newRules []
474474
func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [][]string, fieldIndex int, fieldValues ...string) ([][]string, error) {
475475
line := &CasbinRule{}
476476

477-
line.PType = ptype
477+
line.Ptype = ptype
478478
if fieldIndex <= 0 && 0 < fieldIndex+len(fieldValues) {
479479
line.V0 = fieldValues[0-fieldIndex]
480480
}
@@ -529,9 +529,9 @@ func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [
529529
}
530530

531531
func (c *CasbinRule) queryString() (string, []interface{}) {
532-
queryArgs := []interface{}{c.PType}
532+
queryArgs := []interface{}{c.Ptype}
533533

534-
queryStr := "p_type = ?"
534+
queryStr := "ptype = ?"
535535
if c.V0 != "" {
536536
queryStr += " and v0 = ?"
537537
queryArgs = append(queryArgs, c.V0)
@@ -562,8 +562,8 @@ func (c *CasbinRule) queryString() (string, []interface{}) {
562562

563563
func (c *CasbinRule) toStringPolicy() []string {
564564
policy := make([]string, 0)
565-
if c.PType != "" {
566-
policy = append(policy, c.PType)
565+
if c.Ptype != "" {
566+
policy = append(policy, c.Ptype)
567567
}
568568
if c.V0 != "" {
569569
policy = append(policy, c.V0)

0 commit comments

Comments
 (0)