Since working with databases shouldn't be much work, spludo-gen comes with
a task to generate a Service + DomainModels right out of the database
connection.
$ spludo-gen service
Template: service
The database connection name [default]:
The name for your service (e.g. User): User
The database table name (e.g. users): users
The table field for the id [id]:
...
Finished!
User your new service now with:
var user_service = service_manager.get('User');
user_service.getUserById(function(user) {
console.log(user);
}, 1234);
Now you can use this service. The generated classes is a file calles
lib/services/UserService.js which holds to classes.
The UserService is returned by service_manager.get('User') and
has handy methods to getUserById(id), deleteUser(user),
updateUser(user, values).
It also contains a User class, which is the type of element's which
will be returned by getUserById and have to be inserted as parameter to
deleteUser and so on. The generated domain model has some methods like
getName+getId (depending on your database structure).
The idea behind getters at this point is, that you can overwrite the way the function returns the value, which wouldn't be possible if the service would only return a raw json object.