0.3.27 • Published 3 years ago
sandstorm v0.3.27
Sandstorm
Installation
$ npm i sandstorm
Usage
Adding new schema
const sandstorm = new Sandstorm();
sandstorm.register("Author", {
name: {
type: "String",
required: true,
min: 3,
max: 64
},
last_name: {
type: "String",
required: true,
min: 3,
max: 64
},
nick: "String"
});
sandstorm.register("Book", {
title: {
type: "String",
required: true,
max: 256
},
author: {
type: "Author",
required: true,
search: [
"name",
"last_name",
"nick"
]
}
});
Creating new models
const book = sandstorm.create("Book");
book.set({title: "The Art of Deception",
author: {
last_name: "Mitnick",
name: "Kevin"
}
}).then(() => book.save()).then((_id) => {
console.log("ObjectID of saved book", _id);
}).catch((err) => {
console.error("Ups", err);
});
Finding documents
sandstorm.find("Book", {"author.name": "Kevin"}).toArray().then((docs) => {
console.log("Books written by Kevin", docs.map(book => book.title)).join(", ");
}).catch((err) => {
console.error("Ups", err);
});
Updating
Use merge
to update only chosen fields or set
to overwrite whole document
book.merge({title: "The Art of Deception: Controling the Human Element of Security"})
.then(() => book.save()).then((_id) => {
console.log("ObjectID of saved book", _id);
}).catch((err) => {
console.error("Ups", err);
});
Deleting
sandstorm.find("Book", {"author.name": "Kevin"}).toArray()
.then((docs) => Promise.all(docs.map(book => book.delete())).then(() => {
console.log("All documents deleted");
})).catch((err) => {
console.error("Ups", err);
});
0.3.27
3 years ago
0.3.26
3 years ago
0.3.25
4 years ago
0.3.24
4 years ago
0.3.23
4 years ago
0.3.22
5 years ago
0.3.21
5 years ago
0.3.20
5 years ago
0.3.19
5 years ago
0.3.18
5 years ago
0.3.17
5 years ago
0.3.16
5 years ago
0.3.15
5 years ago
0.3.14
5 years ago
0.3.13
5 years ago
0.3.12
6 years ago
0.3.11
6 years ago
0.3.10
6 years ago
0.3.9
6 years ago
0.3.8
6 years ago
0.3.7
6 years ago
0.4.0-alpha
6 years ago
0.3.6
6 years ago
0.3.5
6 years ago
0.3.4
6 years ago
0.3.3
6 years ago
0.3.2
6 years ago
0.3.1
6 years ago
0.3.0
6 years ago
0.2.11
6 years ago
0.2.10
6 years ago
0.2.9
6 years ago
0.2.8
6 years ago
0.2.7
6 years ago
0.2.6
6 years ago
0.2.5
6 years ago
0.2.4
6 years ago
0.2.3
6 years ago
0.2.2
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago