|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "dataset" for Dataset
|
|
|
|
var ds = Dataset.memory()
|
|
var users = ds["users"]
|
|
|
|
var emptyAll = users.all()
|
|
System.print(emptyAll.count) // expect: 0
|
|
|
|
System.print(users.count()) // expect: 0
|
|
|
|
var user = users.insert({"name": "Alice", "score": 100})
|
|
|
|
var notFound = users.findOne({"name": "Nobody"})
|
|
System.print(notFound == null) // expect: true
|
|
|
|
var emptyFind = users.find({"name": "Nobody"})
|
|
System.print(emptyFind.count) // expect: 0
|
|
System.print(emptyFind is List) // expect: true
|
|
var uid = user["uid"]
|
|
|
|
var changes1 = users.update({"uid": uid, "score": 200})
|
|
System.print(changes1) // expect: 1
|
|
|
|
var changes2 = users.update({"uid": uid, "score": 300, "level": 5})
|
|
System.print(changes2) // expect: 1
|
|
|
|
var updated = users.findOne({"uid": uid})
|
|
System.print(updated["score"]) // expect: 300
|
|
System.print(updated["level"]) // expect: 5
|
|
|
|
var fakeChanges = users.update({"uid": "nonexistent-uid", "score": 999})
|
|
System.print(fakeChanges) // expect: 0
|
|
|
|
System.print(users.delete("nonexistent-uid")) // expect: false
|
|
|
|
ds.close()
|