{"id":24130453,"url":"https://github.com/babyblue94520/hi-sql","last_synced_at":"2025-09-18T23:32:47.966Z","repository":{"id":50681962,"uuid":"358210235","full_name":"babyblue94520/hi-sql","owner":"babyblue94520","description":"Use SQL like Spring Data JPA","archived":false,"fork":false,"pushed_at":"2025-08-28T08:19:04.000Z","size":1481,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-28T15:33:58.819Z","etag":null,"topics":["hi-sql","jpa","orm","spring-data-jpa","sql"],"latest_commit_sha":null,"homepage":"","language":"Java","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/babyblue94520.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,"zenodo":null}},"created_at":"2021-04-15T09:58:20.000Z","updated_at":"2025-03-26T08:51:39.000Z","dependencies_parsed_at":"2025-07-18T08:15:30.221Z","dependency_job_id":"31778e07-5d18-4869-86ea-93bd399f7165","html_url":"https://github.com/babyblue94520/hi-sql","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/babyblue94520/hi-sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babyblue94520%2Fhi-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babyblue94520%2Fhi-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babyblue94520%2Fhi-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babyblue94520%2Fhi-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babyblue94520","download_url":"https://codeload.github.com/babyblue94520/hi-sql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babyblue94520%2Fhi-sql/sbom","scorecard":{"id":222423,"data":{"date":"2025-08-11","repo":{"name":"github.com/babyblue94520/hi-sql","commit":"d22ca75c81efc2ebf99512d7f7f4ad3db6802d17"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'","Warn: branch protection not enabled for branch 'release/1.3.6'","Warn: branch protection not enabled for branch 'release/1.3.5'","Warn: branch protection not enabled for branch 'release/1.3.3'","Warn: branch protection not enabled for branch 'release/1.3.2'","Warn: branch protection not enabled for branch 'release/1.3.1'","Warn: branch protection not enabled for branch 'release/1.3.0'","Warn: branch protection not enabled for branch '1.0.0'","Warn: branch protection not enabled for branch '0.0.6'","Warn: branch protection not enabled for branch '0.0.4'","Warn: branch protection not enabled for branch '0.0.3'","Warn: branch protection not enabled for branch '0.0.1'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"10 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-36p3-wjmg-h94x","Warn: Project is vulnerable to: GHSA-hh26-6xwr-ggv7","Warn: Project is vulnerable to: GHSA-4gc7-5j7h-4qph","Warn: Project is vulnerable to: GHSA-4wp7-92pw-q264","Warn: Project is vulnerable to: GHSA-g5mm-vmx4-3rg7","Warn: Project is vulnerable to: GHSA-6gf2-pvqw-37ph","Warn: Project is vulnerable to: GHSA-558x-2xjg-6232","Warn: Project is vulnerable to: GHSA-564r-hj7v-mcr5","Warn: Project is vulnerable to: GHSA-9cmq-m9j5-mvww","Warn: Project is vulnerable to: GHSA-wxqc-pxw9-g2p8"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T02:54:20.658Z","repository_id":50681962,"created_at":"2025-08-17T02:54:20.658Z","updated_at":"2025-08-17T02:54:20.658Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275852243,"owners_count":25540136,"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","status":"online","status_checked_at":"2025-09-18T02:00:09.552Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["hi-sql","jpa","orm","spring-data-jpa","sql"],"created_at":"2025-01-11T20:33:57.583Z","updated_at":"2025-09-18T23:32:47.923Z","avatar_url":"https://github.com/babyblue94520.png","language":"Java","readme":"# Hi SQL\n\n[中文](README.zh-TW.md)\n\n## Overview\n\n![](images/orm.png)\n![](images/write_sql.png)\n\nA simple and highly flexible pure __SQL__ library.\n\nThere are many __ORM Frameworks__ available, and different projects may use different __ORMs__. When using them, you\nneed to design __SQL__ based on requirements, convert it into the corresponding __ORM__ syntax, and ensure that the _\n_ORM__ generates the expected __SQL__. Special __SQL__ cases require extra effort to convert to __ORM__ syntax, and some\nneed adjustments based on the database being used. The pros and cons of __ORMs__ are well known, so they won't be\ndiscussed further here.\n\n## Requirements\n\n* Spring Framework 5+\n* Java 11+\n\n## Features\n\n* Primarily __Native SQL__\n* High performance\n* Provides basic parameterized queries and dynamic __SQL__ substitution\n* Maps query results to any __Java__ object\n* Supports __Spring @Transactional__\n\n## Quick Start\n\n### Configuration\n\nBy default, it scans all __Interfaces__ annotated with __@Repository__ within the same __Package__.\n\n[HiSqlConfig.java](src/test/java/pers/clare/hisql/data/HiSqlConfig.java)\n\n```java\n\n@EnableHiSql\npublic class HiSqlConfig {\n\n}\n```\n\n### Create Entity and Interface\n\n* __SQLCrudRepository__\n\n  Extend __SQLCrudRepository__ to get basic INSERT, UPDATE, DELETE, and SELECT functionalities for an __Entity__.\n\n  [User.java](src/test/java/pers/clare/hisql/data/entity/User.java)\n\n  [UserRepository.java](src/test/java/pers/clare/hisql/data/repository/UserRepository.java)\n\n  ```java\n  @Repository\n  public interface UserRepository extends SQLCrudRepository\u003cUser, Long\u003e {\n  \n  }\n  ```\n\n* __SQLRepository__\n\n  Extend __SQLRepository__ to create a lightweight __Repository__.\n\n### Usage\n\n```java\n\n@Service\npublic class UserService {\n\n    private UserRepository userRepository;\n\n    public User find(Long id) {\n        if (id == null) return null;\n        return userRepository.findById(id);\n    }\n\n}\n```\n\n## Features\n\n* Parameterization\n\n    * Standard parameters\n\n      ```java\n      @Repository\n      public interface DemoRepository extends SQLRepository {\n      \n        @HiSql(\"select * from test where value=:value\")\n        List\u003cObject\u003e findAll(String value);\n      }\n      ```\n\n    * Object parameters\n\n      Converts an object into parameters like __id__, __obj.id__, __name__, __obj.name__. If duplicate parameter names\n      exist, they are overwritten in order.\n\n      ```java\n      import lombok.Getter;\n      import lombok.Setter;     \n      \n      @Getter\n      @Setter\n      public class ValueObject{\n          private Integer id;\n      \n          private String name;\n      }\n      \n      @Repository\n      public interface DemoRepository extends SQLRepository {\n      \n        @HiSql(\"\"\"\n              select *\n              from test\n              where name=:obj.name\n              limit 1\n          \"\"\")\n        ValueObject findAll(ValueObject obj);\n      \n        @HiSql(\"select * from test where name=:obj.name\")\n        List\u003cValueObject\u003e findAll(ValueObject obj);\n      \n        @HiSql(\"select * from test where name=:name\")\n        List\u003cValueObject\u003e findAll2(ValueObject obj);\n      \n      }\n      ```\n\n* Dynamic __SQL__ Substitution\n\n  Use this method when dynamically adding conditions or replacing __SQL__ strings.\n\n  Avoid manual __SQL__ concatenation externally to prevent __SQL Injection__. Follow the example below.\n\n  ```java\n  @Repository\n  public interface DemoRepository extends SQLRepository {\n    \n      @HiSql(\"select * from test where 1=1 {valueCondition}\")\n      List\u003cMap\u003cString,Object\u003e\u003e findAll(String valueCondition, String value);\n      \n      @HiSql(\"select * from test where 1=1 {value}\")\n      List\u003cMap\u003cString,Object\u003e\u003e findAll(SqlReplace\u003cObject\u003e value);\n  }\n    \n  @Service\n  public class DemoService {\n      private DemoRepository demoRepository;\n        \n      public void findAll(String value){\n          // Simple string substitution\n          demoRepository.findAll(\"and column = :value\", value);\n          // Using SqlReplace, if value is null, it is replaced with blank, otherwise, it is substituted along with the value parameter\n          demoRepository.findAll(SqlReplace.of(value,\" and column = :value\"));\n      }\n  }\n  ```\n\n* Read __SQL__ from __XML__\n\n    * The default root directory is __resources/hisql/__, where an __XML__ file with the same name as the __Class__\n      should be created.\n\n      Example: `resources/hisql/CustomRepository.xml`\n\n    * Create a __Tag__ with the same name as the **Method Name** or use __@HiSql(name=...)__ to specify a __Tag__.\n\n        ```xml\n        \u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n        \u003c!DOCTYPE SQL\u003e\n        \u003cSQL\u003e\n            \u003cfindAll\u003e\u003c![CDATA[\n                select * from user where 1=1 {id} and :id is not null\n            ]]\u003e\u003c/findAll\u003e\n        \u003c/SQL\u003e\n        ```\n\n* More examples in tests\n\n  [CustomRepository.java](src/test/java/pers/clare/hisql/data/repository/CustomRepository.java)\n\n## Advanced\n\n* ### Pagination Optimization\n\n  Use an initially calculated total or an estimated value to avoid repeatedly calculating the total when paginating. If\n  precise totals are required, this method is not recommended.\n\n    ```java\n    Pagination pagination = Pagination.of(0,20);\n    Page page = repository.page(pagination);\n\n    pagination = Pagination.of(page.getPage() + 1, page.getSize(), page.getTotal());\n    repository.page(pagination);\n    ```\n\n* ### Virtual Total Count\n\n  In pagination mode, using __select count(*)__ to query the total count can be very slow. Estimating the total count\n  avoids scanning the entire result set.\n\n  ### Usage\n\n    ```java\n    pagination.setVirtualTotal(true);\n    ```\n\n  ### Implementation\n\n    * MySQL\n\n      Replace the actual count (*) with the explain result \"rows\".\n\n        ```java\n        @Override\n        public long getVirtualTotal(\n                Pagination pagination\n                , Connection connection\n                , String sql\n                , Object[] parameters\n        ) throws SQLException {\n            String totalSql = \"explain select count(*) from(\" + sql + \")t\";\n            ResultSet rs = ConnectionUtil.query(connection, totalSql, parameters);\n            if (rs.next()) {\n                return rs.getLong(\"rows\");\n            } else {\n                throw new HiSqlException(String.format(\"query total error.(%s)\", totalSql));\n            }\n        }\n        ```\n\n* ### Modifying __PaginationMode__\n\n  ### Configuration\n\n    ```java\n    @EnableHiSql(\n        paginationMode = MySQLPaginationMode.class\n    )\n    public class Demo2HiSqlConfig {\n    }\n    ```\n\n  ### Custom Implementation\n\n    ```java\n    public class CustomPaginationMode implements PaginationMode {\n\n        public void appendPaginationSQL(\n                StringBuilder sql\n                , Pagination pagination\n        ) {\n            appendSortSQL(sql, pagination.getSorts());\n            sql.append(\" limit \")\n                    .append(pagination.getSize() * pagination.getPage())\n                    .append(',')\n                    .append(pagination.getSize());\n        }\n\n        @Override\n        public long getVirtualTotal(\n                Pagination pagination\n                , Connection connection\n                , String sql\n                , Object[] parameters\n        ) throws SQLException {\n            // TODO\n        }\n    }\n    ```\n\n* ### Modifying NamingStrategy\n\n  ### Configuration\n\n    ```java\n    @EnableHiSql(\n        naming = UpperCaseNamingStrategy.class\n    )\n    public class Demo2HiSqlConfig {\n    }\n    ```\n\n  ### Custom Implementation\n\n    ```java\n    public class CustomNamingStrategy implements NamingStrategy{\n    }\n\n    @EnableHiSql(\n        naming = CustomNamingStrategy.class\n    )\n    public class Demo2HiSqlConfig {\n    }\n    ```\n\n* ### Custom ResultSetConverter\n\n  Converts ResultSet Value to the target special type.\n\n  ### Custom Implementation\n\n    ```java\n    public class CustomResultSetConverter extends ResultSetConverter {\n        {\n            register(Pattern.class, (rs, i) -\u003e Pattern.compile(rs.getString(i)));\n        }\n    }\n    ```\n\n  ### Configuration\n\n    ```java\n    @EnableHiSql(\n            resultSetConverter = CustomResultSetConverter.class\n    )\n    public class HiSqlConfig {\n    }\n    ```\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabyblue94520%2Fhi-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabyblue94520%2Fhi-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabyblue94520%2Fhi-sql/lists"}