{"id":13804675,"url":"https://github.com/huntlabs/hunt-entity","last_synced_at":"2025-05-05T13:32:38.200Z","repository":{"id":96141747,"uuid":"62301006","full_name":"huntlabs/hunt-entity","owner":"huntlabs","description":"An object-relational mapping (ORM) framework for D language (Similar to JPA / Doctrine),  support PostgreSQL and MySQL.","archived":false,"fork":false,"pushed_at":"2022-07-22T09:57:30.000Z","size":755,"stargazers_count":58,"open_issues_count":7,"forks_count":11,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-08T23:41:55.558Z","etag":null,"topics":["database","dlang","entity","hibernate","jpa","mysql","orm","postgresql","sqlite"],"latest_commit_sha":null,"homepage":"https://www.huntlabs.net","language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huntlabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-06-30T10:08:17.000Z","updated_at":"2025-03-27T16:35:46.000Z","dependencies_parsed_at":"2023-04-25T13:01:44.136Z","dependency_job_id":null,"html_url":"https://github.com/huntlabs/hunt-entity","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huntlabs%2Fhunt-entity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huntlabs%2Fhunt-entity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huntlabs%2Fhunt-entity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huntlabs%2Fhunt-entity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huntlabs","download_url":"https://codeload.github.com/huntlabs/hunt-entity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250808072,"owners_count":21490615,"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":["database","dlang","entity","hibernate","jpa","mysql","orm","postgresql","sqlite"],"created_at":"2024-08-04T01:00:52.404Z","updated_at":"2025-05-05T13:32:37.899Z","avatar_url":"https://github.com/huntlabs.png","language":"D","readme":"[![Build Status](https://travis-ci.org/huntlabs/hunt-entity.svg?branch=master)](https://travis-ci.org/huntlabs/hunt-entity)\n\n## hunt-entity\n[Hunt-entity](https://github.com/huntlabs/hunt-entity) is an object-relational mapping tool for the D programming language. Referring to the design idea of [JPA](https://en.wikipedia.org/wiki/Java_Persistence_API).\n\n## Support databases\n * PostgreSQL 9.0+\n * MySQL 5.1+\n * SQLite 3.7.11+\n \n## Depends\n * [hunt-database](https://github.com/huntlabs/hunt-database)\n * [hunt-sql](https://github.com/huntlabs/hunt-sql)\n\n## Simple code\n```D\nimport hunt.entity;\n\n@Table(\"user\")\nclass User\n{\n    mixin MakeModel;\n\n    @PrimaryKey\n    @AutoIncrement\n    int id;\n\n    string name;\n    double money;\n    string email;\n    bool status;\n}\n\nvoid main()\n{\n    auto option = new EntityOption;\n\n    option.database.driver = \"mysql\";\n    option.database.host = \"localhost\";\n    option.database.port = 3306;\n    option.database.database = \"test\";\n    option.database.username = \"root\";\n    option.database.password = \"123456\";\n    option.database.charset = \"utf8mb4\";\n    option.database.prefix = \"hunt_\";\n\n    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(\"default\", option);\n    EntityManager em = entityManagerFactory.createEntityManager();\n\n    // begin transaction\n    em.getTransaction().begin();\n\n    // define your database existing row id in here\n    int id = 10;\n\n    auto user = em.find!User(id);\n    log(\"User name is: \", user.name);\n\n    // commit transaction\n    em.getTransaction().commit();\n\n    em.close();\n    entityManagerFactory.close();\n}\n```\n\n## Insert row\n```D\n    auto user = new User();\n    user.name = \"Brian\";\n    user.email = \"brian@huntlabs.cn\";\n    user.money = 99.9;\n    \n    // insert user\n    em.persist(user);\n    log(\"User id is: \", user.id);\n```\n\n## Delete row\n```D\n    int n = em.remove!User(id);\n    log(\"The number of users deleted is: \", n);\n```\n\n## Update row\n```D\n    auto user = em.find!User(id);\n    log(\"User name is: \", user.name);\n    user.name = \"zoujiaqing\";\n    em.merge!User(user);\n    log(\"The number of users updated is: \", n);\n```\n\n## Use CriteriaQuery to find\n```D\n    // create CriteriaBuilder object from em\n    CriteriaBuilder builder = em.getCriteriaBuilder();\n\n    CriteriaQuery!User criteriaQuery = builder.createQuery!User;\n    Root!User root = criteriaQuery.from();\n    Predicate p1 = builder.equal(root.User.id, id);\n    TypedQuery!User typedQuery = em.createQuery(criteriaQuery.select(root).where(p1));\n\n    auto user = typedQuery.getSingleResult();\n\n    log(\"User name is: \", user.name);\n```\n\n## Use CriteriaQuery to Multi-condition find\n```D\n    // create CriteriaBuilder object from em\n    CriteriaBuilder builder = em.getCriteriaBuilder();\n\n    CriteriaQuery!User criteriaQuery = builder.createQuery!User;\n    Root!User root = criteriaQuery.from();\n\n    Predicate p1 = builder.lt(root.User.id, 1000);  // User id is less than 1000.\n    Predicate p2 = builder.gt(root.User.money, 0);  // User money is greater than 0.\n    Predicate p3 = builder.like(root.User.name, \"z%\");  // User name prefix is z.\n\n    TypedQuery!User typedQuery = em.createQuery(criteriaQuery.select(root).where(builder.and(p1, p2), p3));\n    User[] users = typedQuery.getResultList();\n\n    log(\"The number of users found is: \", users.length);\n```\n\n## Avaliable Versions\n| Identifier | Description | \n|--------|--------|\n| HUNT_SQL_DEBUG |  Used to log debugging messages about SQL handling|\n| HUNT_SQL_DEBUG_MORE |  Used to log more debugging messages about SQL handling|","funding_links":[],"categories":["Database clients"],"sub_categories":["XML"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuntlabs%2Fhunt-entity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuntlabs%2Fhunt-entity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuntlabs%2Fhunt-entity/lists"}