{"id":19298191,"url":"https://github.com/casbin/xorm-adapter","last_synced_at":"2025-10-07T12:29:59.828Z","repository":{"id":22630906,"uuid":"96882170","full_name":"casbin/xorm-adapter","owner":"casbin","description":"Xorm adapter for Casbin","archived":false,"fork":false,"pushed_at":"2024-04-09T02:47:45.000Z","size":98,"stargazers_count":383,"open_issues_count":1,"forks_count":60,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-14T22:04:15.739Z","etag":null,"topics":["access-control","adapter","authorization","casbin","orm","storage-driver","xorm"],"latest_commit_sha":null,"homepage":"https://github.com/casbin/casbin","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/casbin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"casbin"}},"created_at":"2017-07-11T10:38:28.000Z","updated_at":"2025-05-12T13:15:38.000Z","dependencies_parsed_at":"2024-04-14T01:01:42.263Z","dependency_job_id":"1774a91a-d1d7-44a0-a5b2-083294e52e44","html_url":"https://github.com/casbin/xorm-adapter","commit_stats":{"total_commits":71,"total_committers":26,"mean_commits":2.730769230769231,"dds":"0.45070422535211263","last_synced_commit":"634e6df8a2096c5dab7bc1d0e35ad8aed1b9c34e"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fxorm-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fxorm-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fxorm-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Fxorm-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casbin","download_url":"https://codeload.github.com/casbin/xorm-adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254439466,"owners_count":22071432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["access-control","adapter","authorization","casbin","orm","storage-driver","xorm"],"created_at":"2024-11-09T23:07:13.583Z","updated_at":"2025-10-07T12:29:54.789Z","avatar_url":"https://github.com/casbin.png","language":"Go","funding_links":["https://github.com/sponsors/casbin"],"categories":[],"sub_categories":[],"readme":"# Xorm Adapter\n\n[![Go](https://github.com/casbin/xorm-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/casbin/xorm-adapter/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/casbin/xorm-adapter/badge.svg?branch=master)](https://coveralls.io/github/casbin/xorm-adapter?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/casbin/xorm-adapter)](https://goreportcard.com/report/github.com/casbin/xorm-adapter)\n[![Godoc](https://godoc.org/github.com/casbin/xorm-adapter?status.svg)](https://godoc.org/github.com/casbin/xorm-adapter)\n\nXorm Adapter is the [Xorm](https://gitea.com/xorm/xorm) adapter for [Casbin](https://github.com/casbin/casbin). With this library, Casbin can load policy from Xorm supported database or save policy to it.\n\nBased on [Xorm Drivers Support](https://gitea.com/xorm/xorm#drivers-support), The current supported databases are:\n\n- Mysql: [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql)\n- MyMysql: [github.com/ziutek/mymysql](https://github.com/ziutek/mymysql/tree/master/godrv)\n- Postgres: [github.com/lib/pq](https://github.com/lib/pq)\n- Tidb: [github.com/pingcap/tidb](https://github.com/pingcap/tidb)\n- SQLite: [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)\n- MsSql: [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb)\n- Oracle: [github.com/mattn/go-oci8](https://github.com/mattn/go-oci8) (experiment)\n\n## Installation\n\n    go get github.com/casbin/xorm-adapter/v3\n\n## Simple MySQL Example\n\n```go\npackage main\n\nimport (\n\t\"github.com/casbin/casbin/v2\"\n\t_ \"github.com/go-sql-driver/mysql\"\n\n\t\"github.com/casbin/xorm-adapter/v3\"\n)\n\nfunc main() {\n\t// Initialize a Xorm adapter and use it in a Casbin enforcer:\n\t// The adapter will use the MySQL database named \"casbin\".\n\t// If it doesn't exist, the adapter will create it automatically.\n\ta, _ := xormadapter.NewAdapter(\"mysql\", \"mysql_username:mysql_password@tcp(127.0.0.1:3306)/\") // Your driver and data source. \n\n\t// Or you can use an existing DB \"abc\" like this:\n\t// The adapter will use the table named \"casbin_rule\".\n\t// If it doesn't exist, the adapter will create it automatically.\n\t// a := xormadapter.NewAdapter(\"mysql\", \"mysql_username:mysql_password@tcp(127.0.0.1:3306)/abc\", true)\n\n\te, _ := casbin.NewEnforcer(\"examples/rbac_model.conf\", a)\n\t\n\t// Load the policy from DB.\n\te.LoadPolicy()\n\t\n\t// Check the permission.\n\te.Enforce(\"alice\", \"data1\", \"read\")\n\t\n\t// Modify the policy.\n\t// e.AddPolicy(...)\n\t// e.RemovePolicy(...)\n\t\n\t// Save the policy back to DB.\n\te.SavePolicy()\n}\n```\n\n## Simple Postgres Example\n\n```go\npackage main\n\nimport (\n\t\"github.com/casbin/casbin/v2\"\n\t_ \"github.com/lib/pq\"\n\n\t\"github.com/casbin/xorm-adapter/v3\"\n)\n\nfunc main() {\n\t// Initialize a Xorm adapter and use it in a Casbin enforcer:\n\t// The adapter will use the Postgres database named \"casbin\".\n\t// If it doesn't exist, the adapter will create it automatically.\n\ta, _ := xormadapter.NewAdapter(\"postgres\", \"user=postgres_username password=postgres_password host=127.0.0.1 port=5432 sslmode=disable\") // Your driver and data source.\n\n\t// Or you can use an existing DB \"abc\" like this:\n\t// The adapter will use the table named \"casbin_rule\".\n\t// If it doesn't exist, the adapter will create it automatically.\n\t// a := xormadapter.NewAdapter(\"postgres\", \"dbname=abc user=postgres_username password=postgres_password host=127.0.0.1 port=5432 sslmode=disable\", true)\n\n\te, _ := casbin.NewEnforcer(\"../examples/rbac_model.conf\", a)\n\n\t// Load the policy from DB.\n\te.LoadPolicy()\n\n\t// Check the permission.\n\te.Enforce(\"alice\", \"data1\", \"read\")\n\n\t// Modify the policy.\n\t// e.AddPolicy(...)\n\t// e.RemovePolicy(...)\n\n\t// Save the policy back to DB.\n\te.SavePolicy()\n}\n```\n\n## Context Adapter\n\n`xormadapter` supports adapter with context, the following is a timeout control implemented using context\n\n```go\na, _ := xormadapter.NewAdapter(\"mysql\", \"mysql_username:mysql_password@tcp(127.0.0.1:3306)/\") // Your driver and data source. \n// Limited time 300s\nctx, cancel := context.WithTimeout(context.Background(), 300*time.Microsecond)\ndefer cancel()\nerr := a.AddPolicyCtx(ctx, \"p\", \"p\", []string{\"alice\", \"data1\", \"read\"})\nif err != nil {\n    panic(err)\n}\n```\n\n## Getting Help\n\n- [Casbin](https://github.com/casbin/casbin)\n\n## License\n\nThis project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasbin%2Fxorm-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasbin%2Fxorm-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasbin%2Fxorm-adapter/lists"}