er2code/Database_Description_Language

The layout of the a file is a bit like C structs, and a bit like SQL.

Each relation is defined inside it's own struct block: User { ... attributes go here ... }

This statement will cause a User class to be created.

Each attribute is defined by the name of the attribute, followed by one or more whitespace separated attribute type definers, and terminated by a semicolon.

User {
    id serial;
    username string(30) default(noname) sort unique index;
    password string(40);
    email string(100);
}

This will cause the User relation to contain four attributes:

If the description above is used with er2code to generate PHP code, it should make it possible to write code like the following: #perl // Connect to the database. $db = new DataBase ();

$halfdan = $db->findUserByUsername ( 'halfdan' );
if ( $halfdan != null ) {
    print $halfdan->getUsername() . ' <' . $halfdan->getEmail() . '>';
}

// List is automatically sorted by username
foreach ( $db->listUser() as $user ) {
    print '<a href="user.php?id=' . $user->getId() . '">' . $user->getName() . '</a>';
}

Comments (0)

Post comment

If you wish, you can use markdown syntax in the comment field.