- dataStore.js
- livrosdb.json
Created
September 15, 2017 00:52
-
-
Save rpragana/66b5efccddce108c514248bbe3ec48ba to your computer and use it in GitHub Desktop.
Data-store nodejs module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var livrosdb = require('data-store')('livrosdb',{cwd: 'db'}) | |
var livros = [ | |
{ | |
"titulo": "Essential System Administration", | |
"autor": "Aeleen Frisch", | |
"ano": "2002" | |
}, | |
{ | |
"titulo": "Linux - The Complete Reference", | |
"autor": "Richard Petersen", | |
"ano": "2008" | |
}, | |
{ | |
"titulo": "Speaking Javascript", | |
"autor": "Axel Rauschmayer", | |
"ano": "2014" | |
} | |
]; | |
if (livrosdb.has('livros')) { | |
livros = livrosdb.get('livros') | |
} else { | |
console.log('criando a definição de livros') | |
livrosdb.set('livros',livros) | |
livrosdb.save() | |
} | |
livrosdb.set('font-size',16) | |
livrosdb.set('font-weight',"medium") | |
livrosdb.set('temp',999) | |
livrosdb.union('font-size',22) | |
livrosdb.del('temp') | |
console.log("Resultado de livrosdb.get():") | |
console.log(livrosdb.get()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"livros": [ | |
{ | |
"titulo": "Essential System Administration", | |
"autor": "Aeleen Frisch", | |
"ano": "2002" | |
}, | |
{ | |
"titulo": "Linux - The Complete Reference", | |
"autor": "Richard Petersen", | |
"ano": "2008" | |
}, | |
{ | |
"titulo": "Speaking Javascript", | |
"autor": "Axel Rauschmayer", | |
"ano": "2014" | |
} | |
], | |
"font-size": [ | |
16, | |
22 | |
], | |
"font-weight": "medium" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment