more docs

db4
Doug Coleman 2008-09-08 19:24:44 -05:00
parent a7f116783c
commit 1325939883
4 changed files with 47 additions and 19 deletions

View File

@ -150,8 +150,9 @@ ARTICLE: "db-custom-database-combinators" "Custom database combinators"
"Make a " { $snippet "with-" } " word to open, close, and use your database." "Make a " { $snippet "with-" } " word to open, close, and use your database."
{ $code <" { $code <"
USING: db.sqlite db io.files ;
: with-my-database ( quot -- ) : with-my-database ( quot -- )
{ "my-database.db" temp-file } { "my-database.db" temp-file } sqlite-db rot with-db ;
"> } "> }

View File

@ -82,9 +82,9 @@ HELP: count-tuples
HELP: query HELP: query
{ $values { $values
{ "tuple" null } { "query" null } { "tuple" tuple } { "query" query }
{ "tuples" null } } { "tuples" "a sequence of tuples" } }
{ $description "" } ; { $description "Allows for queries with group by, order by, limit, and offset clauses. " } ;
{ select-tuple select-tuples count-tuples query } related-words { select-tuple select-tuples count-tuples query } related-words

View File

@ -50,10 +50,10 @@ HOOK: insert-tuple* db ( tuple statement -- )
GENERIC: eval-generator ( singleton -- obj ) GENERIC: eval-generator ( singleton -- obj )
: resulting-tuple ( class row out-params -- tuple ) : resulting-tuple ( exemplar-tuple row out-params -- tuple )
rot class new [ rot class new [
[ [
>r slot-name>> r> set-slot-named [ slot-name>> ] dip set-slot-named
] curry 2each ] curry 2each
] keep ; ] keep ;
@ -65,7 +65,7 @@ GENERIC: eval-generator ( singleton -- obj )
: query-modify-tuple ( tuple statement -- ) : query-modify-tuple ( tuple statement -- )
[ query-results [ sql-row-typed ] with-disposal ] keep [ query-results [ sql-row-typed ] with-disposal ] keep
out-params>> rot [ out-params>> rot [
>r slot-name>> r> set-slot-named [ slot-name>> ] dip set-slot-named
] curry 2each ; ] curry 2each ;
: with-disposals ( seq quot -- ) : with-disposals ( seq quot -- )
@ -121,7 +121,7 @@ GENERIC: eval-generator ( singleton -- obj )
[ [ bind-tuple ] [ query-tuples ] 2bi ] with-disposal ; [ [ bind-tuple ] [ query-tuples ] 2bi ] with-disposal ;
: query ( tuple query -- tuples ) : query ( tuple query -- tuples )
>r dup dup class r> <query> do-select ; [ dup dup class ] dip <query> do-select ;
: select-tuples ( tuple -- tuples ) : select-tuples ( tuple -- tuples )
dup dup class <select-by-slots-statement> do-select ; dup dup class <select-by-slots-statement> do-select ;

View File

@ -13,7 +13,7 @@ HELP: +autoincrement+
{ $description "" } ; { $description "" } ;
HELP: +db-assigned-id+ HELP: +db-assigned-id+
{ $description "" } ; { $description "The database assigns a primary key to the object. The primary key is most likely a big integer, but is database-dependent." } ;
HELP: +default+ HELP: +default+
{ $description "" } ; { $description "" } ;
@ -34,7 +34,7 @@ HELP: +primary-key+
{ $description "" } ; { $description "" } ;
HELP: +random-id+ HELP: +random-id+
{ $description "" } ; { $description "Factor chooses a random number and tries to insert the tuple into the database with this number as its primary key. The default number of retries to find a unique random number is 10, though in practice it will almost certainly succeed on the first try." } ;
HELP: +serial+ HELP: +serial+
{ $description "" } ; { $description "" } ;
@ -43,7 +43,7 @@ HELP: +unique+
{ $description "" } ; { $description "" } ;
HELP: +user-assigned-id+ HELP: +user-assigned-id+
{ $description "" } ; { $description "The user is responsible for choosing a primary key for tuples inserted with this database type. Keys must be unique or else the database will throw an error. Usually it is better to use a " { $link +db-assigned-id+ } "." } ;
HELP: <generator-bind> HELP: <generator-bind>
{ $description "" } ; { $description "" } ;
@ -55,22 +55,22 @@ HELP: <low-level-binding>
{ $description "" } ; { $description "" } ;
HELP: BIG-INTEGER HELP: BIG-INTEGER
{ $description "" } ; { $description "A 64-bit integer." } ;
HELP: BLOB HELP: BLOB
{ $description "" } ; { $description "A serialized Factor object. The database library automatically serializes the object for a SQL insert or update and deserializes it on a tuple query." } ;
HELP: BOOLEAN HELP: BOOLEAN
{ $description "" } ; { $description "Either true or false." } ;
HELP: DATE HELP: DATE
{ $description "" } ; { $description "A date without a time component." } ;
HELP: DATETIME HELP: DATETIME
{ $description "" } ; { $description "A date and a time." } ;
HELP: DOUBLE HELP: DOUBLE
{ $description "" } ; { $description "Corresponds to Factor's 64bit floating-point numbers." } ;
HELP: FACTOR-BLOB HELP: FACTOR-BLOB
{ $description "" } ; { $description "" } ;
@ -85,7 +85,7 @@ HELP: REAL
{ $description "" } ; { $description "" } ;
HELP: SIGNED-BIG-INTEGER HELP: SIGNED-BIG-INTEGER
{ $description "" } ; { $description "For portability, if a number is known to be 64bit and signed, then this datatype may be used. Some databases, like SQLite, cannot store arbitrary bignums as BIGINT types. If storing arbitrary bignums, use " { $link FACTOR-BLOB } "." } ;
HELP: TEXT HELP: TEXT
{ $description "" } ; { $description "" } ;
@ -297,7 +297,34 @@ HELP: unknown-modifier
{ $description "" } ; { $description "" } ;
ARTICLE: "db.types" "Database types" ARTICLE: "db.types" "Database types"
"The " { $vocab-link "db.types" } " vocabulary maps Factor types to database types." "The " { $vocab-link "db.types" } " vocabulary maps Factor types to database types." $nl
"Primary keys:"
{ $subsection +db-assigned-id+ }
{ $subsection +user-assigned-id+ }
{ $subsection +random-id+ }
"Null and boolean types:"
{ $subsection NULL }
{ $subsection BOOLEAN }
"Text types:"
{ $subsection VARCHAR }
{ $subsection TEXT }
"Number types:"
{ $subsection INTEGER }
{ $subsection BIG-INTEGER }
{ $subsection SIGNED-BIG-INTEGER }
{ $subsection UNSIGNED-BIG-INTEGER }
{ $subsection DOUBLE }
{ $subsection REAL }
"Calendar types:"
{ $subsection DATE }
{ $subsection DATETIME }
{ $subsection TIME }
{ $subsection TIMESTAMP }
"Arbitrary Factor objects:"
{ $subsection BLOB }
{ $subsection FACTOR-BLOB }
"Factor URLs:"
{ $subsection URL }
; ;
ABOUT: "db.types" ABOUT: "db.types"