M: postgresql-statement prepare-statement ( statement -- )
dup
- >r db get handle>> "" r>
+ >r db get handle>> f r>
[ sql>> ] [ in-params>> ] bi
length f PQprepare postgresql-error
>>handle drop ;
{ +random-id+ "bigint primary key" }
} ;
-: postgresql-compound ( str n -- newstr )
- over {
- { "default" [ first number>string join-space ] }
- { "varchar" [ first number>string paren append ] }
- { "references" [
- first2 >r [ unparse join-space ] keep db-columns r>
- swap [ slot-name>> = ] with find nip
- column-name>> paren append
- ] }
- [ "no compound found" 3array throw ]
- } case ;
-
-M: postgresql-db compound-modifier ( str seq -- newstr )
- postgresql-compound ;
-
M: postgresql-db modifier-table ( -- hashtable )
H{
{ +native-id+ "primary key" }
{ random-generator "" }
} ;
-M: postgresql-db compound-type ( str n -- newstr )
- postgresql-compound ;
+M: postgresql-db compound ( str obj -- str' )
+ over {
+ { "default" [ first number>string join-space ] }
+ { "varchar" [ first number>string paren append ] }
+ { "references" [
+ first2 >r [ unparse join-space ] keep db-columns r>
+ swap [ slot-name>> = ] with find nip
+ column-name>> paren append
+ ] }
+ [ "no compound found" 3array throw ]
+ } case ;
M: sqlite-db commit-transaction ( -- ) "COMMIT" sql-command ;
M: sqlite-db rollback-transaction ( -- ) "ROLLBACK" sql-command ;
-
: maybe-make-retryable ( statement -- statement )
dup in-params>> [ generator-bind? ] contains? [
make-retryable
{ random-generator "" }
} ;
-M: sqlite-db compound-modifier ( str obj -- str' ) compound-type ;
-
-M: sqlite-db compound-type ( str seq -- str' )
- over {
- { "default" [ first number>string join-space ] }
- [ 2drop ]
- } case ;
-
M: sqlite-db type-table ( -- assoc )
H{
{ +native-id+ "integer primary key" }
} ;
M: sqlite-db create-type-table ( symbol -- str ) type-table ;
+
+M: sqlite-db compound ( str seq -- str' )
+ over {
+ { "default" [ first number>string join-space ] }
+ [ 2drop ]
+ } case ;
+
IN: db.types
HOOK: modifier-table db ( -- hash )
-HOOK: compound-modifier db ( str seq -- hash )
+HOOK: compound db ( str obj -- hash )
HOOK: type-table db ( -- hash )
HOOK: create-type-table db ( -- hash )
-HOOK: compound-type db ( str n -- hash )
HOOK: random-id-quot db ( -- quot )
TUPLE: sql-spec class slot-name column-name type primary-key modifiers ;
: lookup-modifier ( obj -- str )
{
- { [ dup array? ] [ unclip lookup-modifier swap compound-modifier ] }
+ { [ dup array? ] [ unclip lookup-modifier swap compound ] }
[ modifier-table at* [ unknown-modifier ] unless ]
} cond ;
: lookup-create-type ( obj -- str )
dup array? [
- unclip lookup-create-type swap compound-type
+ unclip lookup-create-type swap compound
] [
dup create-type-table at*
[ nip ] [ drop lookup-type* ] if