Skip to content

Instantly share code, notes, and snippets.

@vojtech-dobes
Created July 28, 2011 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojtech-dobes/1111705 to your computer and use it in GitHub Desktop.
Save vojtech-dobes/1111705 to your computer and use it in GitHub Desktop.
Fetch the user: MySql vs CouchDB
SELECT `*` FROM `users` WHERE `username` = "john@doe.com" AND `password` = "xxx"
// design document
{
"_id": "_design/user",
"_rev": ... something ...,
"language": "javascript",
"views": {
"credentials": {
"map": "function (doc) {
if (doc.type == 'user') {
emit([doc.username, doc.password], null);
}
}"
}
}
}
// user document
{
"_id": ... something ...,
"_rev": ... something ...,
"type": "user",
"username": "john@doe.com",
"password": "xxx"
}
// http://127.0.0.1:5984/db_name/_design/user/_view/credentials?key=["john@doe.com","xxx"]&include_docs=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment