Skip to content

Instantly share code, notes, and snippets.

@jwill
Created July 28, 2009 23:56
Show Gist options
  • Save jwill/157763 to your computer and use it in GitHub Desktop.
Save jwill/157763 to your computer and use it in GitHub Desktop.
def setupDB = {
model.db = new FeatherDB(new FileSystemBackend())
if (!model.backend.doesDatabaseExist("testdb")) {
try {
model.db.addDatabase("testdb")
} catch (Exception ex) {
ex.printStackTrace()
}
}
}
def populateDB = {
def d = (JSONDocument) Document.newDocument(model.backend, "testdb", "task1", "sa")
["title":"Task1", "text":"Go to supermarket"].each {d.put(it.key, it.value) }
def d2 = (JSONDocument) Document.newDocument(model.backend, "testdb", "task2", "sa")
["title":"Task2", "text":"Go to store"].each {d2.put(it.key, it.value) }
def d3 = (JSONDocument) Document.newDocument(model.backend, "testdb", "task3", "sa")
["title":"Task3", "text":"Go to work", "deadline":new Date()+1].each {d2.put(it.key, it.value) }
[d,d2,d3].each {model.db.getBackend().saveDocument(it) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment