Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

play-iot/qwe-sql

Repository files navigation

QWE SQL

SQL is one of Carl abilities.

build GitHub release (latest SemVer) Sonatype Nexus (Releases) Sonatype Nexus (Snapshots)

Maintainability Rating Reliability Rating Security Rating Duplicated Lines (%) Coverage

Overview

TBD

How To

  • Prepare sql ddl files and put it into src/main/resources. The tips if many sql ddl files, name it with prefix 01_, 02_ with appropriate order
  • Adapt build script build.gradle similar as:
import org.jooq.meta.jaxb.ForcedType

import com.nubeiot.buildscript.jooq.DB
import com.nubeiot.buildscript.jooq.JooqGenerateTask
import com.nubeiot.buildscript.jooq.JooqGenerateTask.JsonDataType
import com.nubeiot.buildscript.jooq.Utils

dependencies {
    compile project(':core:sql')
    compile project.deps.database.h2
}

task jooqGen(type: JooqGenerateTask) {
    packageName = "com.nubeiot.edge.core.model"
    enumTypes = project(':core:sql').ext.enumTypes
    dbTypes = project(':core:sql').ext.dbTypes + [
        new ForcedType(userType: "com.nubeiot.edge.core.loader.ModuleType", types: DB.TYPES.varchar,
                       expression: Utils.toRegexIgnoreCase("service_type"),
                       converter: "com.nubeiot.edge.core.model.converter.ModuleTypeConverter")
    ]
    javaTypes = project(':core:sql').ext.javaTypes + [
        new JsonDataType(className: "com.nubeiot.edge.core.loader.ModuleType",
                         converter: "%s.name()",
                         parser: "com.nubeiot.edge.core.loader.ModuleTypeFactory.factory((String)%s)",
                         defVal: "com.nubeiot.edge.core.loader.ModuleTypeFactory.getDefault()")
    ]
}
  • Run gradle jooq
  • Generated class should be in ${project_folder}/generated/main/java/${your_define_package}

Current limitations

PostgreSQL

  • Timestamp with timezone (timestamptz) data type doesn't work.
  • Function CURRENT_TIMESTAMP doesn't work.