Skip to content

Commit 84f074b

Browse files
authored
fix!: Rename p-type column to ptype & PType to Ptype (#54)
BREAKING CHANGE: Rename `p-type` column in the database to `ptype` and Filter.PType to Filter.Ptype
1 parent 7a90dd8 commit 84f074b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

adapter.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (the *CasbinRule) TableName() string {
3636

3737
// CasbinRule .
3838
type CasbinRule struct {
39-
PType string `xorm:"varchar(100) index not null default ''"`
39+
Ptype string `xorm:"varchar(100) index not null default ''"`
4040
V0 string `xorm:"varchar(100) index not null default ''"`
4141
V1 string `xorm:"varchar(100) index not null default ''"`
4242
V2 string `xorm:"varchar(100) index not null default ''"`
@@ -60,7 +60,7 @@ type Adapter struct {
6060

6161
// Filter .
6262
type Filter struct {
63-
PType []string
63+
Ptype []string
6464
V0 []string
6565
V1 []string
6666
V2 []string
@@ -249,7 +249,7 @@ func (a *Adapter) dropTable() error {
249249
}
250250

251251
func loadPolicyLine(line *CasbinRule, model model.Model) {
252-
var p = []string{line.PType,
252+
var p = []string{line.Ptype,
253253
line.V0, line.V1, line.V2, line.V3, line.V4, line.V5}
254254
var lineText string
255255
if line.V5 != "" {
@@ -285,7 +285,7 @@ func (a *Adapter) LoadPolicy(model model.Model) error {
285285
}
286286

287287
func (a *Adapter) genPolicyLine(ptype string, rule []string) *CasbinRule {
288-
line := CasbinRule{PType: ptype, tableName: a.getFullTableName()}
288+
line := CasbinRule{Ptype: ptype, tableName: a.getFullTableName()}
289289

290290
l := len(rule)
291291
if l > 0 {
@@ -393,7 +393,7 @@ func (a *Adapter) RemovePolicies(sec string, ptype string, rules [][]string) err
393393

394394
// RemoveFilteredPolicy removes policy rules that match the filter from the storage.
395395
func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error {
396-
line := CasbinRule{PType: ptype, tableName: a.getFullTableName()}
396+
line := CasbinRule{Ptype: ptype, tableName: a.getFullTableName()}
397397

398398
idx := fieldIndex + len(fieldValues)
399399
if fieldIndex <= 0 && idx > 0 {
@@ -448,7 +448,7 @@ func (a *Adapter) filterQuery(session *xorm.Session, filter Filter) *xorm.Sessio
448448
col string
449449
val []string
450450
}{
451-
{"p_type", filter.PType},
451+
{"ptype", filter.Ptype},
452452
{"v0", filter.V0},
453453
{"v1", filter.V1},
454454
{"v2", filter.V2},
@@ -501,7 +501,7 @@ func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [
501501
// UpdateFilteredPolicies deletes old rules and adds new rules.
502502
line := &CasbinRule{}
503503

504-
line.PType = ptype
504+
line.Ptype = ptype
505505
if fieldIndex <= 0 && 0 < fieldIndex+len(fieldValues) {
506506
line.V0 = fieldValues[0-fieldIndex]
507507
}
@@ -557,8 +557,8 @@ func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [
557557

558558
func (c *CasbinRule) toStringPolicy() []string {
559559
policy := make([]string, 0)
560-
if c.PType != "" {
561-
policy = append(policy, c.PType)
560+
if c.Ptype != "" {
561+
policy = append(policy, c.Ptype)
562562
}
563563
if c.V0 != "" {
564564
policy = append(policy, c.V0)
@@ -582,9 +582,9 @@ func (c *CasbinRule) toStringPolicy() []string {
582582
}
583583

584584
func (c *CasbinRule) queryString() (interface{}, []interface{}) {
585-
queryArgs := []interface{}{c.PType}
585+
queryArgs := []interface{}{c.Ptype}
586586

587-
queryStr := "p_type = ?"
587+
queryStr := "ptype = ?"
588588
if c.V0 != "" {
589589
queryStr += " and v0 = ?"
590590
queryArgs = append(queryArgs, c.V0)

0 commit comments

Comments
 (0)