let dbname = "mydatabase"
database(dbname).drop();
let db = database(dbname)
assert(db.$name, dbname, "db.$name !== '${dbname}'")
let tasks = database(dbname).collection("tasks")
let newTask = database(dbname)
.collection("tasks")
.push({ id: 1, text: "Task #1", completed: false }, result => {
console.log(result.$key)
})
let newTasks = database(dbname)
.collection("tasks")
.pushMany([
{ id: 2, text: "Task #2", completed: false },
{ id: 3, text: "Task #3", completed: true },
{ id: 4, text: "Task #4", completed: false },
{ id: 5, text: "Task #5", completed: true }
], result => {
console.log(result.length)
})
database(dbname).collection("tasks").find().then(result => {
console.log(result.data().length)
})
database(dbname).collection("tasks").find().then(result => {
console.log(result.first().$key.length)
})
database(dbname).collection("tasks").find({ completed: true })
.then(result => {
console.log(result.data().length)
})
database(dbname).collection("tasks").find({ completed: false })
.then(result => {
console.log(result.data().length)
})
database(dbname).collection("tasks").find({ completed: false, id: 1 })
.then(result => {
console.log(result.data().length)
})
database(dbname).collection("tasks").find({ completed: true, id: 1 })
.then(result => {
assert(result.data().length, 0)
done()
})
database(dbname).collection("tasks").find({ completed: false, id: 1 })
.then(result => {
console.log(result.first().$key.length)
})
database(dbname).collection("tasks")
.find({ completed: false, id: 1 }).then(result => {
let updated = result.first().update({ completed: true }, entry => {
console.log(updated.$key)
})
})
let collection = database(dbname).collection("tasks")
collection.find({ id: 1 }).then(result => {
result.first().delete().then(() => {
collection.find().then(result => {
console.log(result.data().length)
})
})
})
collection.truncate().then(() => {
collection.find().then(result => {
console.log(result.data().length)
})
})
database(dbname).drop()
console.log(localStorage.mydatabase)