Docs » mkstored

Generate a .pm file from some DDL

NAME

mkstored - Generate a .pm file from some DDL

SYNOPSIS

  mkstored [-opts] modulename tablename

DESCRIPTION

Generates a new subclass of WebApp::Stored from a template. We read and parse the DDL for your application and generate a MAP hash for the class based on the structure of the underlying table. Code that should be included in the class must be placed in a separate file to avoid being overwritten each time; the convention is that if the stored class is called Foo, then the code lives in Foo::code (but places itself in the Foo package proper).

When we parse the DDL, we pay attention to the column(s) used in the primary key of the table in question, along with several other attributes of the table. We produce a static data structure in the resulting .pm file that captures this table meta-data, and which WebApp::Stored uses. For more information, see the description of options such as -oidful, below.

OPTIONOLOGIE

Many options have single-letter shorthands and long forms. Both are preceded by a single dash, but single-letter options cannot be collapsed as with some Unix utilities.

In all cases, if an option requires a value, it is given after an equal-sign, e.g.

  -option=value

or

  -o=value

if -o is a shorthand for -option.

Mkstored understands the following options:

-verbose (or -v)

-verbosity=int (or -V=int)

The first form increments the verbosity level every time it is seen. The second form sets the verbosity level to the integer specified. Higher verbosity levels mean more output.

-help

Print a short usage message. If you specify -verbose, you get this man page.

-version (also -copyright)

-license

Print our version and copyright, or our license.

-template=file (-t)

Use the named file as our template .pm file instead of our built-in template. Only do this if you really know what you are doing; at least look at template at the end of of mkstored itself for inspiration if you want to do this properly.

-out=file (-o)

Write our output on the named file.

-force (-F)

Overwrite the output file silently if it already exists.

-multirow (-M)

The table represents a many-to-one relationship; inform WebApp::Stored of this so that it can behave appropriately. See the WebAppp::Stored POD for mode information.

-oidful (-O)

The table represents an oidful table, by which we mean that the table (a) has a primary key that contains an automatically incremented sequence or other value that we do not know at INSERT time, and (b) that we are using a database for which the OID trick works (e.g. PostgreSQL). The OID trick is a way of recovering the value of all of the columns in a newly inserted row by asking the database for the values of the last row that it INSERTed. In PostgreSQL, the most efficient way to do this is by the row's OID, which is available in the DBD::Pg statement handle.

-data (-D)

This table represents static data, a little like an enumerated type. Load it all in when you construct any instance of this class, since if you need one bit of it you'll need all of it. For instance, if you use a table to represent different classes of users (advanced, intermediate, novice) and assign to each class a type number, you would specify that the class we generate is a static data table.

-dir=dir (-d)

Write our output file into the given directory.

-ddl=file (-l)

Read the DDL from the named file, instead of looking for a file named ddl.sql in the current directory.

-superclasse=superclasses

A comma- or space-separated string with a list of superclasses for the automatically generated class. Defaults to the single class WebApp::Stored.

EXAMPLE

To create a subclass of WebApp::Stored called MyApp::Person based on the person table defined in myapp-ddl.sql and put it in the file MyApp/Person.pm:

  $ mkstored -oidful -out=MyApp/Person.pm -ddl=myapp-ddl.sql \
      MyApp::Person person

VERSION HISTORY

Alice: Well I must say I've never heard it that way before...

Caterpillar: I know, I have improved it.

  0.2.3   16 Apr 06     attila  fixed typos, template boilerplate
  0.2.2   27 Feb 05     attila  added -superclasses
  0.2.1   16 Dec 04     attila  completely redid cli
  0.2.0   15 Dec 04     attila  fixed nasty whitespace bug
  0.1.0   25 May 03     attila  got tired of cutting and pasting

Fin.