- TODO
- 0.5.0 API Breaking Release
- 0.5.2
- 0.5.0
- 0.5.0-beta-8
- 0.5.0-beta-7
- 0.5.0-beta-6
- 0.5.0-beta-5
- 0.5.0-beta-4
- 0.5.0-beta-3
- 0.5.0-beta-2
- 0.5.0-beta-1
- 0.4.10
- 0.4.8
- 0.4.6
- 0.4.4
- 0.4.2
- 0.4.0
- 0.3.4
- 0.3.2
- 0.3.0
- 0.2.26
- 0.2.24
- 0.2.22
- 0.2.20
- 0.2.18
- 0.2.16
- 0.2.14
- 0.2.12
- 0.2.10
- 0.2.8
- 0.2.6
- 0.2.4
- 0.2.2
- 0.2.0
- 0.1.8
- 0.1.6
- 0.1.4
- 0.1.2
- 0.1.0
- Add: tests for all type conversions
- Result set
- Json
- Kotlin types
- Add case sensitive database entity aware migration
- Tables
- Others?
- Test: query generating functions
- validate quote parameter is used for table and column names
- alias parameter
-
""
- same as table name
- other string
"a"
-
- Test: list generation functions
- Fix: Readme docs, consider creating a wiki
ℹ️ This branch is a rework with breaking changes to refactor models and related classes to eliminate having to specify identifier quoting in the model by creating the model for a database session. Which makes sense for a database model class.
Biggest change is that the model now takes two template arguments: main model class and its associated data class with an optional session instance and identifier quoting string.
If session
is not given or null
then default session will be used.
If quote
if not given or null
then the connection metaData.identifierQuoteString
will be
used, anything else will use whatever string is passed in. Unless your jdbc driver does not
provide identifier quoting, there is no need to use anything but the default.
Companion object now only has the table name constant string.
All other functions implemented in the Model
with two abstract members: toData()
returning
the data class for the model and operator invoke
for the factory function for the model. To
get another instance of a model myModel
invoke the model instance as a function myModel()
.
For models that do not need a data class ModelNoData
is also available which only takes a
single template argument, as was the case for the Model
class in previous releases.
Having the session instance information in the model simplifies using models because session no longer has to be specified for every method performing database access.
Additionally, list results are simplified because neither the session nor the extractor needs to
be passed, with myModel.listData()
variations can be used or myModel.listModel()
variations.
Additionally there is now an alias:String? = null
argument available for sql generating
functions which will add a table alias to the table name and use the alias for disambiguating
column names. If generating queries with multiple tables, set the alias
to empty string ""
or the table name to have it added to the column references. An empty table alias or one equal
to the table name will only be used for column references.
Generate Kotlin-Model.groovy
has been updated to generate the new model format from tables
in the database.
- Fix: #17, Condition WHERE IN not working
- Fix: merge branch
dev-0.5.0
intomaster
- Fix: merge #15, PR: Allow for custom hikari data sources
- Fix: travis to use precise env to allow jdk8
-
Fix:
SqlCall
out params are now passed by index instead of name to make them independent of actual sql procedure parameter names. -
Fix:
param()
to work for non-null values when calling context's capture type is*
, previous implementation would always result inAny
type, fixed implementation uses the value's class for type's class. -
Fix:
param()
to not construct a new instance if passed value is alreadyParameter<*>
-
Fix: SQL generation for model
listQuery
with where clause and/or alias -
Add:
InOut
type toParameter()
, defaults toInOut.IN
so parameter carries direction of parameter and type. -
Add:
inTo
,outTo
andinOutTo
infix functions to use instead ofto
for param creation. These create parameters with in/inOut/out type eliminating the need for multipleparams()
functions for directional information. Default direction isin
if not provided.They also create an instance of
Parameter
when the captured type is known. Functions usingparam()
from a collection iteration have*
for type capture and loose actual type, resorting toAny
(ie.Object
).These also have
Collection<T>
versions which create a Parameter() with a collection value but type isT::class.java
. When generating parameters for prepared stmt this type is used to determine sql type for the element of the collection instead of genericAny
as was before, again because of*
captured type from a collection. -
Fix: extract
SqlQueryBase<T>
forSqlQuery
andSqlCall
to eliminate the need to override function just to cast them to the right class.SqlCall
no longer extendsSqlQuery
. -
Fix:
SqlQueryBase
now stores each parameter inParameter()
data class format. Eliminates creating a new instance with param() since if it is already parameter it just returns the instance. -
Fix: deprecate old methods in favor of directional parameter declaration.
-
Fix: change
Session
methods to useSqlQueryBase<*>
when eitherSqlQuery
orSqlCall
can be used. For some, like updates with get keys,SqlCall
never returns any keys even when stored procedure executes DML that does, so these are nowSqlQuery
only. Similarly, those only applicable toSqlCall
are nowSqlCall
typed and will not takeSqlQuery
-
Fix: deprecate
Session.forEach(SqlCall, (stmt: CallableStatement) -> Unit, (rs: ResultSet, index: Int) -> Unit)
-
Add:
Session.executeCall(SqlCall, (results: SqlCallResults) -> Unit)
to replaceSession.forEach(SqlCall, (stmt: CallableStatement) -> Unit, (rs: ResultSet, index: Int) -> Unit)
. UseSqlCallResults.forEach
to process result sets returned by the procedure call. To get values of out params useSqlCallResults.get{Type}(paramName)
to get non-null values orSqlCallResults.get{Type}OrNull(paramName)
to get nullable values.For example, when using old
forEach
the code was:val sqlQuery = sqlCall("""CALL processInstances(:clientId, :types)""") .inParams("clientId" to 35) .inOutParams("types" to "") val jsonResult = MutableJsObject() var types: List<String> = listOf() session.forEach(sqlQuery, { stmt -> types = stmt.getString("types").split(',') }) { rs, index -> val key = types[index] jsonResult[key] = MutableJsArray(Rows(rs).map(toJsonObject).toList()) }
Using the new
executeCall
and directional param declarations, the code changes to:val sqlQuery = sqlCall("""CALL processInstances(:clientId, :types)""", mapOf("clientId" inTo 35, "types" inOutTo "")) val jsonResult = MutableJsObject() session.executeCall(sqlQuery) { results:SqlCallResults -> val types = results.getString("types").split(',') results.forEach { rs, index -> val key = types[index] jsonResult[key] = MutableJsArray(Rows(rs).map(toJsonObject).toList()) } }
- Add: import evolutions to also accept
# -- !Ups
and# -- !Downs
as valid Scala play evolution markers - Fix: merge fixes made by Nick Johnson in master
- Break: Add profile name after
db/
to allow multi-database migrations.⚠️ To migrate previousdb/
structure move all directories other thantemplates
ofdb/
todb/default
- default profile is in
default
directory - templates remain under
db/templates
and will apply to all profiles - new
Migrations
constructor takes maps for session arguments indexed by profile string - old
Migrations
constructor now usesdefault
for profile name profile
command line option specifies which profile is to be used. Some commands likerollback
require an explicit profile name, others will usedefault
when one is not given, some likeinit
andmigrate
will apply the command over all profiles
- Fix: Rollback used string compare instead of version compare, causing 0_7_2 to match 0_7_20 rollback.
- Fix:
JavaScript-Enumerated-Value-Type.js
for latest version ofenumerated-type
with objects for values anddropdownChoices
property of{ value: xxx, label: "yyy", }
automatically generated from the enum id column and enum type column.
-
Fix:
JavaScript-Enumerated-Value-Type.js
for latest version ofenumerated-type
with object value containing the id and type instead of constants. -
Add: option to Scala model script to generate a separate Database model and an Api Model used for REST api data exchange.
-
Fix:
Generate Kotlin-Model.groovy
now will look for the model map file starting from the directory selected for generation and go up, until encountering directory with sub-directory.idea
, hitting the root directory or findingmodel-config.json
file. Mappings in this file are now relative to the directory of themodel-config.json
file.if
.idea
sub-directory was seen then will assume that this is the project root and if nomodel-config.json
file is provided then will use the destination directory, without the project directory prefix and one more directory removed to generate the package for generated files. If the first sub-directory is marked assources root
then the package will be correct. Otherwise create amodel-config.json
.Intended use case is to place the
model-config.json
at the project root and map all files in it with path relative to project root. Generating models then is not dependent on which directory in the project is selected as the directory for generating models. -
Fix:
Generate Scala-Slick-Model.groovy
to work likeGenerate Kotlin-Model.groovy
-
Fix: make
Generate Kotlin-Model.groovy
andGenerate Scala-Slick-Model.groovy
more generic with the differences isolated to the last generate method. -
Fix: model generation scripts to get nullability and default value for column from database information. No longer kludging based on column names.
-
Add:
Scala-Object-Enum.kt.js
to generate anobject
with fields mimicking enum values, needs work to make real Scala enums. -
Add:
import-evolutions path min {max}
where path is to the directory holding evolutions andmin
is the minimum evolution to import.max
is optional and if provided gives the maximum evolution number to import. -
Fix:
new-evolution
to put down migration script right after the up migration script instead of all up migrations followed by reversed down migrations.
-
Add:
jsonArray
functions toModel
to list query results directly toJsonArray
ofJsonObject
.⚠️ will convert all columns of the query to properties of theJsonObject
without filtering by model properties. -
Add:
listData
andlistModel
variants with parameter list and no where clause to have the where clause generated from passed parameters. -
Add: optional
model-config.json
to be used by Kotlin model generating script to control location and name of generated models.
- Fix: API Change
- Fix: merge #7, isLast and isAfterLast checking removed for TYPE_FORWARD_ONLY ResultSet thanks to @s5r3
- Fix: migrate was using string compare for current version and versions for finding later ones
- Fix: parameter extraction should take quoted, double quoted and back-quoted strings into
account. Otherwise a string with
:\w+
will be treated as a parameter.
- Fix: migrate command was string sorting versions instead of using versionCompare()
- Add: multiple list parameter handling, PR by root-talis
- Fix: factor out
Session
andTransaction
functions into interfaces. Implementation renamed toSessionImpl
andTransactionImpl
-
Fix: remove database dependent quoting of table name and column names and replace it with an optional
quote
argument toModelProperties
andModel
constructor argument with default fromModelProperties.databaseQuoting
which can be set to any desired string. If the same database type is used on all connections then quoting should be set during initialization throughModel.databaseQuoting
.However, if multiple databases with different quoting requirements are used then
quote
argument will need to be passed to model constructor based on the database connection.- companion functions requiring quoting now take an optional argument
quote
with default ofModelProperties.databaseQuoting
- model companion abstract
createModel()
now hascreateModel(quote: String?)
signature so it can passquote
argument to model constructor.
- companion functions requiring quoting now take an optional argument
-
Fix: list query with where clause parameters to use name parameters instead of plain parameters since parameters are passed as a map.
-
Fix: list queries with where clause parameters having collection values to use
IN (:name)
instead ofname = :name
for condition -
Add: automatic expansion of
sqlQuery
andsqlCall
collection valued parameters into their contained values. This allows lists to be used where individual parameters are expected:
sqlQuery("SELECT * FROM Table WHERE column in (:list)").inParams("list" to listOf(1,2,3))
To expand to SELECT * FROM Table WHERE column in (?,?,?)
with parameters of 1, 2, 3
.
- Change: refactor
sqlQuery
to substitute named parameters and compute named parameter mapping as needed and after any parameter changes. Required to have access to the parameter's type to figure out if it is a list or a single value.
- Add: variations of
list
andlistJson
toModelCompanion
taking where clause and varargPair
or map argument for parameters for the where clause for more flexibility of generating list queries.
- Add:
Model.appendWhereClause()
to simplify creating list queries
- Change: from
by model
toby db
for model property definitions - Add:
Model.listQuery
companion methods to list model instances with or without conditions - Add:
ModelCompanion
to make companion methods of real models simpler to update without code editing - Add: separate session for updating migrations table to keep separate from schema modification session.
- Fix: add trimming of table sql string for comparing by line re-ordering before splitting into lines.
- Fix: JS enum type script for better WebStorm code completion functionality
- Add: copying any extra files under
/db/template
resources directory to new version directory on creation. Intended for things like change notes or other common file templates. - Fix:
model
:auto
,key
,default
,autoKey
combinations - Add:
model.default(Any?)
default property type definition with a provided default value. Will set properties not provided or if their value is null on insert to this value - Add: insert and update queries to skip passing
null
value parameters which have defaults.null
effectively means the same thing as not setting the parameter, using the db defined default instead for insert and no-op for update. - Add: update query which has no non-null non-default modified parameters will update key column to itself to trigger auto updated fields.
- Add: migration verbose
-v
and detailed-d
flags for table validation - Add: ignoring named param pattern in query lines that are commented out with
--
or#
as first non-blank of the line. Otherwise too many parameters will be passed for the query since SQL will not see the named param uses or comments in sql might me interpreted as parameter names. - Add: IntelliJ Ultimate Database Tools data extraction script to generate JavaScript enum from table data. See:
- Add: IntelliJ Ultimate Database Tools data extraction script to generate Kotlin enum from table data. See: Installing IntelliJ Ultimate Database Tools Extension Scripts
- Fix: table validation for out of order lines to ignore trailing , otherwise the last line out of order does not match.
- Fix: init command when run on a database without
migrations
table will use db versions table schema to determine latest matched version as the current version - Add: validation for table names in table sql to match file name when doing init.
- Fix: table validation to properly detect when resource is missing
- Add: migrations to play evolutions conversion command:
new-evolution "play/evolutions/directory"
which will convert the current or requested version migrations and rollbacks to the next play evolutions file in the requested directory.
- Fix: model generating script to convert table name to singular form for use as the model class name.
- Add:
new-...
commands for: function, procedure, trigger and view. - Add: built in templates for creating new entities with placeholders
__VERSION__
replaced by the version for which they are created and__TITLE__
for migration/rollback or__NAME__
for all others to reflect the parameter passed to the command
- Change:
usingSession
tousingDefault
as a short form ofusing(session())
- Add:
Session.defaultDataSource
lambda to generate default data source for use withsession()
version of the function to reduce default session arguments
- Fix: commit before doing
System.exit(1)
for exit command
- Fix: migrations rollback filter condition reversed for multiple version rollback
- Add: migrations
update-schema
command to copy all current version entities to theschema
version directory to allow VCS version to version change tracking.
- Fix: npe when trying to access non existent resource
- Add: migration convenience commands
-
new-major - create a new version directory with major version incremented.
-
new-minor - create a new version directory with minor version incremented.
-
new-patch - create a new version directory with patch version incremented.
-
new-version - create a new version directory with minor version incremented. The directory cannot already exist. If the version is not provided then the next version with its minor version number incremented will be used.
All entity directories will be created, including migrations.
If there is a previous version to the one requested then its entity scripts will be copied to the new version directory, including tables which are used for validation after rollback/migration
-
new-migration "title" - create a new up/down migration script files in the requested (or current) version's migrations directory. The file name will be in the form: N.title.D.sql where N is numeric integer 1..., D is up or down and title is the title passed command.
-
-
Add:
Model(val sqlTable: String, dbCase: Boolean, allowSetAuto: Boolean = true)
,dbCase
to mark all properties without specific column name as having database case. When false, database columns are assumed to be (snake case) versions of the property names. Available on all property providers:auto
,key
,default
-
Add:
model.column(String)
to provide arbitrary column name for the property. Available on all property providers:auto
,key
,default
- Add: migration table compare will match if differences are out of order lines between two tables. This addresses validation failure for tables which are changed due to rollback causing keys and constraints to be in a different order.
- Add:
Model.toJson()
method for converting a model toJsonObject
- Fix: migration command to not apply versions higher than requested
- Add: IntelliJ Database script extension to create Models from database tables
- Fix: Apply all migrations that exist from start. First version under migrations should have initial database creation without migrations.
- Change: refactor code to clean up duplication
- Add:
Model.appendKeys()
to append model's keys for query generation - Fix: wrong conversion for jodaLocalDateTime and a few others. Added casts to catch these errors during compilation
- Fix: add snapshot to
Model.update(session:Session)
after successful update.
- Add: abstract
Model
class for creating models to reduce boiler plate code.
- Fix: wrong filter on get entity resource files list
- Change: change
updateGetId
andupdateGetIds
to returnInt
andList<Int>
respectively - Add: add
updateGetLongId
andupdateGetLongIds
to returnLong
andList<Long>
respectively
- Fix: iteration over empty result set caused exception, due to insufficient conditions present in result set to know there is no next row until next() is invoked.
- Add: rudimentary SQL based migrations with migrate/rollback with up/down sql scripts, table, procedure, function, view and trigger script running. Migrations are for data and tables. The rest of the scripts are applied for a given version. Needs docs and tests.
- Fix: pom packaging to jar
- Fix: pom missing info
- Fix: pom and travis errors
- Fix: pom for dokka plugin javadoc generation
- Initial release