Qore TableMapper Module Reference  1.0
TableMapper Module

TableMapper Module Introduction

Classes provided by this module:

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
"explicit_count": "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"),
# output column: order_type: given as a constant value
"order_type": ("constant": "NEW"),
);

If this map is applied in the following way:

my Table $table($ds, "order_table");
my InboundTableMapper $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.1

  • added table name to error messages

TableMapper v1.0

  • Initial release.