use ERROR:, inline database combinator examples
parent
031ebe98b1
commit
ea69c8996f
|
@ -285,7 +285,7 @@ ARTICLE: "db-custom-database-combinators" "Custom database combinators"
|
||||||
{ $code <"
|
{ $code <"
|
||||||
USING: db.sqlite db io.files ;
|
USING: db.sqlite db io.files ;
|
||||||
: with-sqlite-db ( quot -- )
|
: with-sqlite-db ( quot -- )
|
||||||
"my-database.db" temp-file <sqlite-db> swap with-db ;"> }
|
"my-database.db" temp-file <sqlite-db> swap with-db ; inline"> }
|
||||||
|
|
||||||
"PostgreSQL example combinator:"
|
"PostgreSQL example combinator:"
|
||||||
{ $code <" USING: db.postgresql db ;
|
{ $code <" USING: db.postgresql db ;
|
||||||
|
@ -296,7 +296,7 @@ USING: db.sqlite db io.files ;
|
||||||
"erg" >>username
|
"erg" >>username
|
||||||
"secrets?" >>password
|
"secrets?" >>password
|
||||||
"factor-test" >>database
|
"factor-test" >>database
|
||||||
swap with-db ;">
|
swap with-db ; inline">
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
ABOUT: "db"
|
ABOUT: "db"
|
||||||
|
|
|
@ -87,9 +87,11 @@ M: sqlite-statement bind-tuple ( tuple statement -- )
|
||||||
in-params>> [ sqlite-bind-conversion ] with map
|
in-params>> [ sqlite-bind-conversion ] with map
|
||||||
] keep bind-statement ;
|
] keep bind-statement ;
|
||||||
|
|
||||||
|
ERROR: sqlite-last-id-fail ;
|
||||||
|
|
||||||
: last-insert-id ( -- id )
|
: last-insert-id ( -- id )
|
||||||
db get handle>> sqlite3_last_insert_rowid
|
db get handle>> sqlite3_last_insert_rowid
|
||||||
dup zero? [ "last-id failed" throw ] when ;
|
dup zero? [ sqlite-last-id-fail ] when ;
|
||||||
|
|
||||||
M: sqlite-db insert-tuple-set-key ( tuple statement -- )
|
M: sqlite-db insert-tuple-set-key ( tuple statement -- )
|
||||||
execute-statement last-insert-id swap set-primary-key ;
|
execute-statement last-insert-id swap set-primary-key ;
|
||||||
|
|
Loading…
Reference in New Issue