0.3.28 • Published 8 months ago
sandstorm v0.3.28
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.28
8 months ago
0.3.27
4 years ago
0.3.26
4 years ago
0.3.25
5 years ago
0.3.24
5 years ago
0.3.23
5 years ago
0.3.22
6 years ago
0.3.21
6 years ago
0.3.20
6 years ago
0.3.19
6 years ago
0.3.18
6 years ago
0.3.17
6 years ago
0.3.16
6 years ago
0.3.15
6 years ago
0.3.14
6 years ago
0.3.13
7 years ago
0.3.12
7 years ago
0.3.11
7 years ago
0.3.10
7 years ago
0.3.9
7 years ago
0.3.8
7 years ago
0.3.7
7 years ago
0.4.0-alpha
7 years ago
0.3.6
7 years ago
0.3.5
7 years ago
0.3.4
7 years ago
0.3.3
7 years ago
0.3.2
7 years ago
0.3.1
7 years ago
0.3.0
7 years ago
0.2.11
7 years ago
0.2.10
7 years ago
0.2.9
7 years ago
0.2.8
7 years ago
0.2.7
7 years ago
0.2.6
7 years ago
0.2.5
7 years ago
0.2.4
7 years ago
0.2.3
7 years ago
0.2.2
7 years ago
0.2.1
7 years ago
0.2.0
7 years ago
0.1.4
7 years ago
0.1.3
7 years ago
0.1.2
7 years ago
0.1.1
7 years ago
0.1.0
7 years ago
0.0.3
7 years ago
0.0.2
8 years ago