Permalink
Browse files

scopes, less code, built-in cache removal(temporary), keys declaration

  • Loading branch information...
1 parent 884d03c commit 8b3c8e8f1a87c592bddbfb55d6074e0474aa6362 @vadimdemedes committed May 3, 2012
View
@@ -5,7 +5,6 @@
# Features
- Define models, and operate with them just like usual objects, forget about documentation
-- Built-in caching, using [Memcacher](https://github.com/vdemedes/memcacher)
- Based on Mongolian
- Super-fast, lightweight, all codebase is in one file
- Covered by tests
@@ -23,11 +22,12 @@ npm install mongorito
Mongorito = require 'mongorito'
Mongorito.connect ['mongo://user:password@127.0.0.1:27017/databaseName']
-Mongorito.cache ['127.0.0.1:11211'] # optional, allows automatic caching. It is just one line to enable it!
class Post
- constructor: ->
- super 'posts' # telling our collection name
+ keys: ['author', 'title']
+ scopes:
+ one: limit: 1
+ latest: title: 'Just created'
Post = Mongorito.bake Post # Now, we are ready to go!
@@ -44,7 +44,7 @@ post.save (err) ->
post.remove ->
# removed!
-Post.find title : 'Some title!', (err, posts) ->
+Post.find title: 'Some title!', (err, posts) ->
for post in posts
# post is an instance of Post model, so you can perform usual methods on it
post.remove ->
@@ -54,46 +54,6 @@ Post.find title : 'Some title!', (err, posts) ->
Check out **examples** folder, it has a lot of code, which describes all parts of Mongorito.
-# For pure JS folks
-
-Honestly, Mongorito was not developed with "JS" in mind. Mongorito is for CoffeeScript developers. But, in case you have no other choice:
-
-```javascript
-var Mongorito = require('mongorito');
-
-Mongorito.connect(['mongo://user:password@127.0.0.1:27017/databaseName']);
-Mongorito.cache(['127.0.0.1:11211']);
-
-var Post = (function(){
-
- function Post(){ // constructor
- Post.__super__.constructor.call(this, 'posts');
- }
-
- Post.prototype.validateTitle = function(callback){ // declare methods, like this
- if(! this.title) {
- callback(false);
- } else {
- callback(true);
- }
- }
-
- return Post;
-
-})();
-
-Post = Mongorito.bake(Post); // Now, we are ready to go!
-
-Post.find(function(err, posts){
- var length = posts.length;
- for(var i = 0; i < length; i++) {
- posts[i].remove(function(){ // posts[i] is an instance of Post class, so you can operate with it as a model
- // removed
- });
- }
-});
-```
-
# Tests
Tests made using Mocha. Run using:
@@ -102,6 +62,10 @@ Tests made using Mocha. Run using:
mocha
```
+# Todo
+
+- Connecting to Replica Sets
+- Built-in caching
# License
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -3,7 +3,5 @@ Mongorito = require '../lib/mongorito'
Mongorito.connect ['mongo://127.0.0.1:27017/databaseName']
class Post
- constructor: ->
- super 'posts' # REQUIRED STEP
Post = Mongorito.bake Post # REQUIRED STEP
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3,8 +3,6 @@ Mongorito = require '../lib/mongorito'
Mongorito.connect ['mongo://127.0.0.1:27017/databaseName']
class Post
- constructor: ->
- super 'posts'
beforeCreate: -> # before creating post
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -3,8 +3,7 @@ Mongorito = require '../lib/mongorito'
Mongorito.connect ['mongo://127.0.0.1:27017/databaseName']
class Post
- constructor: ->
- super 'posts'
+ keys: ['title', 'content']
Post = Mongorito.bake Post
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3,8 +3,7 @@ Mongorito = require '../lib/mongorito'
Mongorito.connect ['mongo://127.0.0.1:27017/databaseName']
class Post
- constructor: ->
- super 'posts'
+ keys: ['title', 'author', 'content']
Post = Mongorito.bake Post
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,17 @@
+Mongorito = require '../lib/mongorito'
+
+Mongorito.connect ['mongo://127.0.0.1:27017/databaseName']
+
+class Post
+ keys: ['author', 'content', 'title']
+ scopes:
+ byDrew: author: 'Drew'
+ one: limit: 1
+
+Post = Mongorito.bake Post
+
+Post.one (err, posts) ->
+ posts.length is 1
+
+Post.byDrew (err, posts) ->
+ # posts with author=Drew
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -3,8 +3,7 @@ Mongorito = require '../lib/mongorito'
Mongorito.connect ['mongo://127.0.0.1:27017/databaseName']
class Tweet
- constructor: ->
- super 'tweets'
+ keys: ['body']
validateBody: (callback) -> # you should pass false, if invalid and true, if valid
if @body.length >= 140
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 8b3c8e8

Please sign in to comment.