]> gitweb.factorcode.org Git - factor.git/blob - basis/db/types/types-docs.factor
60d92717e8e8b90ff9903b17c27192b2dbc488d7
[factor.git] / basis / db / types / types-docs.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: classes hashtables help.markup help.syntax io.streams.string
4 kernel sequences strings math ;
5 IN: db.types
6
7 HELP: +db-assigned-id+
8 { $description "The database assigns a primary key to the object. The primary key is most likely a big integer, but is database-dependent." } ;
9
10 HELP: +default+
11 { $description "Allows a default value for a column to be provided." } ;
12
13 HELP: +not-null+
14 { $description "Ensures that a column is not null." } ;
15
16 HELP: +null+
17 { $description "Allows a column to be null." } ;
18
19 HELP: +primary-key+
20 { $description "Makes a column a primary key. Only one column may be a primary key." } ;
21
22 HELP: +random-id+
23 { $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." } ;
24
25 HELP: +user-assigned-id+
26 { $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+ } "." } ;
27
28 HELP: <generator-bind>
29 { $values { "slot-name" object } { "key" object } { "generator-singleton" object } { "type" object } { "generator-bind" generator-bind } }
30 { $description "An internal constructor for creating objects containing parameters used for binding generated values to a tuple query." } ;
31
32 HELP: <literal-bind>
33 { $values { "key" object } { "type" object } { "value" object } { "literal-bind" literal-bind } }
34 { $description "An internal constructor for creating objects containing parameters used for binding literal values to a tuple query." } ;
35
36 HELP: BIG-INTEGER
37 { $description "A 64-bit integer. Whether this number is signed or unsigned depends on the database backend." } ;
38
39 HELP: BLOB
40 { $description "A byte array." } ;
41
42 HELP: BOOLEAN
43 { $description "Either true or false." } ;
44
45 HELP: DATE
46 { $description "A date without a time component." } ;
47
48 HELP: DATETIME
49 { $description "A date and a time." } ;
50
51 HELP: DOUBLE
52 { $description "Corresponds to Factor's 64-bit floating-point numbers." } ;
53
54 HELP: FACTOR-BLOB
55 { $description "A serialized Factor object." } ;
56
57 HELP: INTEGER
58 { $description "A small integer, at least 32 bits in length. Whether this number is signed or unsigned depends on the database backend." } ;
59
60 HELP: NULL
61 { $description "The SQL null type." } ;
62
63 HELP: REAL
64 { $description "A real number of unlimited precision. May not be supported on all databases." } ;
65
66 HELP: SIGNED-BIG-INTEGER
67 { $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 } "." } ;
68
69 HELP: TEXT
70 { $description "Stores a string that is longer than a " { $link VARCHAR } ". SQLite uses this type for strings; it does not handle " { $link VARCHAR } " strings." } ;
71
72 HELP: TIME
73 { $description "A timestamp without a date component." } ;
74
75 HELP: TIMESTAMP
76 { $description "A Factor timestamp." } ;
77
78 HELP: UNSIGNED-BIG-INTEGER
79 { $description "For portability, if a number is known to be 64bit, 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 } "." } ;
80
81 { INTEGER SIGNED-BIG-INTEGER UNSIGNED-BIG-INTEGER } related-words
82
83 HELP: URL
84 { $description "A Factor " { $link "urls" } " object." } ;
85
86 HELP: VARCHAR
87 { $description "The SQL varchar type. This type can take an integer as an argument." }
88 { $examples { $unchecked-example "{ VARCHAR 256 }" "" } } ;
89
90 HELP: user-assigned-id-spec?
91 { $values
92      { "specs" "a sequence of SQL specs" }
93      { "?" "a boolean" } }
94 { $description "Tests if any of the SQL specs has the type " { $link +user-assigned-id+ } "." } ;
95
96 HELP: bind#
97 { $values
98      { "spec" "a SQL spec" } { "obj" object } }
99 { $description "A generic word that lets a database construct a literal binding." } ;
100
101 HELP: bind%
102 { $values
103      { "spec" "a SQL spec" } }
104 { $description "A generic word that lets a database output a binding." } ;
105
106 HELP: db-assigned-id-spec?
107 { $values
108      { "specs" "a sequence of SQL specs" }
109      { "?" "a boolean" } }
110 { $description "Tests if any of the SQL specs has the type " { $link +db-assigned-id+ } "." } ;
111
112 HELP: find-primary-key
113 { $values
114      { "specs" "a sequence of SQL specs" }
115      { "seq" "a sequence of SQL specs" } }
116 { $description "Returns the rows from the SQL specs array that are part of the primary key. Composite primary keys are supported, so this word must return a sequence." }
117 { $notes "This is a low-level word." } ;
118
119 HELP: get-slot-named
120 { $values
121      { "name" "a slot name" } { "tuple" tuple }
122      { "value" "the value stored in the slot" } }
123 { $description "Returns the value stored in a tuple slot, where the tuple slot is a string." } ;
124
125 HELP: no-sql-type
126 { $values
127      { "type" "a SQL type" } }
128 { $description "Throws an error containing a SQL type that is unsupported or the result of a typo." } ;
129
130 HELP: normalize-spec
131 { $values
132      { "spec" "a SQL spec" } }
133 { $description "Normalizes a SQL spec." } ;
134
135 HELP: offset-of-slot
136 { $values
137      { "string" string } { "tuple" tuple }
138      { "n" integer } }
139 { $description "Returns the offset of a tuple slot accessed by name." } ;
140
141 HELP: primary-key?
142 { $values
143      { "spec" "a SQL spec" }
144      { "?" "a boolean" } }
145 { $description "Returns true if a SQL spec is a primary key." } ;
146
147 HELP: relation?
148 { $values
149      { "spec" "a SQL spec" }
150      { "?" "a boolean" } }
151 { $description "Returns true if a SQL spec is a relation." } ;
152
153 HELP: unknown-modifier
154 { $values { "modifier" string } }
155 { $description "Throws an error containing an unknown SQL modifier." } ;
156
157 ARTICLE: "db.types" "Database types"
158 "The " { $vocab-link "db.types" } " vocabulary maps Factor types to database types." $nl
159 "Primary keys:"
160 { $subsection +db-assigned-id+ }
161 { $subsection +user-assigned-id+ }
162 { $subsection +random-id+ }
163 "Null and boolean types:"
164 { $subsection NULL }
165 { $subsection BOOLEAN }
166 "Text types:"
167 { $subsection VARCHAR }
168 { $subsection TEXT }
169 "Number types:"
170 { $subsection INTEGER }
171 { $subsection BIG-INTEGER }
172 { $subsection SIGNED-BIG-INTEGER }
173 { $subsection UNSIGNED-BIG-INTEGER }
174 { $subsection DOUBLE }
175 { $subsection REAL }
176 "Calendar types:"
177 { $subsection DATE }
178 { $subsection DATETIME }
179 { $subsection TIME }
180 { $subsection TIMESTAMP }
181 "Factor byte-arrays:"
182 { $subsection BLOB }
183 "Arbitrary Factor objects:"
184 { $subsection FACTOR-BLOB }
185 "Factor URLs:"
186 { $subsection URL } ;
187
188 ABOUT: "db.types"