Skip to content

Commit

Permalink
dd readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vendelieu committed Nov 13, 2023
1 parent ebc4f89 commit 192e27b
Show file tree
Hide file tree
Showing 10 changed files with 907 additions and 32 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/ci.release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Release pipeline"
on:
push:
tags:
- '*.*.*'
- 'v*.*.*'

jobs:
version:
Expand All @@ -18,6 +18,18 @@ jobs:
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
shell: bash

readme:
name: Replace version in README.md
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: jacobtomlinson/gha-find-replace@v3
with:
find: "*.*.*"
replace: "${{ needs.version.outputs.version }}"
regex: true
include: "./README.md"

release-build:
runs-on: ubuntu-22.04
needs: version
Expand Down
106 changes: 105 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,105 @@
Jooq plugin that provides generator for expanding generated dao.
[version]: 0.0.1

<br/>
<p align="center">
<img src="https://github.com/vendelieu/telegram-bot/assets/3987067/a96e2a39-60f2-4d7a-8270-a0c60d4fe6c3" height="90" alt="jooq plugin extension logo" />
</p>

[![Gradle Plugin](https://img.shields.io/gradle-plugin-portal/v/eu.vendeli.jooq.extension?label=Gradle&logo=gradle)](https://plugins.gradle.org/plugin/eu.vendeli.jooq.extension)

## Introduction

This repository contains a Gradle plugin that integrates a custom jOOQ generator.

The custom generator extends the functionality of jOOQ generated DAOs (Data Access Objects) with helpful functions.

## Usage

### Applying the Plugin

To apply the plugin to your project, add the following to your `build.gradle.kts` file:

```kotlin
plugins {
id("eu.vendeli.jooq.extension") version "0.0.1"
}
```

## Examples

Below are basic examples of extended dao functions:

```kotlin
fun getUserDocument(id: Long, userId: Long) = getOne {
DOCUMENT.ID.eq(id).and(DOCUMENT.USER_ID.eq(userId))
}

fun getAllUserDocuments(userId: Long) = getAll {
DOCUMENT.USER_ID.eq(userId)
}

fun create(uuid: String): User = create { this.uuid = uuid.toUuid() }

fun get(uuid: String): User = getOne { USER.UUID.eq(uuid.toUuid()) } ?: create(uuid)

fun update(uuid: String, block: User.() -> Unit): User? = update(USER.UUID.eq(uuid.toUuid()), block)

fun countUsers(userUuid: String) = count {
USER.CREATED_AT.lt(Instant.now())
}
```

### Configuring the Plugin

The plugin can be configured using the `jooq` extension.

You need to set as provided custom generator and some
generation flags to make it work well.

Here is an example configuration:

```kotlin
generate.apply {
name = "eu.vendeli.jooq.generator.ExtendedJavaJooqGenerator"
isDeprecated = false
isRecords = true
isPojos = true
isImmutablePojos = false
isFluentSetters = true
isInterfaces = true
isDaos = true
isSpringAnnotations = true
}
```

After this, the generated DAO will be expanded with an interface that covers most use cases,
you can also inherit from generated DAO and be able to supplement it using convenient functions.
Note also that the interface itself has built-in `dslContext`.

### Running the Plugin

To generate the jOOQ classes, you can use usual generate command:

```shell
./gradlew generateJooq
```

## Custom Generator

The custom generator extends the functionality of jOOQ generated DAOs with custom functions. For example, every table
and view in your database will generate a `org.jooq.DAO` implementation that includes custom fetch
methods with convenient Kotlin DSL, you can see interface that will be
extended [there](https://github.com/vendelieu/jooq-extension/blob/master/src/main/resources/DAOExtendedImpl.kt).

## License

This project is licensed under the [Apache License, Version 2.0](LICENSE).

## Contact

If you have any questions about this project, please open an issue on GitHub.

## Acknowledgements

This project was inspired by
the [jOOQ documentation](https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration/).
23 changes: 21 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.KtlintExtension

val javaVersion = JavaVersion.VERSION_11

plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.gradle.publish)
`java-gradle-plugin`
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
}

group = "eu.vendeli"
Expand Down Expand Up @@ -46,16 +50,31 @@ java {
targetCompatibility = javaVersion
}


tasks {
withType<Wrapper> {
distributionType = Wrapper.DistributionType.ALL
}

withType<Detekt> {
config = rootProject.files("config/detekt.yml")
}
configure<KtlintExtension> {
debug.set(false)
verbose.set(true)
android.set(false)
outputToConsole.set(true)
ignoreFailures.set(false)
enableExperimentalRules.set(true)
filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}

withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = javaVersion.majorVersion
}
}
}
}
Loading

0 comments on commit 192e27b

Please sign in to comment.