Pure Haxe MongoDB driver that is meant to be truly cross platform.
There are other
Haxe drivers out there but they
use sys.net.Socket
which is not available on all targets. Also they use sync
operations which is not suitable in single-thread environments.
This driver utilizes tink_tcp which provides async TCP operations across all targets in a consistent manner. So this driver should work on any targets that is supported by tink_tcp.
Mongo.connect().handle(function(o) switch(o) {
case Success(mongo):
var db = mongo.db('test');
var collection = db.collection('users');
collection.find({filter:{username:'foo'}}).handle(function(o) trace(o));
case Failure(err):
trace(err);
});
More to come...
This is pretty much work in progress in a sense that although the protocol to
communicate with the database server is complete, not all database commands are
wrapped in a function call (e.g. db.dropDatabase()
or collection.find({})
).
But you can run most, if not all, commands through db.runCommand(command)
by
following the official manual.
To illustrate, collection.find({filter:{a:1}})
is equivalent to:
var cmd = new BsonDocument();
cmd.add('find', 'collection_name');
cmd.add('filter', {a:1});
db.runCommand(cmd);
This library is the driver only. So, do expect that the commands and responses will be very "raw", though efforts has been made to properly typing them.
THis library does not include ORM, but they can be built based on this driver.