It is more convenient that we use Enums in our domain classes rather than String, when we are really sure that Enum is the best representation of a property. Maintaining Strings and constants is just a pain. But it is common problem on how to create a form that accepts Enum values. Below is an example on how to use Select Tag inGrails to choose from Enum values.
When programming in Grails, sometimes we get a String value that we wish to transform to an Enum. For example, when usually get String value from data passed from form or url parameters. Since Groovy 1.7.6, it is now easy to transform a String into a Enum value. Below are some examples:
When a record in a database table is not needed anymore then we may want to delete it. There are two ways of deleting a record. One is called logical delete where the record is still in the table but a marker was set in one of the column to tell the application that uses the table to ignore it. The second one is called physical delete where we really delete the record in the databases. SQL provides the delete statement for physical delete. Below are examples on how to perform delete operation using Groovy SQL.
Reading data from database tables is one of the most common task in programming. For RDBMS servers that supports SQL, we can use SELECT statements for this purpose. Below are some examples on how to read data from database tables using Groovy SQL.
Another common operation when working with database is inserting data. This is simple to achieve using SQL's insert statements. Below are some examples on how to insert data to a database table using Groovy SQL.
One of the first things we do to a database is to create tables. SQL supports data definition language or data description language (DDL). Using SQL "Create" statements, we can create tables in our database. Below is a simple example on how to use Groovy SQL to create a table in the database.
When working with database in Groovy, the first thing we want to do is to connect to a database server. We will not be able to read or manipulate data unless we have a connection. Below will show a simple example on how to connect to a MySQL database in Groovy.