• Stars
    star
    201
  • Rank 194,491 (Top 4 %)
  • Language
    Common Lisp
  • Created almost 11 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An ORM for Common Lisp.

Crane

Build Status Quicklisp

Crane is an ORM for Common Lisp, providing a simple bridge between CLOS and relational databases, and out of the box migrations.

Usage

Defining Tables

(deftable user ()
  (name :type text :uniquep t)
  (age :type integer :nullp nil :initform 18)
  (friend :type integer :foreign user)))

The foreign argument accepts a symbol that represents another table or a sexp of the form (table &key on-delete on-update)), where acceptable values are :no-action :restrict :cascade :set-null :set-default.

Migrating

(deftable user ()
  (name :type text :uniquep t :nullp nil)
  (age :type integer :nullp t :initform 18)
  (description :type text))

Just make the changes, and Crane will compute the diffs and perform all the ALTER TABLEs for you.

Connecting

(setup
 :migrations-directory
 (asdf:system-relative-pathname :myapp #p"migrations/")
 :databases
 '(:main
   (:type :postgres
    :name "myapp_db"
    :user "user"
    :pass "user")))

(connect)

For configuration management and switching databases in development/production environments, you might want to use Envy.

Creating, Saving, and Deleting Objects

(let ((instance (create 'ship :name "Dalliance"
                              :tonnage 77)))
  ;; FIXME: It's back luck to rename a ship
  (setf (name instance) "Serenity")
  ;; Expand the cargo hold
  (incf (tonnage instance) 25)
  ;; Save these changes!
  (save instance)
  ;; Time to retire
  (del instance))

Filtering

