crea il tuo database con leveldb e node.js
DESCRIPTION
Avete mai pensato di scrivere un vostro database? Un Key/Value store, o un database documentale? Oppure un Graph DB? O magari volete un database che si sincronizzi fra Browser e Server in modo trasparente? Nodebase è il movimento che fa per voi! Un gruppo di mad scientist nella comunità Node.js hanno preso l'ultraveloce LevelDB e hanno sviluppato decine di piccole librerie che consentono di aggiungerci tutte le funzionalità di cui avete bisogno, dalla replicazione all'indicizzazione: stiamo parlando di LevelUp!TRANSCRIPT
![Page 1: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/1.jpg)
Problemi con il Database?
http://500px.com/photo/27874937@matteocollina
![Page 3: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/3.jpg)
Costruisci il TUO database con
![Page 4: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/4.jpg)
Level*
Costruisci il TUO database con
![Page 5: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/5.jpg)
Storia*
Not
a D
atab
ase
![Page 6: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/6.jpg)
Storia dei DB• 1960s: Dai nastri ai dischi per raggiungere accesso condiviso e interattività
• Late 1960s: Navigational Databases, links
• Early 1970s: Modello relazionale, content
• Late 1970s: SQL
• Early 1980s: Un database sul mio Desktop
• Late 1980s: Object Oriented Database
• 2000s: velocità e scalabilità, NoSQL
• Early 2010s: non perdiamo una bella astrazione, NewSQLs
![Page 7: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/7.jpg)
La tirannia delle belle astrazioni
![Page 8: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/8.jpg)
Che cos’è un DB?
![Page 9: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/9.jpg)
Uno strumento per interagire con dati strutturati, all’esterno del
core della nostra Applicazione
![Page 10: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/10.jpg)
Core DB features
• Persistenza
• Prestazione
• Semplificazione dell’accesso ai dati complessi
![Page 11: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/11.jpg)
• Small Core, vibrant community
• Extreme modularity
• Reimplement everything in Javascript
![Page 12: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/12.jpg)
Il Node.js dei DB?
• Small Core: LevelUp - http://npm.im/levelup
• TUTTO è un modulo, scaricabile da NPM
• Sperimentazione di molti aspetti sia della teorica che della pratica dei database e dei sistemi distribuiti
• Soluzioni specifiche
![Page 13: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/13.jpg)
![Page 15: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/15.jpg)
LevelDB• Open-source, embedded key/value store di Google
• Chiavi ordinate
• Valori compressi da Snappy
• Operazioni basilari: Get(), Put(), Del()
• Batch() Atomica
• Iterazioni bi-direzionali
![Page 16: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/16.jpg)
LevelDB
![Page 17: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/17.jpg)
LevelUP• Ispirato da LevelDB
• Supportato da un a key/value store per dati arbitrari, ordinati per chiave
• put(), get(), del()
• Scritture atomiche via batch()
• ReadStream: l’ingrediente segreto
• WriteStream: per comodità
• Encoding: UTF-8, HEX, Binary, JSON, Typewise, your encoding.
![Page 18: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/18.jpg)
ReadStream
• La primitiva essenziale per tutte le feature più complesse, ad esempio LevelGraph la usa per realizzare i JOIN.
• E’ la primitiva fondamentale per accedere ai dati ordinati.
• E’ possibile limitare il range tramite start e end
![Page 19: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/19.jpg)
ReadStream
db.createReadStream({ start: 'Bol', end: 'Bol\xff' })
.on('data', function (entry) {
console.log(entry.key)
})
!
// → Bologna
// → Bolzano
![Page 20: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/20.jpg)
Key Structure• L’ordinamento e il recupero delle chiavi richiede un key
design
• Le chiavi sono un descrittore gerarchico del contenuto:
'countries~Ireland' 'countries~Italy' ... 'towns~Italy~Bologna' 'towns~Italy~Bolzano' ... 'streets~Italy~Bologna~Via Indipendenza' 'streets~Italy~Bologna~Via Rizzoli'
![Page 23: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/23.jpg)
BDFL: @rvagg
![Page 24: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/24.jpg)
Level* Committers
![Page 25: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/25.jpg)
RocksDB
• Rilasciato Open Source il 14 Novembre 2013.
• Il 14 Novembre 2013 è già disponibile il “driver” per LevelUp, http://npm.im/rocksdb
• RocksDB è un fork di LevelDB per gestire terabyte di dati
![Page 26: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/26.jpg)
@matteocollina
![Page 27: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/27.jpg)
LevelGraph
![Page 28: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/28.jpg)
LevelGraph
db.join([{ subject: db.v(“a"), predicate: “friend",object: db.v(“x") }, {
subject: db.v(“x"), predicate: “friend", object: db.v(“y") }],
function(err, results) {
// this will print all the 'friend of a friend triples..'
});
![Page 29: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/29.jpg)
- Francesco Fullone - Enrico Zimuel -- Federico Galassi - Matteo Collina -
JavaScriptbest practices
http://www.jsbestpractices.it/
![Page 30: Crea il TUO database con LevelDB e Node.js](https://reader031.vdocuments.pub/reader031/viewer/2022020110/5562d2d6d8b42a49398b4d3e/html5/thumbnails/30.jpg)
@matteocollina @rvagg