comparison doc/manual.tex @ 896:0ae8894d5c97

New command-line options; describe simple SQLite build in demo intro
author Adam Chlipala <adamc@hcoop.net>
date Sat, 18 Jul 2009 13:46:22 -0400
parents 41971801b62d
children 2faf558b2d05
comparison
equal deleted inserted replaced
895:ae9e22822ec5 896:0ae8894d5c97
54 ./configure 54 ./configure
55 make 55 make
56 sudo make install 56 sudo make install
57 \end{verbatim} 57 \end{verbatim}
58 58
59 Some other packages must be installed for the above to work. At a minimum, you need a standard UNIX shell, with standard UNIX tools like sed and GCC in your execution path; MLton, the whole-program optimizing compiler for Standard ML; and the mhash C library. To build programs that access SQL databases, you also need libpq, the PostgreSQL client library. As of this writing, in the ``testing'' version of Debian Linux, this command will install the more uncommon of these dependencies: 59 Some other packages must be installed for the above to work. At a minimum, you need a standard UNIX shell, with standard UNIX tools like sed and GCC in your execution path; MLton, the whole-program optimizing compiler for Standard ML; and the mhash C library. As of this writing, in the ``testing'' version of Debian Linux, this command will install the more uncommon of these dependencies:
60
61 \begin{verbatim} 60 \begin{verbatim}
62 apt-get install mlton libmhash-dev libpq-dev 61 apt-get install mlton libmhash-dev
63 \end{verbatim} 62 \end{verbatim}
64 63
64 To build programs that access SQL databases, you also need one of these client libraries for supported backends.
65 \begin{verbatim}
66 apt-get install libpq-dev libmysqlclient15-dev libsqlite3-dev
67 \end{verbatim}
68
65 It is also possible to access the modules of the Ur/Web compiler interactively, within Standard ML of New Jersey. To install the prerequisites in Debian testing: 69 It is also possible to access the modules of the Ur/Web compiler interactively, within Standard ML of New Jersey. To install the prerequisites in Debian testing:
66
67 \begin{verbatim} 70 \begin{verbatim}
68 apt-get install smlnj libsmlnj-smlnj ml-yacc ml-lpt 71 apt-get install smlnj libsmlnj-smlnj ml-yacc ml-lpt
69 \end{verbatim} 72 \end{verbatim}
70 73
71 To begin an interactive session with the Ur compiler modules, run \texttt{make smlnj}, and then, from within an \texttt{sml} session, run \texttt{CM.make "src/urweb.cm";}. The \texttt{Compiler} module is the main entry point. 74 To begin an interactive session with the Ur compiler modules, run \texttt{make smlnj}, and then, from within an \texttt{sml} session, run \texttt{CM.make "src/urweb.cm";}. The \texttt{Compiler} module is the main entry point.
72 75
73 To run an SQL-backed application, you will probably want to install the PostgreSQL server. Version 8.3 or higher is required. 76 To run an SQL-backed application with a backend besides SQLite, you will probably want to install one of these servers.
74 77
75 \begin{verbatim} 78 \begin{verbatim}
76 apt-get install postgresql-8.3 79 apt-get install postgresql-8.3 mysql-server-5.0
77 \end{verbatim} 80 \end{verbatim}
78 81
79 To use the Emacs mode, you must have a modern Emacs installed. We assume that you already know how to do this, if you're in the business of looking for an Emacs mode. The demo generation facility of the compiler will also call out to Emacs to syntax-highlight code, and that process depends on the \texttt{htmlize} module, which can be installed in Debian testing via: 82 To use the Emacs mode, you must have a modern Emacs installed. We assume that you already know how to do this, if you're in the business of looking for an Emacs mode. The demo generation facility of the compiler will also call out to Emacs to syntax-highlight code, and that process depends on the \texttt{htmlize} module, which can be installed in Debian testing via:
80 83
81 \begin{verbatim} 84 \begin{verbatim}
162 165
163 To time how long the different compiler phases run, without generating an executable, run 166 To time how long the different compiler phases run, without generating an executable, run
164 \begin{verbatim} 167 \begin{verbatim}
165 urweb -timing P 168 urweb -timing P
166 \end{verbatim} 169 \end{verbatim}
170
171 Some other command-line parameters are accepted:
172 \begin{itemize}
173 \item \texttt{-db <DBSTRING>}: Set database connection information, using the format expected by Postgres's \texttt{PQconnectdb()}, which is \texttt{name1=value1 ... nameN=valueN}. The same format is also parsed and used to discover connection parameters for MySQL and SQLite. The only significant settings for MySQL are \texttt{host}, \texttt{hostaddr}, \texttt{port}, \texttt{dbname}, \texttt{user}, and \texttt{password}. The only significant setting for SQLite is \texttt{dbname}, which is interpreted as the filesystem path to the database. Additionally, when using SQLite, a database string may be just a file path.
174
175 \item \texttt{-dbms [postgres|mysql|sqlite]}: Sets the database backend to use.
176 \begin{itemize}
177 \item \texttt{postgres}: This is PostgreSQL, the default. Among the supported engines, Postgres best matches the design philosophy behind Ur, with a focus on consistent views of data, even in the face of much concurrency. Different database engines have different quirks of SQL syntax. Ur/Web tends to use Postgres idioms where there are choices to be made, though the compiler translates SQL as needed to support other backends.
178
179 A command sequence like this can initialize a Postgres database, using a file \texttt{app.sql} generated by the compiler:
180 \begin{verbatim}
181 createdb app
182 psql -f app.sql app
183 \end{verbatim}
184
185 \item \texttt{mysql}: This is MySQL, another popular relational database engine that uses persistent server processes. Ur/Web needs transactions to function properly. Many installations of MySQL use non-transactional storage engines by default. Ur/Web generates table definitions that try to use MySQL's InnoDB engine, which supports transactions. You can edit the first line of a generated \texttt{.sql} file to change this behavior, but it really is true that Ur/Web applications will exhibit bizarre behavior if you choose an engine that ignores transaction commands.
186
187 A command sequence like this can initialize a MySQL database:
188 \begin{verbatim}
189 echo "CREATE DATABASE app" | mysql
190 mysql -D app <app.sql
191 \end{verbatim}
192
193 \item \texttt{sqlite}: This is SQLite, a simple filesystem-based transactional database engine. With this backend, Ur/Web applications can run without any additional server processes. The other engines are generally preferred for large-workload performance and full admin feature sets, while SQLite is popular for its low resource footprint and ease of set-up.
194
195 A command like this can initialize an SQLite database:
196 \begin{verbatim}
197 sqlite3 path/to/database/file <app.sql
198 \end{verbatim}
199 \end{itemize}
200
201 \item \texttt{-output FILENAME}: Set where the application executable is written.
202
203 \item \texttt{-protocol [http|cgi|fastcgi]}: Set the protocol that the generated application speaks.
204 \begin{itemize}
205 \item \texttt{http}: This is the default. It is for building standalone web servers that can be accessed by web browsers directly.
206
207 \item \texttt{cgi}: This is the classic protocol that web servers use to generate dynamic content by spawning new processes. While Ur/Web programs may in general use message-passing with the \texttt{send} and \texttt{recv} functions, that functionality is not yet supported in CGI, since CGI needs a fresh process for each request, and message-passing needs to use persistent sockets to deliver messages.
208
209 Since Ur/Web treats paths in an unusual way, a configuration line like this one can be used to configure an application that was built with URL prefix \texttt{/Hello}:
210 \begin{verbatim}
211 ScriptAlias /Hello /path/to/hello.exe
212 \end{verbatim}
213
214 \item \texttt{fastcgi}: This is a newer protocol inspired by CGI, wherein web servers can start and reuse persistent external processes to generate dynamic content. Ur/Web doesn't implement the whole protocol, but Ur/Web's support has been tested to work with the \texttt{mod\_fastcgi}s of Apache and lighttpd.
215
216 To configure a FastCGI program with Apache, one could combine the above \texttt{ScriptAlias} line with a line like this:
217 \begin{verbatim}
218 FastCgiServer /path/to/hello.exe -idle-timeout 99999
219 \end{verbatim}
220 The idle timeout is only important for applications that use message-passing. Client connections may go long periods without receiving messages, and Apache tries to be helpful and garbage collect them in such cases. To prevent that behavior, we specify how long a connection must be idle to be collected.
221
222 Here is some lighttpd configuration for the same application.
223 \begin{verbatim}
224 fastcgi.server = (
225 "/Hello/" =>
226 (( "bin-path" => "/path/to/hello.exe",
227 "socket" => "/tmp/hello",
228 "check-local" => "disable",
229 "docroot" => "/",
230 "max-procs" => "1"
231 ))
232 )
233 \end{verbatim}
234 The least obvious requirement is setting \texttt{max-procs} to 1, so that lighttpd doesn't try to multiplex requests across multiple external processes. This is required for message-passing applications, where a single database of client connections is maintained within a multi-threaded server process. Multiple processes may, however, be used safely with applications that don't use message-passing.
235
236 A FastCGI process reads the environment variable \texttt{URWEB\_NUM\_THREADS} to determine how many threads to spawn for handling client requests. The default is 1.
237 \end{itemize}
238
239 \item \texttt{-sql FILENAME}: Set where a database set-up SQL script is written.
240 \end{itemize}
167 241
168 242
169 \section{Ur Syntax} 243 \section{Ur Syntax}
170 244
171 In this section, we describe the syntax of Ur, deferring to a later section discussion of most of the syntax specific to SQL and XML. The sole exceptions are the declaration forms for relations, cookies, and styles. 245 In this section, we describe the syntax of Ur, deferring to a later section discussion of most of the syntax specific to SQL and XML. The sole exceptions are the declaration forms for relations, cookies, and styles.