CodeFest 2010. Билык В. — CouchDB: от теории к практике

Post on 22-Jun-2015

1.448 views 0 download

Transcript of CodeFest 2010. Билык В. — CouchDB: от теории к практике

“The learning curve for CouchDB is quite shallow”

“The only drawback is that you may need to do a lot of unlearning if you're well versed in SQL”

Keys&Values

{ "type": "passport", "id": "F7802033", "countryCode": "IND", "surname": "Rai", "givenNames": [ "Aishwarya" ], "sex": "F", "birthDate": "01/11/1973", "placeOfIssue": "Mumbai"}

{ "type": "passport", "id": "F7802033", "countryCode": "IND", "surname": "Rai", "givenNames": [ "Aishwarya" ], "sex": "F", "birthDate": "01/11/1973", "placeOfIssue": "Mumbai"}

{ "type": "passport", "id": "F7802033", "countryCode": "IND", "surname": "Rai", "givenNames": [ "Aishwarya" ], "sex": "F", "birthDate": "01/11/1973", "placeOfIssue": "Mumbai"}

function(doc){ if (doc.type == ʻpassportʼ) { emit(doc._id, doc); }}

{ "total_rows": 100500, "offset": 0, "rows": [ { "id": "F7802033", "key": "F7802033", "value": { "_id": "F7802033", "type": "passport", "countryCode": "IND", "surname": "Rai", ... } },...

function(doc){ if (doc.type == ʻpassportʼ) { emit(doc._id, null); }}

{ "total_rows": 100500, "offset": 0, "rows": [ { "id": "F7802033", "key": "F7802033", "value": null },...

... "rows": [{ "id": "F7802033", "key": "F7802033", "value": null, "doc": { "_id": "F7802033", "type": "passport", "countryCode": "IND", "surname": "Rai", ... } },...

?include_docs=true

?skip=100&limit=10

...skip...skip... ...skip...skip...

!

?startkey=foo&limit=11

!... ...

{ "_id": "FFE2...", "type": "post", "title": "Умники и умницы CodeFest", "text": "Сегодня пятница, а значит осталась всего неделя до CodeFest в Новосибирске..." ...}

{ "type": "comment", "post": "FFE2...", "text": "Хотелось бы сходить." ...}

{ "type": "comment", "post": "FFE2...", "text": "Обязательно буду!" ...}

function(doc){ if (doc.type == ʻpostʼ) {

emit([doc._id,0], null);

} else if (doc.type == ʼcommentʼ) {

emit([doc.post,1], null);

}}

["FFE2...",0] → {"type": "post", "title": "Умники и умницы CodeFest" ...}

["FFE2...",1] → {"type": "comment", "text": "Хотелось бы сходить."...}

["FFE2...",1] → {"type": "comment", "text": "Обязательно буду!"...}

Остроумный коментарий-42?anonymous {

"type": "comment_rating", "comment": "ABE2...", "rating": -1 ...}

function( doc ) {

if (doc.type == ʼcomment_ratingʼ ) {emit(doc.comment, doc.rating);

}}

function( keys, values ) { return sum(values);}

GQL: SELECT * FROM Person WHERE birth_year >= :min_year AND height >= :min_height #ERROR

["heavy",191] → {"type": "boxer", "name": "David Deron Haye" ...}...["heavy",201] → {"type": "boxer", "name": "Vitaliy Klychko" ...}...["heavy",213] → {"type": "boxer", "name": "Nikolai Valuev" ...}

function( doc ) {if (doc.type == ʼorderʼ ) {

for(i in doc.orderLines) {for(j in doc.orderLines) {

if ( i != j ) {emit([ doc.orderLines[i].article, doc.orderLines[j].article ], 1);

}

......

Cartesian explosion