Permalink
Browse files

adding more examples

  • Loading branch information...
1 parent c526864 commit 5b35e3b98ee5fc1ab35d3699a53f9f953405ee94 @bobbysmith007 bobbysmith007 committed May 13, 2011
Showing with 74 additions and 0 deletions.
  1. +2 −0 README.mediawiki
  2. +42 −0 examples/generating-from-mssql-server.lisp
  3. +30 −0 examples/generating-from-trac-postgresql-db.lisp
View
@@ -16,6 +16,8 @@ custom clsql ORM.
== Examples ==
+'''Please see the examples directory'''
+
<code>
(with-a-database (*application*) ;; a private macro that sets up clsql:*default-database*
(clsql-orm:gen-view-classes
@@ -0,0 +1,42 @@
+(defpackage :clsql-orm-mssql-example (:use :cl :cl-user))
+(in-package :clsql-orm-mssql-example)
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defclass mssql-db-class (CLSQL-SYS::STANDARD-DB-CLASS)
+ ())
+ (defclass mssql-db-obj (CLSQL-SYS::STANDARD-DB-OBJECT)
+ ()
+ (:METACLASS mssql-db-class)))
+
+(defmethod generate-view-classes ()
+ (clsql-sys:with-database
+ (clsql-sys:*default-database*
+ `("DSN-NAME" "USER-NAME" "PASSWORD")
+ :pool T
+ :make-default nil
+ :database-type :odbc
+ :if-exists :warn-new)
+
+ (clsql-orm:gen-view-classes
+ ;; Generate all these in a new
+ ;; package named :clsql-orm-mssql-example-objects
+ ;; :nicknames :adwolf-db
+ :package :clsql-orm-mssql-example-objects
+ :nicknames :mssql-objs
+
+ ;; set each class inheritance chain
+ :inherits-from '(clsql:mssql-db-object)
+ ;; set each classes metaclass
+ :metaclass 'mssql-db-class
+
+ ;; should we automatically export the symbols we create from the
+ ;; package above
+ :export-symbols T
+
+ ;; SQLServer Owner
+ :schema "dbo"
+
+ ;; Should we try to singularize the class names we create from the table
+ ;; eg: Services -> adwolf-db:service when T
+ ;; & Services -> adwolf-db:services when nil
+ :singularize nil)))
@@ -0,0 +1,30 @@
+(defpackage :clsql-orm-pg-example
+ (:use :cl :cl-user))
+
+(in-package :clsql-orm-pg-example)
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defclass pg-db-class (CLSQL-SYS::STANDARD-DB-CLASS)
+ ())
+ (defclass pg-db-obj (CLSQL-SYS::STANDARD-DB-OBJECT)
+ ()
+ (:METACLASS pg-db-class)))
+
+(defmethod generate-view-classes ()
+ (clsql-sys:with-database
+ (clsql-sys:*default-database*
+ `("host" "database" "user" "password")
+ :pool nil
+ :database-type :postgresql-socket
+ :if-exists :warn-new)
+ ;; generate classes from the trac database into the current package
+ ;; These symbols will not automatically be
+ (clsql-orm:gen-view-classes
+ ;; in the public schema
+ :schema "public"
+ ;; for each of these table names
+ :classes '(ticket ticket_change recent_ticket_changes recent_wiki_changes)
+ :metaclass 'pg-db-class
+ :inherits-from '(pg-db-obj))
+
+ ))

0 comments on commit 5b35e3b

Please sign in to comment.