Giter Club home page Giter Club logo

casbin-sqlx-adapter's Introduction

casbin-sqlx-adapter

sqlx adapter for Casbin https://github.com/casbin/casbin

Based on sqlx, and tested in MySQL.

Installation

go get github.com/memwey/casbin-sqlx-adapter

Usage example

opts := &AdapterOptions{
    DriverName: "mysql",
    DataSourceName: "root:1234@tcp(127.0.0.1:3306)/yourdb",
    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 {
    panic(err)
}

Notice

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.

Thank

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.

Others

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.

License

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

casbin-sqlx-adapter's People

Contributors

kjaebker avatar memwey avatar tobias-kuendig avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.