Scorpiion / vane

Server-side framework for Dart/Dartlang with a built-in middleware system.
BSD 3-Clause "New" or "Revised" License
59 stars 11 forks source link

Add "synchronous ready to use" mongodb connection #13

Open Scorpiion opened 10 years ago

Scorpiion commented 10 years ago

Today when you are doing actions on a database, you have to first wait for a future before you get your connection, and by doing so you also get one more indentation block. By providing a "synchronous ready to use" connection this indentation block would not be needed, and would make for easier code to read and write for some use cases.

Alternative implementations:

  1. Change so a connection always is prepared and connected
  2. Add a new getter called just "db" (or something else) and then somehow tell Vane that some classes should prepare a connection ready to use for this getter. It could for example be a "var mongoSync" parameter that is set in the body of the class. Similar to how we do with async/sync for a middleware.
  3. Implement this as a middleware, middlewares are executed synchronously per default (if async is not set) and hence this might be a good use case for this. Implement a middleware called "MongoSync" or "SyncMongo" (or something better?), let that middleware just make the call to "mongodb.then()" then pass the connection on the tube (Vane's built in communication channel) to the handler running after it. The main handler would start with something like "Db db = tube.receive();" and then in can continue without any indentation.

I think I like alternative 3 the best, since this is not a critical issue I leave it here for now. If you have a preference please a comment with either a 1, 2 or 3 and optionally a motivation.