Created
January 7, 2011 22:26
-
-
Save timvisher/770222 to your computer and use it in GitHub Desktop.
This file contains 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
import com.gmongo.GMongo | |
class Details { | |
def weight; | |
def weight_units; | |
def model_num; | |
Details(weight, weight_units, model_num) { | |
this.weight = weight; | |
this.weight_units = weight_units; | |
this.model_num = model_num; | |
} | |
} | |
class Price { | |
def retail; | |
def sale; | |
Price(retail, sale) { | |
this.retail = retail; | |
this.sale = sale; | |
} | |
} | |
class Category { | |
def slug; | |
def parents; | |
def name; | |
def description; | |
Category(slug, parents, name, description) { | |
this.slug = slug; | |
this.parents = parents; | |
this.name = name; | |
this.description = description; | |
} | |
} | |
class Product { | |
// Shouldn't be needed because the driver provides it for us | |
// def _id | |
def slug; | |
def sku; | |
def name; | |
def details; | |
def tags; | |
def price; | |
def priceHistory; | |
def categoryIds; | |
def averageReview; | |
Product (slug, sku, name, details, tags, price, priceHistory, categoryIds, averageReview) { | |
this.slug = slug; | |
this.sku = sku; | |
this.name = name; | |
this.details = details; | |
this.tags = tags; | |
this.price = price; | |
this.priceHistory = priceHistory; | |
this.categoryIds = categoryIds; | |
this.averageReview = averageReview; | |
} | |
} | |
//Demo | |
//Set up DB Connection | |
mongo = new GMongo() | |
mongo.dropDatabase('ecommerce') | |
db = mongo.getDB('ecommerce') | |
def categories = [new Category("home", null, "Home", null), | |
new Category("outdoors", null, "Outdoors", null)]; | |
categories << new Category("gardeningTools", | |
[categories[0], categories[1]], | |
"Gardening Tools", | |
"Gardening gadgets galore!"); | |
db.categories << categories | |
assert 3 == db.categories.count | |
//def products = [ | |
new Product("1", | |
"1", | |
"Extra Large Wheel Barrow", | |
"Heavy Duty Wheelbarrow", | |
new Details(47, "lbs", 1), | |
["tools", "equipment", "soil"], | |
new Price(589700, 489700), | |
[new Price(529700, 429700), new Price(469700, 369700)], | |
categories[2])// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment