Chapter 2. CommonSQL Tutorial

Based on the UncommonSQL Tutorial

Table of Contents

Introduction
Data Modeling with CLSQL
Class Relations
Object Creation
Finding Objects
Deleting Objects
Conclusion

Introduction

The goal of this tutorial is to guide a new developer thru the process of creating a set of CLSQL classes providing a Object-Oriented interface to persistent data stored in an SQL database. We will assume that the reader is familiar with how SQL works, how relations (tables) should be structured, and has created at least one SQL application previously. We will also assume a minor level of experience with Common Lisp.

CLSQL provides two different interfaces to SQL databases, a Functional interface, and an Object-Oriented interface. The Functional interface consists of a special syntax for embedded SQL expressions in Lisp, and provides lisp functions for SQL operations like SELECT and UPDATE. The object-oriented interface provides a way for mapping Common Lisp Objects System (CLOS) objects into databases and includes functions for inserting new objects, querying objects, and removing objects. Most applications will use a combination of the two.

CLSQL is based on the CommonSQL package from LispWorks Ltd, so the documentation that LispWorks makes available online is useful for CLSQL as well. It is suggested that developers new to CLSQL read their documentation as well, as any differences between CommonSQL and CLSQL are minor. LispWorks makes the following documents available: