Permalink
Browse files

remove out of date test ,add README

  • Loading branch information...
1 parent 38d580e commit 505d43c5b11e95b757e94b97dc30d67621f1c7cc blackdog committed Apr 12, 2010
Showing with 217 additions and 0 deletions.
  1. +141 −0 README
  2. +76 −0 oldTest.hx
View
141 README
@@ -0,0 +1,141 @@
+
+This is a _in progress_ version of a haxe wrapper for ChrisKv's javascript impl at
+
+http://github.com/christkv/node-mongodb-native
+
+To use, place ChrisKv's work in, e.g. .node_libraries, .node_libraries/mongodb
+
+I've only implemented what I need, and I haven't been very faithful to the underlying driver as I wanted to implement some simple serialization for haxe objects and also have static typing on objects.
+
+Here's an example of usage so far, you'll also need my bdog library for the serialization.
+
+Given ...
+
+package bdog.accounts ;
+
+using Lambda;
+
+class Persist implements haxe.rtti.Infos {
+ public function new() {}
+}
+
+
+enum AccountType {
+ REAL;
+ FREE;
+}
+
+enum TxnClass {
+ DB;
+ CR;
+}
+
+enum Txn {
+ CARD(v:Float);
+ WIN(v:Float);
+ JACKPOT(v:Float);
+ INITIAL(v:Float);
+}
+
+enum AccStatus {
+ OK;
+ BAD;
+}
+
+class Session extends Persist {
+ public var _id:String;
+ public var sessionID:String;
+ public var userID:String;
+ public var loggedOn:String;
+ public var loggedOff:String;
+ public var ipAddress:String;
+ public var role:Role;
+}
+
+class Account extends Persist {
+ public var _id:String;
+ public var type:AccountType;
+ public var site:String;
+ public var balance:Float;
+ public var currency:String;
+ public var status:AccStatus;
+ public var lastTransOn:String;
+}
+
+class User extends Persist {
+ public var _id:String;
+ public var firstname:String;
+ public var lastname:String;
+ public var email:String;
+ public var password:String;
+ public var signupOn:String;
+ public var site:String;
+ public var role:Role;
+ public var handle:String;
+ public var accounts:Array<Account>;
+ public var updatedBy:String;
+}
+
+class Ledger extends Persist {
+ public var _id:String;
+ public var userID:String;
+ public var accountType:AccountType;
+ public var tvalue:Float;
+ public var newBalance:Float;
+ public var summary:String;
+ public var addedOn:String;
+ public var addedBy:String;
+ public var transType:String;
+}
+
+
+then this works ...
+
+
+ public static function
+ signUp(email:String,password:String,
+ first:String,last:String,handle:String,
+ role:Role,site:String,
+ ip:String,fn:{uuid:String,user:User}->Void) {
+
+ var
+ db = new MongoPool('localhost',27017,'accounts',10),
+ users = db.col(User);
+
+ users.findOne({email:email,password:password},function(user) {
+ if (user == null) {
+ var
+ entryDate = Date.now().toString(),
+ u = new User();
+
+ u.email=email;
+ u.password=password;
+ u.firstname=first;
+ u.lastname=last;
+ u.handle="temp";
+ u.role=role;
+ u.site=site;
+ u.signupOn = entryDate;
+ u.accounts = accTemplates; // should be a copy?
+ u.updatedBy = null;
+
+ users.insert(u,function(newUser:User) {
+ newSession(db,newUser,ip,function(uuid) {
+ var trns = initialTrans(u,entryDate,MongoDB.ID(newUser));
+ var ledgers = db.col(Ledger);
+ ledgers.insertMany(trns,function(d) {
+ trace("closing for "+email);
+ db.close();
+ fn({uuid:uuid,user:newUser});
+ });
+ });
+ });
+ } else {
+ db.close();
+ fn({uuid:null,user:user});
+ }
+ });
+ }
+
+
+
View
76 oldTest.hx
@@ -0,0 +1,76 @@
+
+import js.Node;
+import bdog.mongo.Mongo;
+import bdog.mongo.MongoNative;
+
+typedef Woot = {
+ var a:String;
+}
+
+class Test {
+ static var pool:MongoPool;
+
+ public inline static function
+ DB() {
+ return new MongoNative(pool);
+ }
+
+ public static function
+ main() {
+ pool = new MongoPool('localhost',27017,'ritchie',3);
+ easy();
+ }
+
+ public static function
+ easy() {
+ var db = DB();
+ db.col('newish').insert({counter:1,hello:'there'});
+ for (i in 0...10)
+ db.col('newish').insert({counter:i,hello:'rhere'+i});
+
+ db.col('newish').count(function(c) {
+ trace('have now '+c);
+ });
+ }
+
+ public static function
+ primitives() {
+
+ for(i in 0...200) {
+
+ new MongoNative(pool).open(function(err,db) {
+ if (err != null) trace(err);
+ trace("opening "+i);
+
+ db.collection('woot',function(err,coll) {
+ coll.find({a:{_lte:3}},function(err,cursor) {
+ cursor.each(function(err,woot:Woot) {
+ // trace(woot);
+ });
+ });
+ });
+
+ db.collection('woot',function(err,coll) {
+ coll.insert({nice:'one laddie'},function(err,doc) {
+ if (err != null) trace(err);
+ //trace(doc);
+ coll.count(function(err,c) {
+ trace("n recs is "+c);
+ db.close();
+ });
+
+
+ });
+ });
+
+ db.createCollection('stuff',function(err,coll) {
+ coll.insert({mystuff:[1,2,3]},function(err,doc) {
+ db.close();
+ });
+ });
+
+ });
+ }
+ }
+
+}

0 comments on commit 505d43c

Please sign in to comment.