Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Table of Contents |
---|
Description
Blob A variables and attributes representing or attributes of type blob
representing a valid CSV files file can be parsed to collections a collection of object instances .
- Currently the parser only supports plain CSV files. Native Excel formats etc. are not supported.
- CSV files must have a single header line.
- Column names must match the attribute names as defined in the associated object type. For example an object’s first_name attribute will only be populated from the CSV file if the CSV file has a column with a header that is first_name Column headers that don’t match attributes from the associated object type will be ignored.
- Parsing is type-safe. For example an object with a birth_date attribute that is of type date must contain values that can be converted to a date value using the acting user’s preferred Locale and Time Zone.
- Any parsing errors will result in the entire transaction being rolled back. Details of the error can be inspected using the Helium logging service.
- Complex attributes are supported. For example the CSV file may contain a column header clinic.name This will automatically populate the name attribute of an object that is associated with the primary object through a simple relationship with the name clinic. Simple relationships are one-to-one and many-to-one relationships. Other relationships aren’t supported and will be ignored. The object instance that represents the named relationships will only be created if the value in the column is not null. So if none of the complex attributes access through a specific relationships is set to a non-null value, then that related object won’t be created.
Example code for extracting nurses from CSV in a blob type
by simply using the fromCsv
built-in function. Please read through this page for clarity on what defines a "valid" CSV file.
Example
The code snippets below demonstrates how the fromCsv
built-in function can be used populate a collection of Nurse object instances:
Formatting CSV Newline Character Files to Unix
CSV files created or manipulated using Microsoft Excel might not be compatible as is with Helium. This is due to the carriage-return character Excel uses namely, '/r'. To replace all '/r' characters with the standard Unix newlines the tr utility can be used.
The following will replace the carriage-return character and write the result to a new file:
language | bash |
---|---|
title | Unix newline |
Code Block | ||||
---|---|---|---|---|
| ||||
persistent object Clinic { string name; } persistent object Nurse { string first_name; string last_name; @ManyToOne date birth_date Clinic clinic; } object UploadedFile { blob data; } |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
Nurse[] extractNurses(UploadedFile f) { return Nurse:fromCsv(f.data); } |
Code Block |
---|
|
| |
first_name,last_name,clinic.name
Beatrice,Malherbe,Sonop Clinic
Pieter,Potgieter,Somerset Clinic |
Info |
---|
Note that CSV files created or manipulated using Microsoft Excel might need to be converted before importing into Helium. |
Additional Mentions and References
- Helium Tutorial Lesson 9
- Persistent Entity BIFs under Quick Reference
hidden | true |
---|