Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the best practice ? (beginner question) #34

Open
k33g opened this issue Jun 3, 2012 · 0 comments
Open

What is the best practice ? (beginner question) #34

k33g opened this issue Jun 3, 2012 · 0 comments

Comments

@k33g
Copy link

k33g commented Jun 3, 2012

Hello
I wish I knew what was best if I make an application with Express (for example) :

  • i need a "model"
  • i need to save each instance of model

do I have to, every time I save, do a :

var mystore = nStore.new("data/blog.db", function() {
    mystore.save(null, myModel, function(err, key){ ... });
});

or I declare, initially, a global variable (for example) then I use in my modelsUndo edits :

global.blogStore = nStore.new("data/blog.db", function() {
    app.get('/add',function(req, res){

        var model_from_client = JSON.parse(req.param("model", null));       
        var post = new Post(model_from_client.title, model_from_client.message);

        post.save(function(key){
            console.log("Post added with key : ", key)
        });

    });

    app.listen(3000);
    console.log('Express app started on port 3000');    
});

and with :

var Post = function (title, message) {
    this.title = title ? title : "";
    this.message = message ? message : "";

    this.save = function(callback) {
        blogStore.save(null,this,function(err, key){
            callback(key, err);
        });
    }
}

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant