db.sqlite: add with-tmp-sqlite, db.tuples: some fixes
parent
1794edfa84
commit
cfc7ef04b5
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2005, 2008 Chris Double, Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien arrays assocs classes compiler db
|
||||
hashtables io.files kernel math math.parser namespaces
|
||||
hashtables io.files io.files.tmp kernel math math.parser namespaces
|
||||
prettyprint sequences strings tuples alien.c-types
|
||||
continuations db.sqlite.lib db.sqlite.ffi db.tuples
|
||||
words combinators.lib db.types ;
|
||||
|
@ -22,6 +22,11 @@ M: sqlite-db dispose ( db -- ) dispose-db ;
|
|||
: with-sqlite ( path quot -- )
|
||||
>r <sqlite-db> r> with-db ; inline
|
||||
|
||||
: with-tmp-sqlite ( quot -- )
|
||||
".db" [
|
||||
swap with-sqlite
|
||||
] with-tmpfile ;
|
||||
|
||||
TUPLE: sqlite-statement ;
|
||||
C: <sqlite-statement> sqlite-statement
|
||||
|
||||
|
|
|
@ -12,23 +12,38 @@ TUPLE: no-slot-named ;
|
|||
: no-slot-named ( -- * ) T{ no-slot-named } throw ;
|
||||
|
||||
: slot-spec-named ( str class -- slot-spec )
|
||||
"slots" word-prop [ slot-spec-name = ] with find nip
|
||||
[ no-slot-named ] unless* ;
|
||||
"slots" word-prop [ slot-spec-name = ] with find nip ;
|
||||
|
||||
: offset-of-slot ( str obj -- n )
|
||||
class slot-spec-named slot-spec-offset ;
|
||||
class slot-spec-named dup [ slot-spec-offset ] when ;
|
||||
|
||||
DEFER: get-slot-named
|
||||
: get-delegate-slot-named ( str obj -- value )
|
||||
delegate [ get-slot-named ] [ drop no-slot-named ] if* ;
|
||||
|
||||
: get-slot-named ( str obj -- value )
|
||||
tuck offset-of-slot [ no-slot-named ] unless* slot ;
|
||||
2dup offset-of-slot [
|
||||
rot drop slot
|
||||
] [
|
||||
get-delegate-slot-named
|
||||
] if* ;
|
||||
|
||||
DEFER: set-slot-named
|
||||
: set-delegate-slot-named ( value str obj -- )
|
||||
delegate [ set-slot-named ] [ 2drop no-slot-named ] if* ;
|
||||
|
||||
: set-slot-named ( value str obj -- )
|
||||
tuck offset-of-slot [ no-slot-named ] unless* set-slot ;
|
||||
2dup offset-of-slot [
|
||||
rot drop set-slot
|
||||
] [
|
||||
set-delegate-slot-named
|
||||
] if* ;
|
||||
|
||||
: primary-key-spec ( class -- spec )
|
||||
db-columns [ primary-key? ] find nip ;
|
||||
|
||||
: primary-key ( tuple -- obj )
|
||||
dup class primary-key-spec get-slot-named ;
|
||||
dup class primary-key-spec first swap get-slot-named ;
|
||||
|
||||
: set-primary-key ( obj tuple -- )
|
||||
[ class primary-key-spec first ] keep
|
||||
|
@ -41,9 +56,9 @@ TUPLE: no-slot-named ;
|
|||
HOOK: create-sql db ( columns table -- seq )
|
||||
HOOK: drop-sql db ( columns table -- seq )
|
||||
|
||||
HOOK: insert-sql* db ( columns table -- slot-names sql )
|
||||
HOOK: update-sql* db ( columns table -- slot-names sql )
|
||||
HOOK: delete-sql* db ( columns table -- slot-names sql )
|
||||
HOOK: insert-sql* db ( columns table -- sql )
|
||||
HOOK: update-sql* db ( columns table -- sql )
|
||||
HOOK: delete-sql* db ( columns table -- sql )
|
||||
HOOK: select-sql db ( tuple -- statement )
|
||||
|
||||
HOOK: row-column-typed db ( result-set n type -- sql )
|
||||
|
|
Loading…
Reference in New Issue