Archive for January 2010
git – peer repositories
$ mkdir a $ cd a $ git init Initialized empty Git repository in /cygdrive/c/users/grault/a/.git/ $ echo a > a $ git add a $ git commit -m "first" [master (root-commit) 8a4bdd7] first 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 a $ cd .. $ mkdir b $ cd b $ git init Initialized empty Git repository in /cygdrive/c/users/grault/b/.git/ $ git remote add a ../a $ git branch -a $ git fetch a remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ../a * [new branch] master -> a/master $ git branch -a remotes/a/master $ git merge a/master $ git branch -a * master remotes/a/master $ ls a $ cat a a $ cd .. $ cd a $ git remote add b ../b $ git fetch b From ../b * [new branch] master -> b/master $ git branch -a * master remotes/b/master $
hu.dwim.perec tutorial, lisp clos persistency
Let us see a session which demonstrates the possibility of persisting objects into a database and get it back later on by using project hu.dwim.perec (sometimes available on dwim.hu, when the server is up and running). The slots here are of type integer, but there’s a persistence strategy even for type t, when (AFAIK) some kind of internal representation is dumped. To setup a postgresql database for this session, feel free to read further here.
CL-USER> (setf *load-verbose* nil)
NIL
CL-USER> (setf *compile-verbose* nil)
NIL
CL-USER> (asdf:oos 'asdf:load-op :hu.dwim.perec.postgresql :verbose nil)
#<ASDF:LOAD-OP (:VERBOSE NIL) {B2BC6C9}>
CL-USER> (defpackage :ptest
(:use :hu.dwim.common
:hu.dwim.def
:hu.dwim.defclass-star
:hu.dwim.perec
:hu.dwim.rdbms))
#<PACKAGE "PTEST">
CL-USER> (in-package :ptest)
#<PACKAGE "PTEST">
PTEST> (def special-variable
*psql-db*
(make-instance 'postgresql/perec
:generated-transaction-class-name 'transaction
:default-result-type 'vector
:muffle-warnings t
:connection-specification '(:database "perec_db1"
:user-name "perec_user"
:port 5433
:host "localhost"
:password "perec999pass")))
#<POSTGRESQL/PEREC {B4BF189}>
PTEST> (def persistent-class*
some-user-info ()
((userid :type integer)
(some-data :type integer)))
#<PERSISTENT-CLASS SOME-USER-INFO>
PTEST> (make-compiled-query-cache)
#<HASH-TABLE :TEST EQUAL :COUNT 0 {C53BBC1}>
PTEST> (setf hu.dwim.perec::*compiled-query-cache* *)
#<HASH-TABLE :TEST EQUAL :COUNT 0 {C53BBC1}>
PTEST> (setf (hu.dwim.logger:log-level 'hu.dwim.rdbms::rdbms)
hu.dwim.logger:+fatal+
(hu.dwim.logger:log-level 'hu.dwim.rdbms::sql)
hu.dwim.logger:+fatal+)
5
PTEST> (with-database *psql-db*
(with-transaction
(make-instance 'some-user-info :userid 1 :some-data -1)))
#<SOME-USER-INFO :persistent #t 12>
PTEST> (with-database *psql-db*
(with-transaction
(make-instance 'some-user-info :userid 2 :some-data -2)))
#<SOME-USER-INFO :persistent #t 13>
PTEST> (with-database *psql-db*
(with-transaction
(select (o)
(from (o some-user-info))
(where (= 1 (userid-of o))))))
(#<SOME-USER-INFO :persistent #? 12 {B14A2E1}>)
PTEST> (with-database *psql-db*
(with-transaction
(some-data-of (revive-instance (car *)))))
-1
PTEST>
Tables are created automatically in the appropriate database:
perec_db1=# select * from _some_user_info;
_oid | _userid | _some_data
---------+---------+------------
960005 | 1 | -1
1025541 | 2 | -2
(2 rows)
perec_db1=# \d _some_user_info
Table "public._some_user_info"
Column | Type | Modifiers
------------+---------+-----------
_oid | bigint | not null
_userid | numeric |
_some_data | numeric |
Indexes:
"_some_user_info_pkey" PRIMARY KEY, btree (_oid)
perec_db1=#