|
3 | 3 | [](https://github.com/ydb-platform/ydb-java-dialects/actions/workflows/ci-jooq-dialect.yaml)
|
4 | 4 |
|
5 | 5 | # YDB JOOQ Dialect
|
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +This project introduces a JOOQ dialect specifically tailored for the Yandex Database (YDB). JOOQ, a popular Java-based ORM tool for SQL-centric database interaction, is now equipped to leverage the unique capabilities of YDB, enabling developers to maintain a high level of type safety and SQL abstraction. |
| 10 | + |
| 11 | +### Features |
| 12 | + |
| 13 | +- Full support for all YDB data types during code generation |
| 14 | +- Preserves the original file structure in generated code |
| 15 | +- Advanced type safety features aligning with YDB's data types |
| 16 | +- Support for YDB-specific SQL syntax and operations *(coming soon)* |
| 17 | + |
| 18 | +## Getting Started |
| 19 | + |
| 20 | +### Requirements |
| 21 | + |
| 22 | +To utilize this JOOQ YDB Dialect, ensure you have: |
| 23 | + |
| 24 | +- Java 11 or above. |
| 25 | +- JOOQ 3.15 or higher. |
| 26 | +- [YDB JDBC Driver](https://github.com/ydb-platform/ydb-jdbc-driver) |
| 27 | +- Access to a YDB Database instance. |
| 28 | + |
| 29 | +### Installation |
| 30 | + |
| 31 | +For Maven, add the following dependencies to your pom.xml: |
| 32 | + |
| 33 | +```xml |
| 34 | +<dependency> |
| 35 | + <groupId>org.jooq</groupId> |
| 36 | + <artifactId>jooq</artifactId> |
| 37 | + <version>${jooq.version}</version> |
| 38 | +</dependency> |
| 39 | + |
| 40 | +<dependency> |
| 41 | + <groupId>tech.ydb.jdbc</groupId> |
| 42 | + <artifactId>ydb-jdbc-driver</artifactId> |
| 43 | + <version>${ydb.jdbc.version}</version> |
| 44 | +</dependency> |
| 45 | + |
| 46 | +<dependency> |
| 47 | + <groupId>tech.ydb.dialects</groupId> |
| 48 | + <artifactId>jooq-ydb-dialect</artifactId> |
| 49 | + <version>${jooq.ydb.dialect.version}</version> |
| 50 | +</dependency> |
| 51 | +``` |
| 52 | +For Gradle, include in your build.gradle: |
| 53 | + |
| 54 | +```groovy |
| 55 | +dependencies { |
| 56 | + implementation "org.jooq:jooq:$jooqVersion" |
| 57 | + implementation "tech.ydb.dialects:jooq-ydb-dialect:$jooqYdbDialectVersion" |
| 58 | + implementation "tech.ydb.jdbc:ydb-jdbc-driver:$ydbJdbcVersion" |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### Configuration |
| 63 | +Configure the JOOQ runtime to use the YDB dialect and JDBC driver: |
| 64 | + |
| 65 | +```java |
| 66 | +String url = "jdbc:ydb:grpc://localhost:2136/local"; |
| 67 | +Connection conn = DriverManager.getConnection(url); |
| 68 | + |
| 69 | +DSLContext dsl = new YdbDslContext(conn); |
| 70 | +``` |
| 71 | + |
| 72 | +### XML config |
| 73 | + |
| 74 | +To ensure successful code generation, it is essential to correctly configure the XML configuration file. Specifically, you must specify two mandatory fields for YDB: `strategy.name=tech.ydb.jooq.codegen.YdbGeneratorStrategy` and `database.name=tech.ydb.jooq.codegen.YdbDatabase`. Here is an example: |
| 75 | + |
| 76 | +```xml |
| 77 | +<configuration> |
| 78 | + <jdbc> |
| 79 | + <driver>tech.ydb.jdbc.YdbDriver</driver> |
| 80 | + <url>jdbc:ydb:grpc://localhost:2136/local</url> |
| 81 | + <user>$user</user> |
| 82 | + <password>$password</password> |
| 83 | + </jdbc> |
| 84 | + |
| 85 | + <generator> |
| 86 | + <name>org.jooq.codegen.JavaGenerator</name> |
| 87 | + |
| 88 | + <strategy> |
| 89 | + <name>tech.ydb.jooq.codegen.YdbGeneratorStrategy</name> |
| 90 | + </strategy> |
| 91 | + |
| 92 | + <database> |
| 93 | + <name>tech.ydb.jooq.codegen.YdbDatabase</name> |
| 94 | + |
| 95 | + <includes>.*</includes> |
| 96 | + |
| 97 | + <excludes></excludes> |
| 98 | + </database> |
| 99 | + |
| 100 | + <target> |
| 101 | + <packageName>ydb</packageName> |
| 102 | + <directory>./generated</directory> |
| 103 | + </target> |
| 104 | + </generator> |
| 105 | +</configuration> |
| 106 | +``` |
| 107 | +For more information, see [here](https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration/) |
| 108 | + |
| 109 | +## Usage |
| 110 | +Leverage the power of JOOQ to create, read, update, and delete operations in a type-safe manner. Utilize advanced querying capabilities with the strong SQL abstraction provided by JOOQ. |
| 111 | + |
| 112 | +Integration with Spring Boot: |
| 113 | +```properties |
| 114 | +spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local |
| 115 | +``` |
| 116 | + |
| 117 | +## Limitations |
| 118 | + |
| 119 | +To understand what SQL constructs YDB can perform, |
| 120 | +see the [documentation](https://ydb.tech/docs/en/yql/reference/) for the query language. |
| 121 | + |
| 122 | +## Authorization |
| 123 | + |
| 124 | +See [connect to YDB](../README.md/#connect-to-ydb). |
| 125 | + |
| 126 | +## Support and Contact |
| 127 | + |
| 128 | +For support, you can open issues in the repository issue tracker with tag `jooq`. |
0 commit comments