Commits

Greg Slepak committed a839a8a

added find-or-create-dbobj

Comments (0)

Files changed (1)

example-site/dragonfly-framework/plugins-inactive/db/database_orm.lsp

 (define (find-dbobj db table cols finder , data)
 	(when (integer? finder) (setf finder (string DBOBJ_ROWID_COL finder)))
 	(when (setf data (assoc-row-with-db db (format DBOBJ_SELECT_SQL (join cols ",") table finder)))
-		(instantiate DB.OBJ db table data finder)))
+		(instantiate DB.OBJ db table data finder)
+	)
+)
 
-(global 'create-dbobj 'find-dbobj)
+
+(define (find-or-create-dbobj db table data finder)
+	(unless (find-dbobj db table (map first data) finder)
+		(create-dbobj db table data)
+	)
+)
+
+(global 'create-dbobj 'find-dbobj 'find-or-create-dbobj)
 
 (context DB.OBJ)