-
-
Save LCHCAPITALHUMAIN/a7b344057f7f5b87ef1f to your computer and use it in GitHub Desktop.
example of effect of getter in gstorm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GrabResolver(name='gstorm', root='http://dl.bintray.com/kdabir/maven') | |
@Grab('io.github.kdabir.gstorm:gstorm:0.7') | |
@GrabConfig(systemClassLoader = true) | |
@Grab('org.hsqldb:hsqldb:2.3.2') | |
import groovy.sql.* | |
import gstorm.* | |
// using sql object explicitly to create Gstorm instance, this can be any other jdbc driver | |
def sql = Sql.newInstance("jdbc:hsqldb:mem:database1", "sa", "", "org.hsqldb.jdbcDriver") | |
@Table("Employees") // if have a different table name | |
class Employee { | |
@Id Integer empId // annotate Id if you dont want want implicit id | |
String name | |
String department | |
String getName(){ | |
this.name.toUpperCase() | |
} | |
} | |
new Gstorm(sql).stormify(Employee) | |
new Employee(name: "John Doe", department: "Accounts").save() | |
new Employee(name: "Donald Duck", department: "Marketing").save() | |
new Employee(name: "Alfred Hitchcock", department: "Marketing").save() | |
Employee.where("department = 'Marketing'").each { // pass any standard SQL where clause | |
println "${it.name} is in Marketing" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment