Crea il TUO database con LevelDB e Node.js

30
Problemi con il Database? http://500px.com/photo/27874937 @matteocollina

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 of Crea il TUO database con LevelDB e Node.js

Page 1: Crea il TUO database con LevelDB e Node.js

Problemi con il Database?

http://500px.com/photo/27874937@matteocollina

Page 2: Crea il TUO database con LevelDB e Node.js

Chiami un consulente?

http://500px.com/photo/22823315

Page 3: Crea il TUO database con LevelDB e Node.js

Costruisci il TUO database con

Page 4: Crea il TUO database con LevelDB e Node.js

Level*

Costruisci il TUO database con

Page 5: Crea il TUO database con LevelDB e Node.js

Storia*

Not

a D

atab

ase

Page 6: Crea il TUO database con LevelDB e Node.js

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

La tirannia delle belle astrazioni

Page 8: Crea il TUO database con LevelDB e Node.js

Che cos’è un DB?

Page 9: Crea il TUO database con LevelDB e Node.js

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

Core DB features

• Persistenza

• Prestazione

• Semplificazione dell’accesso ai dati complessi

Page 11: Crea il TUO database con LevelDB e Node.js

• Small Core, vibrant community

• Extreme modularity

• Reimplement everything in Javascript

Page 12: Crea il TUO database con LevelDB e Node.js

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
Page 14: Crea il TUO database con LevelDB e Node.js

http://500px.com/photo/50810860

Page 15: Crea il TUO database con LevelDB e Node.js

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

LevelDB

Page 17: Crea il TUO database con LevelDB e Node.js

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

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

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

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 21: Crea il TUO database con LevelDB e Node.js

http://npm.im/levelmeup

Page 22: Crea il TUO database con LevelDB e Node.js

levelmeup @ nodeconf.eu

Page 23: Crea il TUO database con LevelDB e Node.js

BDFL: @rvagg

Page 24: Crea il TUO database con LevelDB e Node.js

Level* Committers

Page 25: Crea il TUO database con LevelDB e Node.js

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

@matteocollina

Page 27: Crea il TUO database con LevelDB e Node.js

LevelGraph

Page 28: Crea il TUO database con LevelDB e Node.js

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

- 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

@matteocollina @rvagg