rejectedsoftware/vibe.d — pull request #80 by davideagen (2012-07-29 17:25:15+00:00)
Title: Adding mongodb URL support.

Connections can be created with a full mongodb URL and valid mongodb urls can be parsed.

The slaveOk option has been implemented.

The rest of the features that can be specified in a mongodb:// URL (username,
password, database, multiple hosts, etc.) are not yet implemented and
warnings will be logged if attempts to use unimplemented funcationality are
made.

mongo.d changes:

connectMongoDB:
If the host field entered starts with 'mongodb://' try to construct the
MongoDB object with the URL parsing constructor. Otherwise use the
hostname/port constructor.

db.d changes:

Replaced m_host and m_port with a MongoConnectionConfig struct.
This struct holds all the configuration information that can be
specified via a mongodb:// URL.

Added a new constructor that parses a mongodb:// URL to create the
MongoConnectionConfig struct.

Modified the existing host/port constructor to instead use the host
and port to create a mongodb URL that is then passed to the new URL
constructor for processing.

Use the new MongoConnectionConfig constructor for MongoConnection
instead of the host/port constructor

connection.d changes:

Replaced m_host and m_port with a MongoConnectionConfig instance.

Added a constructor that takes a MongoConnectionConfig object.
This constructor warns (via logWarn) if features are specified in
the config that are not yet implemented.

Modified the host/port constructor to set a MongoHost instance
in the MongoConnectionConfig.

The query method has been modified to include the defQueryFlags
field of the MongoConnectionConfig struct. This implements the
new slaveOk option support.

A new function named parseMongoDBUrl (with unittest) parses a
mongodb:// URL and returns a MongoConnectionConfig object. If parsing
succeeds it returns true and false otherwise. Mongo url's are a
little different than regular URL's (multiple host/port entries, etc.)
so a dedicated parser seemed to make more sense than forcing mongo
specifics into the Url struct in url.d.

Added new structs MongoConnectionConfig and MongoHost.