Skip to content

Commit

Permalink
version 2.0.0, lots of things
Browse files Browse the repository at this point in the history
  • Loading branch information
rnett committed Dec 28, 2018
1 parent f1c6904 commit ba243bc
Show file tree
Hide file tree
Showing 11 changed files with 1,092 additions and 174 deletions.
42 changes: 37 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,35 @@ look at the Type class and its uses, it is the only vendor dependant part.
Error reports / issues are welcome, but there is no guarantee I will get to it.
This isn't something I'm supporting, just something I use that might be useful.

# Features

* KotlinX Serializer generation (saved fields on serialization, loads from database on deserializiation)
* Multiplatform support (with cross-platform capable serialization for easy data transfer)
* Foreign and Referencing Keys
* Optional assume nullable unless explcit `not null`
* Imports and package statement
* Export to class/package structure
* `new` pesudo-Constructor that takes fields as arguments
* Customizable names, mutability

# Limitations

* Some data types
* Anything Non-postgres
* Must have one primary key that is an int or long type if you want DAO (DSL will still be generated)

# Usage

## GUI (ExposedDaoGenerator.jar)

Download the ExposedDaoGenerator.jar. Run it.

##### It is still in Beta, the UI is somewhat buggy.
Supports package names, save/load, import/export, and export to files (a file per table).

Also supports Kotlin multiplatform projects
(generates a common class, a JS class that will work on other platforms, and the JVM class with the exposed backend).

##### UI is somewhat buggy, but as long as you don't try to break it you should be allright.
Issues and feedback are appreciated.

To start, hit File -> New or `CTRL-N` to create a new database from a connection string.
Expand All @@ -32,7 +54,9 @@ You can change the names of the columns and keys, and make the class properties

I plan to add the ability to change the type, and to exclude columns.

### Saving
### Usage

To change settings, use `CTRL-SHIFT-O`.

You can save your (edited) database to a .daogen file using File -> Save or `CTRL-S`.

Expand All @@ -46,6 +70,8 @@ To change the export file, use `CTRL-SHIFT-E`.

To import the database from an exported file, use `CTRL-I`.

To export to files, use `CTRL-ALT-E`.

If Autosave is checked, the database will automatically be saved to the save file when any changes are made (if the save file is set).

If Auto Export is checked, the database will automatically be exported to the export file when any changes are made (if the export file is set).
Expand All @@ -58,11 +84,17 @@ Download daogen.jar or build with gradle.
The jar is /libs/daogen.jarif you build with gradle.


Run with the command arguments: `<connectionString> [-f outFile] [-s schema] [-nodao] [-cc] [-q]`
Run with the command arguments: `<connectionString> [-p package] [-f outFile] [-s schema] [-tables tablesCSVList] [-nodao] [-noserialize] [-multiplatform JVM/JS/Common] [-cc] [-q]`
* `connectionString` is the JDBC connection string. **[MANDATORY]**
* `outFile` file to output to. Default is not to output the generated code to a file. Optional, **must be preceded by -f**
* `schema` schema to look at. Default is all of them. Optional, **must be preceded by -s**
* `package` is the package to put in the package statement. Optional, **must be preceded by -p**
* `outFile` is the file to output to. Default is not to output the generated code to a file. Optional, **must be preceded by -f**
* `schema` is schema to look at. Default is all of them. Optional, **must be preceded by -s**
* `tablesCSVList` is the list of tables, separated by commas, to look at. Default is all of them. Optional, **must be preceded by -tables**
* `-nodao` means not to generate DAO (classes), just DSL (objects). Optional.
* `-noserialize` means not to generate KotlinX Serializers. Optional.
* `-multiplatform` optionally generates the DAO for a multiplatform project's platform.
`-multiplatform` can be followed by `JVM`, `JS`, or `Common`, which causes daogen to output for that platform.
Note that specifying `JVM` here is different than no multiplatform at all; with `JVM`, `actual` statements will be included.
* `-cc` means to copy the generated code to the clipboard. Optional.
* `-q` means to run in quiet mode without outputting the generated code. Optional.

Expand Down
35 changes: 29 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.Coroutines
import org.apache.tools.ant.filters.*
import org.jetbrains.kotlin.contracts.model.structure.UNKNOWN_COMPUTATION.type
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import sun.tools.jar.resources.jar

val kotlin_version = "1.2.71"
val kotlin_version = "1.3.11"

buildscript {
val kotlin_version = "1.3.11"
repositories {
jcenter()
mavenCentral()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://kotlin.bintray.com/kotlinx")
}

dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlin_version")
}
}
group = "com.rnett.daogen"
version = "2.0.0-beta"
version = "2.0.0"

plugins {
java
kotlin("jvm") version "1.2.71"
kotlin("jvm") version "1.3.11"
}

apply {
plugin("kotlinx-serialization")
}

val serializiation_version = "0.9.1"

repositories {
mavenCentral()
jcenter()
maven("https://jitpack.io")
maven("https://kotlin.bintray.com/kotlinx")
}

dependencies {
Expand All @@ -26,6 +45,9 @@ dependencies {
implementation("org.postgresql:postgresql:42.2.5")
implementation("no.tornado:tornadofx:1.7.16")
implementation("com.github.salomonbrys.kotson:kotson:2.5.0")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serializiation_version")
implementation("com.github.rnett:core:1.3.8")
}

configure<JavaPluginConvention> {
Expand All @@ -35,6 +57,7 @@ tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}


val jars = mapOf(
"daogen" to "com.rnett.daogen.MainKt",
"ExposedDaoGenerator" to "com.rnett.daogen.app.DaogenApp"
Expand Down
30 changes: 21 additions & 9 deletions src/main/kotlin/com/rnett/daogen/Main.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.rnett.daogen

import com.rnett.daogen.database.DB
import com.rnett.daogen.ddl.generateDB
import com.rnett.daogen.ddl.generateKotlin
import com.rnett.daogen.ddl.*
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.io.File

var doDAO = true
import kotlin.contracts.ExperimentalContracts

/**
* args: <connectionString> [-f outFile] [-s schema] [-nodao] [-cc] [-q]
* args: <connectionString> [-p package] [-f outFile] [-s schema] [-tables <tablesCSVList>] [-nodao] [-noserialize] [-multiplatform <JVM/JS/Common>] [-cc] [-q]
*/
@ExperimentalContracts
fun main(args: Array<String>) {

if (args.contains("--version")) {
println("Daogen version 1.0.0")
println("Daogen version 2.0.0")
return
}

Expand All @@ -28,10 +27,23 @@ fun main(args: Array<String>) {

val schema = args["-s"]

if ("-nodao" in args)
doDAO = false
val pack = args["-p"] ?: "unknown"

val tables = args["-tables"]

val doDao = "-nodao" !in args
val doSerialize = "-noserialize" !in args
val multiplatform = args["-multiplatform"]

val out = DB.connect(dbString).generateDB(dbString, schema).generateKotlin()
val options = GenerationOptions(pack, doSerialize, true, doDao, multiplatform != null)

val db = DB.connect(dbString).generateDB(dbString, schema, tables?.split(",")?.map { it.trim() })

val out = when (multiplatform) {
"JS" -> db.generateKotlinJS(options)
"Common" -> db.generateKotlinCommon(options)
else -> db.generateKotlin(options)
}

if ("-cc" in args) {
val sel = StringSelection(out)
Expand Down
Loading

0 comments on commit ba243bc

Please sign in to comment.