{"id":26022849,"url":"https://github.com/junnishimura/casbin-bun-adapter","last_synced_at":"2025-09-07T02:10:05.790Z","repository":{"id":230683273,"uuid":"776462239","full_name":"JunNishimura/casbin-bun-adapter","owner":"JunNishimura","description":"Bun ORM adapter for Casbin","archived":false,"fork":false,"pushed_at":"2024-06-17T01:25:57.000Z","size":128,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-20T20:32:09.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JunNishimura.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,"publiccode":null,"codemeta":null}},"created_at":"2024-03-23T15:22:19.000Z","updated_at":"2024-06-16T00:11:23.000Z","dependencies_parsed_at":"2024-06-20T20:02:30.521Z","dependency_job_id":"112aae4b-c3e6-433a-a0e5-6cf3d58e156a","html_url":"https://github.com/JunNishimura/casbin-bun-adapter","commit_stats":null,"previous_names":["junnishimura/casbin-bun-adapter"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JunNishimura%2Fcasbin-bun-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JunNishimura%2Fcasbin-bun-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JunNishimura%2Fcasbin-bun-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JunNishimura%2Fcasbin-bun-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JunNishimura","download_url":"https://codeload.github.com/JunNishimura/casbin-bun-adapter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242194257,"owners_count":20087541,"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":[],"created_at":"2025-03-06T10:37:11.295Z","updated_at":"2025-03-06T10:37:11.792Z","avatar_url":"https://github.com/JunNishimura.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Casbin Bun Adapter\n\u003cp align='left'\u003e\n  \u003cimg alt=\"GitHub release (latest by date)\" src=\"https://img.shields.io/github/v/release/JunNishimura/casbin-bun-adapter\"\u003e\n  \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/JunNishimura/casbin-bun-adapter\"\u003e\n  \u003ca href=\"https://github.com/JunNishimura/casbin-bun-adapter/actions/workflows/test.yml\"\u003e\u003cimg src=\"https://github.com/JunNishimura/casbin-bun-adapter/actions/workflows/test.yml/badge.svg\" alt=\"test\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://goreportcard.com/report/github.com/JunNishimura/casbin-bun-adapter\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/JunNishimura/casbin-bun-adapter\" alt=\"Go Report Card\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## 📖 Overview\ncasbin-bun-adapter is the [Bun](https://bun.uptrace.dev/) ORM adapter for [Casbin](https://casbin.org/).\n\n## 🙌 Supported DB \nThe following databases supported by Bun are also supported by this adapter\n1. MySQL\n2. PostgreSQL\n3. Microsoft SQL Server\n4. SQLite\n\n## 💻 Installation \n```\ngo get github.com/JunNishimura/casbin-bun-adapter\n```\n\n## 👀 Example\n```go\npackage main\n\nimport (\n\tcasbinbunadapter \"github.com/JunNishimura/casbin-bun-adapter\"\n\t\"github.com/casbin/casbin/v2\"\n)\n\nfunc main() {\n\t// initialize a Bun adapter and use it in a Casbin enforcer\n\ta, _ := casbinbunadapter.NewAdapter(\"mysql\", \"mysql_username:mysql_password@tcp(127.0.0.1:3306)/database\")\n\te, _ := casbin.NewEnforcer(\"model.conf\", a)\n\n\t// load the policy from DB.\n\t_ = e.LoadPolicy()\n\n\t// check the permission.\n\t_, _ = e.Enforce(\"alice\", \"data1\", \"read\")\n\n\t// modify the policy\n\t// e.AddPolicy(...)\n\t// e.RemovePolicy(...)\n\t// e.UpdatePolicy(...)\n\n\t// save the policy back to DB.\n\t_ = e.SavePolicy()\n}\n```\n\n## 😢 Limitations\ncasbin-bun-adapter has following limitations.\n### 1. Table names cannot be freely specified\nTo specify the table name in Bun, you need to specify it in a structure tag or call the ModelTableExpr method in the query builder.\n```go\ntype User struct {\n  bun.BaseModel `bun:\"table:users,alias:u\"`\n  ID    int64  `bun:\"id,pk,autoincrement\"`\n  Name  string `bun:\"name,notnull\"`\n}\n```\n\n```go\nres, err := db.NewInsert().\n    Model(user).\n    ModelTableExpr(\"custom_name\") // specify table name\n    Exec(ctx)\n```\nIf you want to create a table with a name specified by the user, you can use ModelTableExpr, but I gave up using ModelTableExpr because I found that query build to tuncate table does not support ModelTableExpr.\n\nIf we come up with a better approach, or if Bun's specifications regarding the above change, we will modify this one accordingly.\n\n### 2. Unique indexes cannot be added on columns in the casbin_policies table\nFor Postgres, you can specify `IF NOT EXISTS` to create a key only when the key does not exist, but other DBs do not support the above syntax by default.\n\nThere seems to be no way to check if the index is posted in Bun.\n\nIf I find the way to check if the index exists with SQL, it might be possible to achieve this, so I'll leave this as a future issue.\n\n## 🙇‍♂️ Thanks\nI would like to express my appreciation to [Gorm Adapter](https://github.com/casbin/gorm-adapter), since casbin-bun-adapter is implemented in a way that fits the Bun ORM based on it.\n\n## 🪧 License\ncasbin-bun-adapter is released under [MIT License](https://github.com/JunNishimura/casbin-bun-adapter/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunnishimura%2Fcasbin-bun-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunnishimura%2Fcasbin-bun-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunnishimura%2Fcasbin-bun-adapter/lists"}