<commit_before>package com.tobykurien.sparkler_example

import com.tobykurien.sparkler.db.DatabaseManager
import com.tobykurien.sparkler.db.Model
import com.tobykurien.sparkler.transformer.JsonModelTransformer

import static com.tobykurien.sparkler.Sparkler.*

/**
 * A simple RESTful example showing howto create, get, update and delete book resources.
 * The database configuration is stored in /config/database.yml
 * 
 * @see http://code.google.com/p/spark-java/#Examples
 */
class Example2 {
   def static void main(String[] args) {
      DatabaseManager.init(Example2.package.name) // init db with package containing db models
      val book = Model.with(typeof(Book)) // get reference to ModelContext for Book
      
      // Gets all available book resources (id's)
      get(new JsonModelTransformer("/books") [req, res|
         // JsonModelTransform can take a Model (or LazyList of Models) and generate JSON
         book.findAll
      ])
       
      // Gets the book resource for the provided id
      get(new JsonModelTransformer("/books/:id") [req, res|
         book.findById(req.params("id")) as Book
      ])
      
      // Creates a new book resource, will return the ID to the created resource
      // author and title are sent as query parameters e.g. /books?author=Foo&title=Bar
      post(new JsonModelTransformer("/books") [req, res|
         book.createIt(
            "title", req.queryParams("title"),
            "author", req.queryParams("author")) as Book         
      ])
      
      // Updates the book resource for the provided id with new information
      // author and title are sent as query parameters e.g. /books/<id>?author=Foo&title=Bar<commit_msg>removed unnecessary typecasts, updated comments<commit_after>package com.tobykurien.sparkler_example

import com.tobykurien.sparkler.db.DatabaseManager
import com.tobykurien.sparkler.db.Model
import com.tobykurien.sparkler.transformer.JsonModelTransformer

import static com.tobykurien.sparkler.Sparkler.*

/**
 * A simple RESTful example showing howto create, get, update and delete book resources.
 * The database configuration is stored in /config/database.yml
 * Manage the database by running (from project root): java -jar libs/h2-1.3.174.jar
 * 
 * @see http://code.google.com/p/spark-java/#Examples
 */
class Example2 {
   def static void main(String[] args) {
      DatabaseManager.init(Example2.package.name) // init db with package containing db models
      val book = Model.with(typeof(Book)) // get reference to ModelContext for Book
      
      // Gets all available book resources (id's)
      get(new JsonModelTransformer("/books") [req, res|
         // JsonModelTransform provides db connection, and can take a Model 
         // (or LazyList of Models) and generate JSON
         book.findAll
      ])
       
      // Gets the book resource for the provided id
      get(new JsonModelTransformer("/books/:id") [req, res|
         book.findById(req.params("id"))
      ])
      
      // Creates a new book resource, will return the ID to the created resource
      // author and title are sent as query parameters e.g. /books?author=Foo&title=Bar
      get(new JsonModelTransformer("/books+") [req, res|
         book.createIt(
            "title", req.queryParams("title"),
            "author", req.queryParams("author"))     
      ])
      
      // Updates the book resource for the provided id with new information
      // author and title are sent as query parameters e.g. /books/<id>?author=Foo&title=Bar
{'fraction_non_alphanumeric': 0.10056657223796034, 'fraction_numerical': 0.0028328611898017, 'mean_word_length': 2.910299003322259, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '417485', 'n_tokens_mistral': 1009, 'n_tokens_neox': 981, 'n_words': 314}