Объявить класс, который будет связан с таблицей в базе данных
(def-view-class user ()
((id
:accessor id
:initarg :id
:type integer
:db-type "serial"
:db-kind :key)
(username
:accessor username
:initarg :username
:type string)
(password-hash
:accessor password-hash
:initarg :password-hash
:type string
:column password_hash))
(:base-table users))
Добавить запись в базу данных
(update-records-from-instance
(make-instance 'user
:id 1
:username "foo"
:password-hash (hash-login-information "foo" "foobar"))))
Найти пользователя с id=2 и установить ему поле username в значение joe
(let ((user (first (select 'user :where [= [id] 1] :flatp t :refresh t))))
(setf (username user) "joe")
(update-records-from-instance user))
Удалить таблицу, привязанную к классу и пересоздать её.
(drop-view-from-class 'user)
(create-view-from-class 'user)
Источники:
- 1-4 - coding.derkeiler.com