func (a *Adapter) SavePolicy(model model.Model) error {
	a.dropTable()
	a.createTable()
	var lines []CasbinRule
	for ptype, assertion := range model["p"] {
		for _, rule := range assertion.Policy {
			line := savePolicyLine(ptype, rule)
			lines = append(lines, line)
		}
	}
	for ptype, assertion := range model["g"] {
		for _, rule := range assertion.Policy {
			line := savePolicyLine(ptype, rule)
			lines = append(lines, line)
		}
	}
	err := a.writeLines(lines)
	return err
}
SavePolicy saves policy to RQLite database.
package rqliteadapter
import (
	"fmt"
	"github.com/casbin/casbin/model"
	"github.com/casbin/casbin/persist"
	"github.com/raindog308/gorqlite"
	"runtime"
)
var tableName = "rules"
type CasbinRule struct {
	PType, V0, V1, V2, V3, V4, V5 string
}
type Adapter struct {
	url  string
	conn *gorqlite.Connection
}
func finalizer(a *Adapter) {
	a.conn.Close()
}
func NewAdapter(url string) *Adapter {
	a := &Adapter{}
	a.url = url
	a.open()
	runtime.SetFinalizer(a, finalizer)
	return a
}
func (a *Adapter) open() {
	conn, err := gorqlite.Open(a.url)
	if err != nil {
		panic(err)
	}
	a.conn = &conn
	a.createTable()
}
func (a *Adapter) close() {
	a.conn.Close()
}
func (a *Adapter) createTable() {
	stmt := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (p_type TEXT NULL, v0 TEXT NULL, v1 TEXT NULL, v2 TEXT NULL, v3 TEXT NULL, v4 TEXT NULL, v5 TEXT NULL, PRIMARY KEY(p_type, v0, v1, v2, v3, v4, v5))", tableName)
	a.conn.WriteOne(stmt)
}
func (a *Adapter) dropTable() {
	stmt := fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName)
	a.conn.WriteOne(stmt)
}
func loadPolicyLine(line CasbinRule, model model.Model) {
	lineText := line.PType
	if line.V0 != "" {
		lineText += ", " + line.V0
	}
	if line.V1 != "" {
		lineText += ", " + line.V1
	}
	if line.V2 != "" {
		lineText += ", " + line.V2
	}
	if line.V3 != "" {
		lineText += ", " + line.V3
	}
	if line.V4 != "" {
		lineText += ", " + line.V4
	}
	if line.V5 != "" {
		lineText += ", " + line.V5
	}
	persist.LoadPolicyLine(lineText, model)
}
func (a *Adapter) LoadPolicy(model model.Model) error {
	var err error
	var result gorqlite.QueryResult
	result, err = a.conn.QueryOne(fmt.Sprintf("SELECT * FROM %s", tableName))
	if err != nil {
		return err
	}
	for result.Next() {
		var line CasbinRule
		err = result.Scan(&line)
		loadPolicyLine(line, model)
	}
	return nil
}
func savePolicyLine(ptype string, rule []string) CasbinRule {
	line := CasbinRule{}
	line.PType = ptype
	if len(rule) > 0 {
		line.V0 = rule[0]
	}
	if len(rule) > 1 {
		line.V1 = rule[1]
	}
	if len(rule) > 2 {
		line.V2 = rule[2]
	}
	if len(rule) > 3 {
		line.V3 = rule[3]
	}
	if len(rule) > 4 {
		line.V4 = rule[4]
	}
	if len(rule) > 5 {
		line.V5 = rule[5]
	}
	return line
}