source: project/sqlite3-tinyclos/tags/1.2.3/sqlite3-tinyclos-demo.scm @ 4991

Last change on this file since 4991 was 4991, checked in by Thomas Chust, 13 years ago

[sqlite3-tinyclos] Conversion of repository directory layout, step 1

File size: 1.1 KB
Line 
1;;;; sqlite3-tinyclos-demo.scm
2;;;; Small demonstration of the capabilities of sqlite3-tinyclos
3
4;;; load extensions
5(require-extension
6  sqlite3 tinyclos sqlite3-tinyclos)
7
8;;; create a database
9(define db
10  (sqlite3:open "test.db"))
11
12(sqlite3:exec db
13  "CREATE TABLE eggs(
14                  name TEXT NOT NULL, license TEXT, is_module INTEGER NOT NULL DEFAULT 0,
15                  PRIMARY KEY(name), CHECK(is_module IN (0, 1)));")
16
17;;; define the object class
18(sqlite3:define-stored-object-class db "eggs")
19
20;;; add some data
21(let ((egg (make <egg> "sqlite3")))
22  ;; now the entry should already exist
23  (print (sqlite3:in-store? egg))
24  ;; let's add some data
25  (set-license! egg "BSD")
26  ;; and read it back
27  (print (license egg))
28  ;; other fields are filled with default data
29  (print (module? egg))
30  ;; changing the primary key is possible as well
31  (sqlite3:set-pk! egg "foo")
32  (print (sqlite3:pk egg))
33  ;; which does not change data, of course
34  (print (license egg))
35  ;; and we can also delete the entry
36  (print (sqlite3:remove-from-store! egg))
37  ;; then it is gone
38  (print (sqlite3:in-store? egg)))
39
40;;;; vim:set shiftwidth=2 softtabstop=2: ;;;;
Note: See TracBrowser for help on using the repository browser.