// SavePolicy saves policy to database.
SavePolicy saves policy to database.
// SavePolicy saves policy to database .
func (a *adapter) SavePolicy(model model.Model) error {
	if a.filtered {
		return errors.New("cannot save a filtered policy")
	}
	if err := a.dropTable(); err != nil {
		return err
	}
	var lines []interface{}
	for ptype, ast := range model["p"] {
		for _, rule := range ast.Policy {
			line := savePolicyLine(ptype, rule)
			lines = append(lines, &line)
		}
	}
	for ptype, ast := range model["g"] {
		for _, rule := range ast.Policy {
			line := savePolicyLine(ptype, rule)
			lines = append(lines, &line)
		}
	}
	ctx, cancle := context.WithTimeout(context.TODO(), a.timeout)
	defer cancle()
	if _, err := a.collection.InsertMany(ctx, lines); err != nil {
		return err
	}
	return nil
}
func ( a * adapter ) SavePolicy ( model model . Model ) error { if a . filtered { return errors . New ( " " ) } if err := a . dropTable ( ) ; err != nil { return err } var lines [ ] interface { } for ptype , ast := range model [ " " ] { for _ , rule := range ast . Policy { line := savePolicyLine ( ptype , rule ) lines = append ( lines , & line ) } } for ptype , ast := range model [ " " ] { for _ , rule := range ast . Policy { line := savePolicyLine ( ptype , rule ) lines = append ( lines , & line ) } } ctx , cancle := context . WithTimeout ( context . TODO ( ) , a . timeout ) defer cancle ( ) if _ , err := a . collection . InsertMany ( ctx , lines ) ; err != nil { return err } return nil }
SavePolicy saves policy to database.
SavePolicy saves policy to database .