Gstorm is very light persistence helper for simple scenarios such as groovy scripts.
class Person { String name, project } // this is your model class
def g = new Gstorm(sql)
g.stormify(Person) // table automatically gets created for this class
def person = new Person(name: "kunal", project: "gstorm")
person.save() // which saves object to db
def result = Person.where("name = 'kunal'") // pass any standard SQL where clause
println result
println "all records -> ${Person.all}" // get all objects from db
person.name = "kunal dabir"
person.save() // saves the object back to db
println Person.get(person.id) // loads the object by id
person.delete() // delete the person from db
To see gstorm in action just execute following from command line:
groovy https://raw.github.com/kdabir/gstorm/master/examples/getting_started.groovy
Provided you have groovy installed, you don't need to install anything else.
In groovy scripts, when you need persistence, and you often feel hibernate is overkill but handwritten SQL is headache. You don't want to connect to external Database server and still wish you could just create a table and save objects as quickly as possible. You hate writing SQL for trivial CRUD but still want to be able to harness the power of SQL when need be. You can then try Gstorm.
Gstorm take very simple approach to solve this problem by focusing just on needs of persistence mechanism required for small scripts.
The market is already flooded with ORMs and NoSQL databases. It's pointless to introduce anything that's heavy, complex, rigid and tries to solve all the problems in the world.
- Creates Tables for you
- Allows you to persist objects without worrying about CRUD SQL statements (so cliche !!)
- Very light layer, no jar baggage
- Can still fire complex SQL queries that would have been difficult in NoSQL or plain collection backed DBs
- Typically this would be useful in scripts, Not in multi-layered web applications or any complex scenario
- Doesn't handle any relationships or complex data types
Gstorm uses HSQLDB syntax internally.
##Getting started
Grab GStorm using
@GrabResolver(name='gstorm', root='http://kdabir.github.io/mavenrepo/') @Grab('gstorm:gstorm:0.3')
Include hsqldb
@GrabConfig(systemClassLoader = true) @Grab('org.hsqldb:hsqldb:2.2.9')
and gstormify your model
new Gstorm(sql).stormify(Person)
where sql
is an instance of groovy.sql.Sql
Just go through the example's source and test and have fun.
Gstorm is just few days old and few groovy lines long. There is long list of items that I would want to complete before calling it feature complete. The project is in development mode and should not be used in any production scenarios.
enableQueryLogging
to enable sql query loggingget()
to load a model by id
- autogenerated
id
property on model - ability to
update()
orsave()
when model hasid
- using gradle to publish to maven repo
- travis ci
- added
all
method/property
- initial prototype
save()
andwhere()
methods added