瀏覽代碼

SPOD -> Record

Simon Krajewski 12 年之前
父節點
當前提交
8f5fffcc2c

+ 1 - 1
std/haxe/web/Dispatch.hx

@@ -178,7 +178,7 @@ class Dispatch {
 			var cl : Dynamic = Type.resolveClass(c);
 			if( cl == null ) throw "assert";
 			var o : Dynamic;
-			#if spod_macro
+			#if !old_spod
 			o = cl.manager.unsafeGet(v, lock);
 			#else
 			o = cl.manager.get(v, lock);

+ 1 - 1
std/neko/db/Connection.hx

@@ -21,6 +21,6 @@
  */
 package neko.db;
 
-#if !spod_macro
+#if old_spod
 typedef Connection = sys.db.Connection;
 #end

+ 4 - 8
std/neko/db/Manager.hx

@@ -21,11 +21,7 @@
  */
 package neko.db;
 
-#if spod_shard
-
-typedef Manager<T : Object> = mt.db.ShardManager<T>;
-
-#elseif spod_macro
+#if !old_spod
 
 #else
 
@@ -33,8 +29,8 @@ import Reflect;
 import neko.db.Connection;
 
 /**
-	SPOD Manager : the persistent object database manager. See the tutorial on
-	haXe website to learn how to use SPOD.
+	Record Manager : the persistent object database manager. See the tutorial on
+	haXe website to learn how to use Record.
 **/
 @:unifyMinDynamic
 class Manager<T : Object> {
@@ -221,7 +217,7 @@ class Manager<T : Object> {
 		return cast cnx.request(sql).results();
 	}
 
-	/* -------------------------- SPODOBJECT API -------------------------- */
+	/* -------------------------- RECORDOBJECT API -------------------------- */
 
 	function doInsert( x : T ) {
 		unmake(x);

+ 1 - 1
std/neko/db/Mysql.hx

@@ -20,7 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 package neko.db;
-#if !spod_macro
+#if old_spod
 
 import neko.db.Connection;
 

+ 4 - 4
std/neko/db/Object.hx

@@ -22,12 +22,12 @@
 package neko.db;
 
 /**
-	SPOD Object : the persistent object base type. See the tutorial on haXe
-	website to learn how to use SPOD.
+	Record Object : the persistent object base type. See the tutorial on haXe
+	website to learn how to use Record.
 **/
-#if !spod_macro
+#if old_spod
 
-#if spod_rtti
+#if spod-rtti
 @:rtti
 #end
 class Object {

+ 1 - 1
std/neko/db/ResultSet.hx

@@ -21,6 +21,6 @@
  */
 package neko.db;
 
-#if !spod_macro
+#if old_spod
 typedef ResultSet = sys.db.ResultSet;
 #end

+ 6 - 1
std/neko/db/Sqlite.hx

@@ -21,7 +21,12 @@
  */
 package neko.db;
 
+#if old_spod
 import neko.db.Connection;
+#else
+import sys.db.Connection;
+import sys.db.ResultSet;
+#end
 
 private class SqliteConnection implements Connection {
 
@@ -178,7 +183,7 @@ private class SqliteResultSet implements ResultSet {
 	public function getFloatResult( n : Int ) : Float {
 		return result_get_float(r,n);
 	}
-	
+
 	public function getFieldsNames() : Array<String> {
 		return null;
 	}

+ 1 - 1
std/neko/db/Transaction.hx

@@ -20,7 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 package neko.db;
-#if !spod_macro
+#if old_spod
 
 class Transaction {
 

+ 1 - 1
std/php/db/Connection.hx

@@ -21,6 +21,6 @@
  */
 package php.db;
 
-#if !spod_macro
+#if old_spod
 typedef Connection = sys.db.Connection;
 #end

+ 9 - 4
std/php/db/Manager.hx

@@ -21,12 +21,16 @@
  */
 package php.db;
 
+#if !old_spod
+
+#else
+
 import Reflect;
 import php.db.Connection;
 
 /**
-	SPOD Manager : the persistent object database manager. See the tutorial on
-	haXe website to learn how to use SPOD.
+	Record Manager : the persistent object database manager. See the tutorial on
+	haXe website to learn how to use Record.
 **/
 class Manager<T : Object> {
 
@@ -218,7 +222,7 @@ class Manager<T : Object> {
 		return cast cnx.request(sql).results();
 	}
 
-	/* -------------------------- SPODOBJECT API -------------------------- */
+	/* -------------------------- RECORDOBJECT API -------------------------- */
 
 	function doInsert( x : T ) {
 		unmake(x);
@@ -437,7 +441,7 @@ class Manager<T : Object> {
 	/* --------------------------- INIT / CLEANUP ------------------------- */
 
 	/**
-	* Left for compability with neko SPOD
+	* Left for compability with neko Record
 	*/
 	public static function initialize() {
 
@@ -497,3 +501,4 @@ class Manager<T : Object> {
 		return c;
 	}
 }
+#end

+ 6 - 1
std/php/db/Mysql.hx

@@ -21,7 +21,12 @@
  */
 package php.db;
 
+#if old_spod
 import php.db.Connection;
+#else
+import sys.db.Connection;
+import sys.db.ResultSet;
+#end
 
 private class MysqlConnection implements Connection {
 
@@ -205,7 +210,7 @@ class Mysql {
 		pass : String,
 		socket : String,
 		database : String
-	} ) : php.db.Connection {
+	} ) : Connection {
 		var c = untyped __call__("mysql_connect",
 			params.host + (params.port == null ? '' : ':'+params.port) + (params.socket == null ? '' : ':'+params.socket),
 			params.user,

+ 8 - 3
std/php/db/Object.hx

@@ -22,10 +22,14 @@
 package php.db;
 
 /**
-	SPOD Object : the persistent object base type. See the tutorial on haXe
-	website to learn how to use SPOD.
+	Record Object : the persistent object base type. See the tutorial on haXe
+	website to learn how to use Record.
 **/
-class Object #if spod_rtti implements haxe.rtti.Infos #end {
+#if old_spod
+#if spod_rtti
+@:rtti
+#end
+class Object {
 
 /*
 	(optional)
@@ -86,3 +90,4 @@ class Object #if spod_rtti implements haxe.rtti.Infos #end {
 	}
 
 }
+#end

+ 1 - 1
std/php/db/PDO.hx

@@ -23,7 +23,7 @@ package php.db;
 
 import php.NativeArray;
 
-#if spod_macros
+#if !old_spod
 import sys.db.Connection;
 import sys.db.ResultSet;
 #end

+ 1 - 1
std/php/db/ResultSet.hx

@@ -21,6 +21,6 @@
  */
 package php.db;
 
-#if !spod_macro
+#if old_spod
 typedef ResultSet = sys.db.ResultSet;
 #end

+ 5 - 0
std/php/db/Sqlite.hx

@@ -21,7 +21,12 @@
  */
 package php.db;
 
+#if old_spod
 import php.db.Connection;
+#else
+import sys.db.Connection;
+import sys.db.ResultSet;
+#end
 
 private class SqliteConnection implements Connection {
 

+ 1 - 1
std/php/db/Transaction.hx

@@ -21,7 +21,7 @@
  */
 package php.db;
 
-#if !spod_macro
+#if old_spod
 class Transaction {
 
 	public static function isDeadlock(e : Dynamic) {

+ 14 - 14
std/sys/db/Manager.hx

@@ -23,15 +23,15 @@ package sys.db;
 import Reflect;
 import sys.db.Connection;
 
-#if (!spod_macro && !doc_gen && !macro)
-#error "Please use -D spod_macro when using new SPOD version"
+#if (!old_spod && !doc_gen && !macro)
+#error "Cannot use sys.db.Manager with -D old_spod"
 #end
 
 /**
-	SPOD Manager : the persistent object database manager. See the tutorial on
-	haXe website to learn how to use SPOD.
+	Record Manager : the persistent object database manager. See the tutorial on
+	haXe website to learn how to use Record.
 **/
-#if !macro @:build(sys.db.SpodMacros.addRtti()) #end
+#if !macro @:build(sys.db.RecordMacros.addRtti()) #end
 class Manager<T : Object> {
 
 	/* ----------------------------- STATICS ------------------------------ */
@@ -58,7 +58,7 @@ class Manager<T : Object> {
 
 	/* ---------------------------- BASIC API ----------------------------- */
 
-	var table_infos : SpodInfos;
+	var table_infos : RecordInfos;
 	var table_name : String;
 	var table_keys : Array<String>;
 	var class_proto : { prototype : Dynamic };
@@ -82,23 +82,23 @@ class Manager<T : Object> {
 	}
 
 	public macro function get(ethis,id,?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<T> #end {
-		return SpodMacros.macroGet(ethis,id,lock);
+		return RecordMacros.macroGet(ethis,id,lock);
 	}
 
 	public macro function select(ethis, cond, ?options, ?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<T> #end {
-		return SpodMacros.macroSearch(ethis, cond, options, lock, true);
+		return RecordMacros.macroSearch(ethis, cond, options, lock, true);
 	}
 
 	public macro function search(ethis, cond, ?options, ?lock:haxe.macro.Expr.ExprOf<Bool>) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<List<T>> #end {
-		return SpodMacros.macroSearch(ethis, cond, options, lock);
+		return RecordMacros.macroSearch(ethis, cond, options, lock);
 	}
 
 	public macro function count(ethis, cond) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<Int> #end {
-		return SpodMacros.macroCount(ethis, cond);
+		return RecordMacros.macroCount(ethis, cond);
 	}
 
 	public macro function delete(ethis, cond, ?options) : #if macro haxe.macro.Expr #else haxe.macro.Expr.ExprOf<Void> #end {
-		return SpodMacros.macroDelete(ethis, cond, options);
+		return RecordMacros.macroDelete(ethis, cond, options);
 	}
 
 	public function dynamicSearch( x : {}, ?lock : Bool ) : List<T> {
@@ -114,7 +114,7 @@ class Manager<T : Object> {
 		return getCnx().quote( s );
 	}
 
-	/* -------------------------- SPODOBJECT API -------------------------- */
+	/* -------------------------- RECORDOBJECT API -------------------------- */
 
 	function doUpdateCache( x : T, name : String, v : Dynamic ) {
 		var cache : { v : Dynamic } = Reflect.field(x, "cache_" + name);
@@ -183,7 +183,7 @@ class Manager<T : Object> {
 		addToCache(x);
 	}
 
-	inline function isBinary( t : SpodInfos.SpodType ) {
+	inline function isBinary( t : RecordInfos.RecordType ) {
 		return switch( t ) {
 			case DSmallBinary, DNekoSerialized, DLongBinary, DBytes(_), DBinary: true;
 			//case DData: true // -- disabled for implementation purposes
@@ -507,7 +507,7 @@ class Manager<T : Object> {
 		object_cache = new haxe.ds.StringMap();
 	}
 
-	function initRelation( r : SpodInfos.SpodRelation ) {
+	function initRelation( r : RecordInfos.RecordRelation ) {
 		// setup getter/setter
 		var spod : Dynamic = Type.resolveClass(r.type);
 		if( spod == null ) throw "Missing spod type " + r.type;

+ 3 - 3
std/sys/db/Object.hx

@@ -22,11 +22,11 @@
 package sys.db;
 
 /**
-	SPOD Object : the persistent object base type. See the tutorial on haXe
-	website to learn how to use SPOD.
+	Record Object : the persistent object base type. See the tutorial on haXe
+	website to learn how to use Record.
 **/
 @:keepSub
-@:autoBuild(sys.db.SpodMacros.macroBuild()) @:skipFields
+@:autoBuild(sys.db.RecordMacros.macroBuild()) @:skipFields
 class Object {
 
 	var _lock(default,never) : Bool;

+ 8 - 8
std/sys/db/SpodInfos.hx → std/sys/db/RecordInfos.hx

@@ -21,7 +21,7 @@
  */
 package sys.db;
 
-enum SpodType {
+enum RecordType {
 	DId;
 	DInt;
 	DUId;
@@ -59,13 +59,13 @@ enum SpodType {
 	DNull;
 }
 
-typedef SpodField = {
+typedef RecordField = {
 	var name : String;
-	var t : SpodType;
+	var t : RecordType;
 	var isNull : Bool;
 }
 
-typedef SpodRelation = {
+typedef RecordRelation = {
 	var prop : String;
 	var key : String;
 	var type : String;
@@ -74,11 +74,11 @@ typedef SpodRelation = {
 	var isNull : Bool;
 }
 
-typedef SpodInfos = {
+typedef RecordInfos = {
 	var name : String;
 	var key : Array<String>;
-	var fields : Array<SpodField>;
-	var hfields : haxe.ds.StringMap<SpodField>;
-	var relations : Array<SpodRelation>;
+	var fields : Array<RecordField>;
+	var hfields : haxe.ds.StringMap<RecordField>;
+	var relations : Array<RecordRelation>;
 	var indexes : Array<{ keys : Array<String>, unique : Bool }>;
 }

+ 31 - 31
std/sys/db/SpodMacros.hx → std/sys/db/RecordMacros.hx

@@ -20,7 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 package sys.db;
-import sys.db.SpodInfos;
+import sys.db.RecordInfos;
 import haxe.macro.Expr;
 import haxe.macro.Type.VarAccess;
 #if macro
@@ -29,22 +29,22 @@ import haxe.macro.Context;
 
 private typedef SqlFunction = {
 	var name : String;
-	var params : Array<SpodType>;
-	var ret : SpodType;
+	var params : Array<RecordType>;
+	var ret : RecordType;
 	var sql : String;
 }
 
-class SpodMacros {
+class RecordMacros {
 
 	static var GLOBAL = null;
 	static var simpleString = ~/^[A-Za-z0-9 ]*$/;
 
 	var isNull : Bool;
 	var manager : Expr;
-	var inf : SpodInfos;
+	var inf : RecordInfos;
 	var g : {
-		var cache : haxe.ds.StringMap<SpodInfos>;
-		var types : haxe.ds.StringMap<SpodType>;
+		var cache : haxe.ds.StringMap<RecordInfos>;
+		var types : haxe.ds.StringMap<RecordType>;
 		var functions : haxe.ds.StringMap<SqlFunction>;
 	};
 
@@ -55,16 +55,16 @@ class SpodMacros {
 			g = initGlobals();
 			GLOBAL = g;
 		}
-		inf = getSpodInfos(c);
+		inf = getRecordInfos(c);
 	}
 
 	function initGlobals()
 	{
 		var cache = new haxe.ds.StringMap();
 		var types = new haxe.ds.StringMap();
-		for( c in Type.getEnumConstructs(SpodType) ) {
-			var e : Dynamic = Reflect.field(SpodType, c);
-			if( Std.is(e, SpodType) )
+		for( c in Type.getEnumConstructs(RecordType) ) {
+			var e : Dynamic = Reflect.field(RecordType, c);
+			if( Std.is(e, RecordType) )
 				types.set("S"+c.substr(1), e);
 		}
 		types.remove("SNull");
@@ -111,7 +111,7 @@ class SpodMacros {
 		#end
 	}
 
-	public dynamic function getManager( t : haxe.macro.Type, p : Position ) : SpodMacros {
+	public dynamic function getManager( t : haxe.macro.Type, p : Position ) : RecordMacros {
 		#if macro
 		return getManagerInfos(t, p);
 		#else
@@ -140,7 +140,7 @@ class SpodMacros {
 		throw "Unsupported " + Std.string(t);
 	}
 
-	function makeSpod( t : haxe.macro.Type ) {
+	function makeRecord( t : haxe.macro.Type ) {
 		switch( t ) {
 		case TInst(c, _):
 			var name = c.toString();
@@ -155,7 +155,7 @@ class SpodMacros {
 			var name = t.toString();
 			if( p.length == 1 && (name == "Null" || name == "sys.db.SNull") ) {
 				isNull = true;
-				return makeSpod(p[0]);
+				return makeRecord(p[0]);
 			}
 		default:
 		}
@@ -191,7 +191,7 @@ class SpodMacros {
 			case "String": DText;
 			case "Date": DDateTime;
 			case "haxe.io.Bytes": DBinary;
-			default: throw "Unsupported SPOD Type " + name;
+			default: throw "Unsupported Record Type " + name;
 			}
 		case TAbstract(a, _):
 			var name = a.toString();
@@ -199,14 +199,14 @@ class SpodMacros {
 			case "Int": DInt;
 			case "Float": DFloat;
 			case "Bool": DBool;
-			default: throw "Unsupported SPOD Type " + name;
+			default: throw "Unsupported Record Type " + name;
 			}
 		case TEnum(e, _):
 			var name = e.toString();
 			return switch( name ) {
 			case "Bool": DBool;
 			default:
-				throw "Unsupported SPOD Type " + name + " (enums must be wrapped with SData or SEnum)";
+				throw "Unsupported Record Type " + name + " (enums must be wrapped with SData or SEnum)";
 			}
 		case TType(td, p):
 			var name = td.toString();
@@ -248,7 +248,7 @@ class SpodMacros {
 			return makeType(follow(t, true));
 		default:
 		}
-		throw "Unsupported SPOD Type " + Std.string(t);
+		throw "Unsupported Record Type " + Std.string(t);
 	}
 
 	function makeIdent( e : Expr ) {
@@ -262,7 +262,7 @@ class SpodMacros {
 		}
 	}
 
-	function getSpodInfos( c : haxe.macro.Type.Ref<haxe.macro.Type.ClassType> ) : SpodInfos {
+	function getRecordInfos( c : haxe.macro.Type.Ref<haxe.macro.Type.ClassType> ) : RecordInfos {
 		var cname = c.toString();
 		var i = g.cache.get(cname);
 		if( i != null ) return i;
@@ -305,7 +305,7 @@ class SpodMacros {
 						for( p in m.params )
 							params.push({ i : makeIdent(p), p : p.pos });
 						isNull = false;
-						var t = makeSpod(f.type);
+						var t = makeRecord(f.type);
 						if( t == null ) error("Relation type should be a sys.db.Object", f.pos);
 						var r = {
 							prop : f.name,
@@ -429,7 +429,7 @@ class SpodMacros {
 		return { expr : EBinop(OpAdd, sql, makeString(s,sql.pos)), pos : sql.pos };
 	}
 
-	function sqlQuoteValue( v : Expr, t : SpodType ) {
+	function sqlQuoteValue( v : Expr, t : RecordType ) {
 		switch( v.expr ) {
 		case EConst(c):
 			switch( c ) {
@@ -449,11 +449,11 @@ class SpodMacros {
 		return { expr : ECall( { expr : EField(manager, "quoteAny"), pos : v.pos }, [ensureType(v,t)]), pos : v.pos }
 	}
 
-	inline function sqlAddValue( sql : Expr, v : Expr, t : SpodType ) {
+	inline function sqlAddValue( sql : Expr, v : Expr, t : RecordType ) {
 		return { expr : EBinop(OpAdd, sql, sqlQuoteValue(v,t)), pos : sql.pos };
 	}
 
-	function unifyClass( t : SpodType ) {
+	function unifyClass( t : RecordType ) {
 		return switch( t ) {
 		case DId, DInt, DUId, DUInt, DEncoded, DFlags(_), DTinyInt, DTinyUInt, DSmallInt, DSmallUInt, DMediumInt, DMediumUInt: 0;
 		case DBigId, DBigInt, DSingle, DFloat: 1;
@@ -475,18 +475,18 @@ class SpodMacros {
 		return c == rc || (c == 0 && rc == 1); // allow Int-to-Float expansion
 	}
 
-	function typeStr( t : SpodType ) {
+	function typeStr( t : RecordType ) {
 		return Std.string(t).substr(1);
 	}
 
-	function canStringify( t : SpodType ) {
+	function canStringify( t : RecordType ) {
 		return switch( unifyClass(t) ) {
 		case 0, 1, 2, 3, 4, 5, 7: true;
 		default: false;
 		};
 	}
 
-	function convertType( t : SpodType ) {
+	function convertType( t : RecordType ) {
 		var pack = [];
 		return TPath( {
 			name : switch( unifyClass(t) ) {
@@ -504,7 +504,7 @@ class SpodMacros {
 		});
 	}
 
-	function unify( t : SpodType, rt : SpodType, pos : Position ) {
+	function unify( t : RecordType, rt : RecordType, pos : Position ) {
 		if( !tryUnify(t, rt) )
 			error(typeStr(t) + " should be " + typeStr(rt), pos);
 	}
@@ -847,7 +847,7 @@ class SpodMacros {
 		return null;
 	}
 
-	function ensureType( e : Expr, rt : SpodType ) {
+	function ensureType( e : Expr, rt : RecordType ) {
 		return { expr : ECheckType(e, convertType(rt)), pos : e.pos };
 	}
 
@@ -1004,7 +1004,7 @@ class SpodMacros {
 		case TInst(c, _): if( c.toString() == "sys.db.Object" ) return null; c;
 		default: return null;
 		};
-		return new SpodMacros(c);
+		return new RecordMacros(c);
 	}
 
 
@@ -1014,7 +1014,7 @@ class SpodMacros {
 	public static function addRtti() : Array<Field> {
 		if( RTTI ) return null;
 		RTTI = true;
-		Context.getType("sys.db.SpodInfos");
+		Context.getType("sys.db.RecordInfos");
 		Context.onGenerate(function(types) {
 			for( t in types )
 				switch( t ) {
@@ -1037,7 +1037,7 @@ class SpodMacros {
 				default:
 				}
 		});
-		Context.registerModuleReuseCall("sys.db.Manager", "sys.db.SpodMacros.addRtti()");
+		Context.registerModuleReuseCall("sys.db.Manager", "sys.db.RecordMacros.addRtti()");
 		return null;
 	}
 

+ 2 - 2
std/sys/db/TableCreate.hx

@@ -20,7 +20,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 package sys.db;
-import sys.db.SpodInfos;
+import sys.db.RecordInfos;
 
 class TableCreate {
 
@@ -29,7 +29,7 @@ class TableCreate {
 		return dbName == "SQLite" ? "PRIMARY KEY AUTOINCREMENT" : "AUTO_INCREMENT";
 	}
 
-	public static function getTypeSQL( t : SpodType, dbName : String ) {
+	public static function getTypeSQL( t : RecordType, dbName : String ) {
 		return switch( t ) {
 		case DId: "INTEGER "+autoInc(dbName);
 		case DUId: "INTEGER UNSIGNED "+autoInc(dbName);