{"id":15652080,"url":"https://github.com/cssxsh/mirai-hibernate-plugin","last_synced_at":"2025-04-14T07:08:15.982Z","repository":{"id":39332843,"uuid":"440886465","full_name":"cssxsh/mirai-hibernate-plugin","owner":"cssxsh","description":"Mirai Console Hibernate/ORM 数据库前置插件","archived":false,"fork":false,"pushed_at":"2024-09-11T06:07:39.000Z","size":773,"stargazers_count":32,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T07:08:09.812Z","etag":null,"topics":["hibernate","mirai","mirai-console","orm"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cssxsh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-12-22T14:34:04.000Z","updated_at":"2025-03-08T12:49:52.000Z","dependencies_parsed_at":"2024-01-23T06:26:15.139Z","dependency_job_id":"c6fc87ea-1d0a-4553-a4ca-5b1e64742b66","html_url":"https://github.com/cssxsh/mirai-hibernate-plugin","commit_stats":null,"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssxsh%2Fmirai-hibernate-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssxsh%2Fmirai-hibernate-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssxsh%2Fmirai-hibernate-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssxsh%2Fmirai-hibernate-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cssxsh","download_url":"https://codeload.github.com/cssxsh/mirai-hibernate-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837280,"owners_count":21169374,"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":["hibernate","mirai","mirai-console","orm"],"created_at":"2024-10-03T12:41:15.033Z","updated_at":"2025-04-14T07:08:15.950Z","avatar_url":"https://github.com/cssxsh.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Mirai Hibernate Plugin](https://github.com/cssxsh/mirai-hibernate-plugin)\n\n\u003e Mirai Hibernate 前置插件\n\n[Mirai Console](https://github.com/mamoe/mirai-console) 的前置插件，用于 Hibernate ORM 框架的初始化\n\n[![maven-central](https://img.shields.io/maven-central/v/xyz.cssxsh.mirai/mirai-hibernate-plugin)](https://search.maven.org/artifact/xyz.cssxsh.mirai/mirai-hibernate-plugin)\n[![Database Test](https://github.com/cssxsh/mirai-hibernate-plugin/actions/workflows/test.yml/badge.svg)](https://github.com/cssxsh/mirai-hibernate-plugin/actions/workflows/test.yml)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/f82572fd42324ce19df9d1639250127d)](https://www.codacy.com/gh/cssxsh/mirai-hibernate-plugin/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=cssxsh/mirai-hibernate-plugin\u0026amp;utm_campaign=Badge_Grade)\n\n插件自带聊天记录器 [MiraiHibernateRecorder](src/main/kotlin/xyz/cssxsh/mirai/hibernate/MiraiHibernateLoader.kt),  \n会记录 `群聊/私聊` 的内容到数据库方便其他插件使用，默认是 `h2database` 数据库(since `2.2.0+`)  \n\n每个插件都有应有独立的数据库配置在其配置文件目录 `config/.../hibernate.properties`  \n例如，聊天记录器数据库配置在 `config/xyz.cssxsh.mirai.plugin.mirai-hibernate-plugin/hibernate.properties`\n\n## 数据库支持\n\n本插件打包了以下版本的数据库驱动和连接池\n\n* `com.mysql:mysql-connector-j:9.0.0` - [mysql.hibernate.properties](example/mysql.hibernate.properties)\n* `org.mariadb.jdbc:mariadb-java-client:3.4.1` - [mariadb.hibernate.properties](example/mariadb.hibernate.properties)\n* `org.xerial:sqlite-jdbc:3.46.0.1` - [sqlite.hibernate.properties](example/sqlite.hibernate.properties)\n* `org.postgresql:postgresql:42.7.3` - [postgresql.hibernate.properties](example/postgresql.hibernate.properties)\n* `com.h2database:h2:2.3.230` - [h2.hibernate.properties](example/h2.hibernate.properties)\n* `com.microsoft.sqlserver:mssql-jdbc:12.8.0.jre11` - [sqlserver.hibernate.properties](example/sqlserver.hibernate.properties)\n* `com.zaxxer:HikariCP:5.0.1`\n\n需要其他数据库驱动或连接池支持，请添加 `plugin-shared-libraries` 依赖，有2种方法\n\n1.  将 **Jar包** 放到 `plugin-shared-libraries` 目录中一同被 `mirai-console` 加载\n\n2.  在 `plugin-shared-libraries/libraries.txt` 中添加 maven 引用，  \n    例如 `com.oracle.database.jdbc:ojdbc11:21.8.0.0`\n\n## 在 Mirai Console Plugin 项目中引用\n\n```kotlin\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    compileOnly(\"xyz.cssxsh.mirai:mirai-hibernate-plugin:${version}\")\n}\n\n// hibernate 6 和 HikariCP 5 需要 jdk11\nmirai {\n    jvmTarget = JavaVersion.VERSION_11\n}\n```\n\n## 在 Mirai Core Jvm 项目中引用\n\n```kotlin\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"xyz.cssxsh.mirai:mirai-hibernate-plugin:${version}\")\n}\n```\n需要手动对 `xyz.cssxsh.mirai.hibernate.factory` 进行初始化，和对 `MiraiHibernateRecorder` 进行注册\n\n**Maven 项目请根据上面的 maven-central 指向的链接查询相关配置方法**\n\n## 在 mirai-api-http 中引用\n\n使用本插件作为 mirai-api-http 的消息源需要额外的拓展插件 \u003chttps://github.com/cssxsh/mirai-hibernate-http\u003e \n\n## 一些方法和类说明\n\n*   [MiraiHibernateConfiguration](src/main/kotlin/xyz/cssxsh/mirai/hibernate/MiraiHibernateConfiguration.kt)\n    配置的，对应于 `JvmPlugin` 的 `SessionFactory`  \n    默认将会读取(生成)在 `config` 目录下的 `hibernate.properties` 作为配置文件  \n    并且自动扫描加载当前插件的 `entry` 类包中被 `jakarta.persistence.Entity` 标记的实体类\n\n*   [MiraiHibernateRecorder](src/main/kotlin/xyz/cssxsh/mirai/hibernate/MiraiHibernateRecorder.kt)  \n    是本插件自带的消息记录器，通过对 `MessageEvent` 和 `MessagePostSendEvent` 记录，保存消息历史到数据库\n\n*   [CriteriaBuilder.rand](src/main/kotlin/xyz/cssxsh/hibernate/Criteria.kt)  \n    `MiraiHibernateConfiguration` 中会对 Sqlite / PostgreSql 的 `random` 进行别名注册为 `rand` 统一SQL语句的中的随机函数名\n\n*   [CriteriaBuilder.dice](src/main/kotlin/xyz/cssxsh/hibernate/Criteria.kt)  \n    `MiraiHibernateConfiguration` 中会注册名为 `dice` 的宏，用于随机取行\n\n### 示例代码\n\n*   [kotlin](src/test/kotlin/xyz/cssxsh/mirai/test/MiraiHibernatePluginTest.kt)\n*   [java](src/test/java/xyz/cssxsh/mirai/test/MiraiHibernateDemo.java)\n\n## 安装\n\n### MCL 指令安装\n\n**请确认 mcl.jar 的版本是 2.1.0+**  \n`./mcl --update-package xyz.cssxsh.mirai:mirai-hibernate-plugin --channel maven-stable --type plugins`\n\n### 手动安装\n\n1.  从 [Releases](https://github.com/cssxsh/mirai-hibernate-plugin/releases) 或者 [Maven](https://repo1.maven.org/maven2/xyz/cssxsh/mirai/mirai-hibernate-plugin/) 下载 `mirai2.jar`\n2.  将其放入 `plugins` 文件夹中\n\n### 聊天数据迁移\n\n1.  将原 `config/xyz.cssxsh.mirai.plugin.mirai-hibernate-plugin/hibernate.properties` 改名备份为 `hibernate.backup.properties`\n2.  按照 [example](example) 中的例子写一份新的 `hibernate.properties`\n3.  重启 `mirai-console`\n\n## [爱发电](https://afdian.net/@cssxsh)\n\n![afdian](.github/afdian.jpg)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcssxsh%2Fmirai-hibernate-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcssxsh%2Fmirai-hibernate-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcssxsh%2Fmirai-hibernate-plugin/lists"}