Git Product home page Git Product logo

clsql-orm's Introduction

CLSQL-ORM

Use this package to help with introspective operations against databases that support information_schema . It supports generating view-class definitions from the database schema.

This was originally clsql-postgres-introspect, though this is a bit far removed from that.

I have used this to successfully generate view-classes for PostgreSQL, MSSQL (through freetds and unixodbc), and mysql.

This project does not attempt to be a persistence layer. It also makes quite a few assumptions about what should be generated and with what types that may not match your desires or existing notions. As such this code might only be useful as a jumping off point for creating your own custom clsql ORM.

Examples

Please see the examples directory

(with-a-database (*application*) ;; a clsql-helper macro that sets up clsql:*default-database* 
  (clsql-orm:gen-view-classes
   :inherits-from '(pg-db-obj) ;; a class I have that I want all my pg-db-objects to inherit from
   :classes 
   ;; The tables I want to turn into classes
   '(users user_districts_and_counties titles salaries roles fiscal-years expenses budgets counties
     districts counties-with-districts reports data-entry-finalizations
     specialties bad-state-salary-input races)))
(clsql-orm:gen-view-classes
   :inherits-from '(pg-db-obj) ;; a class I have that I want all my pg-db-objects to inherit from
   :classes 
   ;; The tables I want to turn into classes
   '(users))

;;; Results in the following class definition being evaled:
(def-view-class user (pg-db-obj)
  ((date-entered :column date_entered :accessor date-entered
		 :db-constraints nil :type wall-time :initarg
		 date-entered)
   (deleted :column deleted :accessor deleted :db-constraints nil
	    :type boolean :initarg deleted)
   (email :column email :accessor email :db-constraints (not-null)
	  :type (varchar 128) :initarg email)
   (enabled :column enabled :accessor enabled :db-constraints
	    (not-null) :initform t :type boolean :initarg enabled)
   (first-name :column first_name :accessor first-name
	       :db-constraints nil :initform nil :type varchar
	       :initarg first-name)
   (id :column id :accessor id :db-kind key :db-constraints
       (not-null) :type integer :initarg id)
   (last-name :column last_name :accessor last-name :db-constraints
	      nil :initform nil :type varchar :initarg last-name)
   (password :column password :accessor password :db-constraints
	     (not-null) :type (varchar 32) :initarg password)
   (role-id :column role_id :accessor role-id :db-constraints
	    (not-null) :type integer :initarg role-id)
   (role-join :accessor role-join :db-kind join :db-info
	      (join-class role :home-key role-id :foreign-key id
			  :set nil))
   (salt :column salt :accessor salt :db-constraints (not-null) :type
	 (varchar 4) :initarg salt))
  (base-table users))

Authors

Authors of this Branch

Author of MySQL Bug Fixes

Scott Brown [email protected]

Original Author information

Alan Shields [email protected]

This work was made possible by the Centola Lab of the Oklahoma Medical Research Foundation

License information is in the file LICENSE (LLGPL)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.