(filter 'user) ;; Returns everything

(filter 'user :name "Eudoxia")

(filter 'user (:> :age 21))

;; Returns a single object
(single 'user :name "Eudoxia")

;; Throws an error if this returns more
;; than one object
(single! 'user (:< age 35))

;; t if a match exists, nil otherwise
(exists 'user :name "Eudoxia")

;; If this record doesn't exist create it
(get-or-create 'user :name "Eudoxia" :age 19)

Transactions

;;;; Automatic
(with-transaction ()
  (let ((restaurants (filter 'restaurant ...)))
    (loop for restaurant in restaurants do
          ...
          (save restaurant))))

;;;; Manual
(progn
  (begin-transaction)
  (let ((restaurants (filter 'restaurant ...)))
    (loop for restaurant in restaurants do
          ...
          (save restaurant)))
  (commit))

Fixtures

;;;; initial-data.lisp
(app:user
  (:name "eudoxia"
   :groups (:admin :staff))
  (:name "joe"
   :groups (:admin)))
(app:company
  (:name "Initech"
   :city "Denver"))

;;;; myapp.asd
(asdf:defsystem myapp
  :defsystem-depends-on (:clos-fixtures)
  :components ((:module "src"
                :components
                ((:fixture "initial-data")))))

Inflate/Deflate

(definflate (stamp 'timestamp)
  ;; Inflate a timestamp value
  ;; into a timestamp object
  (local-time:universal-to-timestamp stamp))

(defdeflate (stamp local-time:timestamp)
  ;; Deflate a timestamp object
  ;; into a string
  (local-time:format-timestring nil stamp))

Documentation

I'm in the process of moving the documentation to Codex, so for now you can check it out in the website.

License

Copyright (c) 2013 Fernando Borretti ([email protected])

Released under the MIT license.

More Repositories

1

cmacro

Lisp macros for C
Common Lisp
885
star
2

corvus

Low-level Lisp for LLVM
Common Lisp
502
star
3

magma

Extending C with cmacro
C
328
star
4

interim

Low-level Lisp with compile-time memory management
Standard ML
269
star
5

lucerne

A web framework for Common Lisp, built on Clack
Common Lisp
142
star
6

cl-yaml

YAML parser for Common Lisp
Common Lisp
61
star
7

corona

Create and manage virtual machines from Common Lisp
Common Lisp
49
star
8

rock

Asset manager and compiler for Common Lisp web apps
Common Lisp
46
star
9

trivial-ssh

An SSH client library for Common Lisp (Built on libssh2)
Common Lisp
43
star
10

hermetic

Security for Clack-based Common Lisp web applications.
Common Lisp
42
star
11

docparser

Extract documentation from Common Lisp systems
Common Lisp
41
star
12

eco

Fast, flexible, designer-friendly templates for Common Lisp
Common Lisp
39
star
13

trivial-download

Download files from Common Lisp through Drakma.
Common Lisp
38
star
14

asdf-linguist

ASDF extensions.
Common Lisp
34
star
15

spaced-repetition-tools

Scripts for generating flashcards.
Python
33
star
16

swank-protocol

A low-level client for Swank
Common Lisp
31
star
17

cl-pass

Password hashing and verification library
Common Lisp
30
star
18

clack-errors

Error page middleware for Clack.
JavaScript
27
star
19

lime

A client for Swank
Common Lisp
26
star
20

dotfiles

Not guaranteed to work outside of My Machineโ„ข
Emacs Lisp
23
star
21

find-port

Programmatically find open ports.
Common Lisp
19
star
22

trivial-open-browser

Open a browser window. From Common Lisp.
Common Lisp
18
star
23

terminal-keypress

Read keyboard events in the terminal from Common Lisp
Common Lisp
15
star
24

parsing-menhir

Code for a tutorial on parsing with Menhir
OCaml
15
star
25

eudoxia0.github.io

Personal website
HTML
14
star
26

lcm

Manage your system configuration in Common Lisp.
Common Lisp
12
star
27

astro-eog581

Astronomical calculations for The Epiphany of Gliese 581.
Common Lisp
11
star
28

terminal-size

Get the size of the terminal from Common Lisp
Common Lisp
11
star
29

parsimony

Parser combinators for Standard ML
Standard ML
10
star
30

clos-fixtures

CLOS fixtures.
Common Lisp
9
star
31

avatar-api

Get avatars from Gravatar and other services.
Common Lisp
9
star
32

postmaster

Email for humans
Common Lisp
8
star
33

arachne

A web crawling framework in Common Lisp.
Common Lisp
8
star
34

cl-virtualbox

Control VirtualBox from Common Lisp
Common Lisp
8
star
35

airloom

A reverse literate programming tool.
Haskell
7
star
36

cl-libyaml

libyaml bindings for Common Lisp
Common Lisp
6
star
37

concordia

A document preparation system
Standard ML
4
star
38

trivial-extract

Extract compressed files painlessly.
Common Lisp
4
star
39

ctbnrle

Continuous Time Bayesian Network Reasoning and Learning Engine (CTBN-RLE)
C
4
star
40

cartesian

My personal exocortex
Python
3
star
41

which

The which command in Common Lisp
Common Lisp
3
star
42

l0

Linear Lisp
Standard ML
3
star
43

cl-base58

An implementation of base58 for Common Lisp
Common Lisp
3
star
44

parse-front-matter

A Jekyll-style front matter parser
Common Lisp
3
star
45

clippings-parser

Export Kindle clippings to JSON, CSV, or Markdown.
Python
2
star
46

NeuriteTracer

An experiment in computer vision.
C++
2
star
47

lass-flexbox

Flexbox for Lass
Common Lisp
2
star
48

mlunit

A test framework for Standard ML
Standard ML
2
star
49

ocaml-nix-starter

OCaml starter project template using Nix for reproducibility.
Nix
2
star
50

git-file-history

View a file's git history, and individual commit info
Common Lisp
2
star
51

diy-clozemaster

Python
2
star
52

sml-sqlite3

SQLite3 bindings for MLton
Standard ML
1
star
53

MNT

Molecular machinery built in NanoEngineer, in .mmp format.
1
star
54

wax

TeX-like markup language experiment thing
Common Lisp
1
star
55

path-parse

Parse the PATH environment variable portably
Common Lisp
1
star
56

benchmarks

Common Lisp vs. the World
Common Lisp
1
star
57

texgen

Lisp DSL for generating TeX
Common Lisp
1
star