ORM is an Object–Relational database Mapper, being worked on by DKF.

Currently, it's available in the half-bakery only.

chorler 20230530: link is broken, half-bakery is broken.

It lacks a number of key features, such as the ability to tell if the database has been changed under its feet.


The object-relational mapper converts a database already containing information into classes (one per table) and objects (one per row, dynamically loaded). In particular, it introspects the database to discover its primary keys and foreign key relations in order to build the cross-links between table classes. It uses TDBC under the hood to actually manage the connections.

Database Class

The connection is bound by passing it as the argument when creating the object that represents the overall database:

ORM::Database create dbName tdbcConnection

[TODO: document the operations on dbs and tables]

Row Class

Each row is represented by an object with one method per column that acts as an accessor for that column:

row columnName ?newValue?

Without the newValue, it returns the current value of the column (which may be the name of an object in another table). With newValue, it updates the column (when setting a column that contains a foreign key, you set in the mapped value and the appropriate key id will be used on the back end).


package require tdbc::sqlite3
package require ORM

ORM::Database create crm [tdbc::sqlite3::connection new "/path/to/mydatabase.sqlite3"]

crm table order foreach o {
    puts "Order #[$o id]"
    puts "Customer: [[$o customer] firstname] [[$o customer] surname]"
    puts "Address: [[$o dispatch] house] [[$o dispatch] street]"
    puts "Address: [[$o dispatch] city], [[$o dispatch] state]"
    puts "Description:\n\t[$o description]"

See also

toorm - an object relational mapper for Tcl.