luggage
Dropbox file API wrapper for storing json data.
Have you ever noticed that their stuff is shit and your shit is stuff?
(George Carlin)
Usage
const backend = new DropboxBackend(token);
const store = new Luggage(backend);
const articles = store.collection('articles');
Filtering
articles.where({ author: 'John Doe' }).read().then((articles) => {
console.log('John\'s articles:', articles);
});
articles.where(article => article.authors.includes('John Doe')).read().then((articles) => {
console.log('John\'s articles:', articles);
});
articles.where({ author: 'John Doe' }).on('data', (articles) => {
console.log('John\'s articles:', articles);
});
articles.where({ author: 'John Doe' }).where(article => article.comments > 0)
articles.where({ author: 'John Doe' }).and(article => article.comments > 0)
Finding single record
articles.find({ author: 'John Doe' }).read().then((article) => {
console.log('John\'s article:', article);
});
articles.find(article => article.author === 'John Doe').read().then((article) => {
console.log('John\'s article:', article);
});
articles.find({ author: 'John Doe' }).on('data', (article) => {
console.log('John\'s article:', article);
});
Updating record
articles.find({ id: 1 }).update({ author: 'Jane Doe' }).then(([article]) => {
console.log('Author changed:', article.author);
});
articles.find(article => article.id === 42).update((article) => {
article.authors.push('Jane Doe');
return article;
})
Adding new record
articles.add({ author: 'John Doe', body: 'Blah blah blah mr. Freeman' }).then(([article]) => {
console.log('New article was added:', article);
});
Deleting record
articles.find({ id: 1 }).delete().then(([article]) => {
console.log('No longer within collection:', article);
});