// retoor <retoor@molodetz.nl>
import "dataset" for Dataset
var ds = Dataset.memory()
var products = ds["products"]
for (i in 1..50) {
products.insert({
"name": "Product %(i)",
"price": i * 10,
"category": i % 3 == 0 ? "A" : (i % 3 == 1 ? "B" : "C"),
"active": i % 2 == 0
})
}
System.print(products.count()) // expect: 50
var expensive = products.find({"price__gte": 400})
System.print(expensive.count) // expect: 11
var categoryA = products.find({"category": "A"})
System.print(categoryA.count) // expect: 16
var combined = products.find({"price__gte": 200, "price__lte": 300, "category": "B"})
System.print(combined.count) // expect: 3
var inList = products.find({"name__in": ["Product 1", "Product 10", "Product 50"]})
System.print(inList.count) // expect: 3
var like = products.find({"name__like": "Product 1\%"})
System.print(like.count) // expect: 11
var notEqual = products.find({"category__ne": "A", "active": true})
System.print(notEqual.count) // expect: 17
ds.close()