|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "dataset" for Dataset
|
|
import "io" for File
|
|
|
|
var dbPath = "/tmp/test_dataset.db"
|
|
|
|
if (File.exists(dbPath)) {
|
|
File.delete(dbPath)
|
|
}
|
|
|
|
var ds = Dataset.open(dbPath)
|
|
var users = ds["users"]
|
|
|
|
var user = users.insert({"name": "Alice", "score": 100})
|
|
System.print(user["name"]) // expect: Alice
|
|
System.print(users.count()) // expect: 1
|
|
|
|
ds.close()
|
|
|
|
System.print(File.exists(dbPath)) // expect: true
|
|
|
|
var ds2 = Dataset.open(dbPath)
|
|
var users2 = ds2["users"]
|
|
|
|
System.print(users2.count()) // expect: 1
|
|
var found = users2.findOne({"name": "Alice"})
|
|
System.print(found["score"]) // expect: 100
|
|
|
|
ds2.close()
|
|
|
|
File.delete(dbPath)
|
|
System.print(File.exists(dbPath)) // expect: false
|