Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


sqlx adapter for Casbin

Based on sqlx, and tested in MySQL.


go get

Usage example

opts := &AdapterOptions{
    DriverName: "mysql",
    DataSourceName: "root:1234@tcp(",
    TableName: "casbin_rule",
    // or reuse an existing connection:
    // DB: myDBConn,

a := NewAdapterFromOptions(opts)
// Casbin v2 may return an error
e, err := casbin.NewEnforcer("examples/rbac_model.conf", a)
if err != nil {


The v2 version of Casbin has some break change, check for the detail. If you are still using v1 version, use 0.1.x of this project.

The implement is kind of different from the official one. In this implement you should create the database and table on your own.

In my opinion, in a general PRODUCTION environment, the business code can rarely create a database, create a table or drop a table.

The filtered adapter feature has been added in some adapter implements such as Xorm Adapter. However, it's not yet documented in the doc. I will add it after it's documented. See this issue.


Special thanks to Casbin. They provide a superb authorization library.

Special thanks to sqlx. It provides a brilliant set of extensions on go's standard database/sql library.

And this project is inspected by Xorm Adapter, Gorm Adapter, Beego ORM Adapter and MySQL adapter . Thanks all of them.


This is a very first opensource of me and if this project violates any of the opensource guidelines, please contact me. The project is far from perfect, issues and pull requesets are very welcome.


This project is under Apache 2.0 License. See the LICENSE file for the full license text.