Qore TableMapper Module Reference: TableMapper Module

Qore TableMapper Module Reference 1.0

- Main Page
- Related Pages
- Namespaces
- Classes

All Classes Namespaces Functions Variables Groups Pages
TableMapper Module

# TableMapper Module Introduction

Classes provided by this module:

- InboundTableMapper: extends the Mapper::Mapper class; assumes an SQL table target
- InboundTableMapperIterator: provides a specialization of the Mapper::AbstractMapperIterator class; assumes an SQL table target; automatically inserts mapped data into the target table based on the mapper provided

# TableMapper Examples

The following is an example map hash with comments:

const DataMap = (
# output column: "id" mapper from the "Id" element of any "^attributes^" hash in the input record
"id": "^attributes^.Id",
# output column: "name": maps from an input field with the same name (no translations are made)
"name": True,
# output column: "explicit_count": maps from the input "Count" field, if any value is present then it is converted to an integer
"explicit_count": ("type": "int", "name": "Count"),
# output column: "implicit_count": runs the given code on the input record and retuns the result, the code returns the number of "Products" sub-records
"implicit_count": int sub (any $ignored, hash $rec) { return $rec.Products.size(); },
# output column: "order_date": converts the "OrderDate" string input field to a date in the specified format
"order_date": ("name": "OrderDate", "date_format": "DD.MM.YYYY HH:mm:SS.us"),
);

If this map is applied in the following way:

my Table $table($ds, "order_table");
my TableMapper $map($table, DataMap);
{
on_success $map.commit();
on_error $map.rollback();
# apply the map and insert the mapped for for each input record
map $map.insertRowNoCommit($1), $input;
}
printf("%d record%s inserted\n", $map.getCount(), $map.getCount() == 1 ? "" : "s");

This will insert all the mapped input data into data into the `ORDER_TABLE` table and then print out the number of rows inserted.

# Release Notes

## TableMapper v1.0

Initial release.