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