Greg Slepak avatar Greg Slepak committed 2652bf7

DB.ORM -> DB.Singleton

Comments (0)

Files changed (2)


 ;; @module database_orm
-;; @description DB.OBJ - Simple Object Relational Mapping (ORM) for DF.DB
+;; @description DB.Singleton - Simple ORM Singleton class for DF.DB
 ;; @version 1.0
 ;; @author Greg Slepak
 (DF:activate-plugin "db/database_utils")
-(new-class 'DB.OBJ)
-(context DB.OBJ)
+(new-class 'DB.Singleton)
+(context DB.Singleton)
 (constant 'SELECT_SQL	"SELECT %s FROM %s WHERE %s LIMIT 1"
           'UPDATE_SQL	"UPDATE %s SET %s=? WHERE %s LIMIT 1")
-(define (DB.OBJ:DB.OBJ _db _table _cols _finder)
+(define (DB.Singleton:DB.Singleton _db _table _cols _finder)
 	(if (= @self @class)
 		(autorelease (instantiate @class _db _table _cols _finder))
 									(<- attr-str revert-set)
 									(<- attr-str change-set))))))))))
-(define (DB.OBJ:refetch)
+(define (DB.Singleton:refetch)
 	(set 'dirty nil
 	     'revert-set (assoc-row-with-db db (format SELECT_SQL (join (map first revert-set) ",") table finder))
 	     'change-set revert-set
-(define (DB.OBJ:save , diff)
+(define (DB.Singleton:save , diff)
 	(unless (null? (setf diff (difference change-set revert-set)))
 		(when (db:execute-update (format UPDATE_SQL table (join (map first diff) "=?,") finder) (map last diff))
 			(set 'revert-set change-set 'dirty nil)


 				<% ) %>
-				(setf obj (instantiate DB.OBJ db "people" '("name" "age") "ROWID=1"))
+				(setf obj (instantiate DB.Singleton db "people" '("name" "age") "ROWID=1"))
 				I've found a person called <%=(obj:name)%> in the table '<%=obj:table%>' at location <%=obj:finder%>, this person is <%=(obj:age)%> years old.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.