Grails Postgresql Extensions

THIS BRANCH (master) IS FOR GRAILS 3 AND HIBERNATE 5.2

This is a grails plugin that provides hibernate user types to use Postgresql native types such as Array, Hstore, Json,
Jsonb... from a Grails application. It also provides new criterias to query this new native types.

Currently the plugin supports array, hstore, json and jsonb fields as well as some query methods.
More native types and query methods will be added in the future.

Installation

The Grails 3 version supports both Hibernate 4.X (versions 4.x.x of the plugin) and Hibernate 5.X (versions 5.x.x of the
plugin). In build.gradle add the jcenter repository and the following dependency to install the plugin:

Hibernate plugin

It's also necessary to install the Grails-Hibernate plugin. Depending if you use Hibernate 4 or Hibernate 5 you'll need
different dependencies. Please make sure you use the latest versions of the plugin and the hibernate dependencies

Please be aware that Hibernate 5 has changed the default name of the sequences so for a domain class TestMapJson the
table name is test_map_json and the sequence name is seq_test_map_json in Hibernate 4 and testmapjson_seq in
Hibernate 5.

Native Types

Arrays

The Enum arrays behaves almost identical to Integer arrays in that they store and retrieve an array of ints. The
difference, however, is that this is used with an Array of Enums, rather than Ints. The Enums are serialized to their
ordinal value before persisted to the database. On retrieval, they are then converted back into their original Enum
type.

Is Empty

With this criteria you can get all the rows that contains an-empty array in the selected field. To use it just use the
new criteria pgArrayIsEmpty:

def result = Like.withCriteria {
pgArrayIsEmpty 'favoriteMovies'
}

Is Not Empty

With this criteria you can get all the rows that contains a not empty array in the selected field. To use it just use
the new criteria pgArrayIsNotEmpty:

def result = Like.withCriteria {
pgArrayIsNotEmpty 'favoriteMovies'
}

Is Empty or Contains

This criteria is a mix of the pgContains and pgIsEmpty. Sometimes you have to execute 'pgContains' criteria if the
list has elements or a 'pgIsEmpty' if the list is empty. It could be something like this: