InterSystems IRIS Objects and SQL
During this tutorial, you've seen and written many class methods. InterSystems IRIS also allows you to write code to access persistent objects of classes, as well as write SQL queries to access rows in tables. You can think of the Person records you've stored in the ^PersonD global as 1) persistent objects in the Person class, and 2) rows in the Person relational table. A full discussion of classes, objects, properties, methods, and queries is beyond the scope of this tutorial. You can learn about these topics using online learning and the documentation; a good starting place is learning.intersystems.comOpens in a new tab. The last few pages of this tutorial provide a brief look at InterSystems IRIS Objects.
Here's an example of a class definition for persistent Person objects that matches the work you did in your data entry class.
-
It has three properties for Name, Phone, and DOB. Name and Phone use pattern matching for validation, and DOB uses a condition based on $horolog.
-
It has two calculated properties for LastName and FirstName.
-
It has Name, Phone (unique), and DOB indexes, and a bitmap index of ID numbers (called an Extent index).
/// Persistent class for Persons
Class ObjectScript.Person Extends %Persistent
{
Property Name As %String(PATTERN="1U.L1"",""1U.L");
Property LastName As %String [ Calculated, SqlComputeCode = {set {LastName}=$p({Name},",",1)}, SqlComputed ];
Property FirstName As %String [ Calculated, SqlComputeCode = {set {FirstName}=$p({Name},",",2)}, SqlComputed ];
Property Phone As %String(PATTERN="3n1""-""3n1""-""4n");
Property DOB As %Date(MAXVAL = "$piece($horolog, "","", 1)");
/// Index for LastName,FirstName
Index NameIndex On (LastName, FirstName);
/// Uniqueness index for property Phone
Index PhoneIndex On Phone [ Unique ];
/// Index for property DOB
Index DOBIndex On DOB;
/// Bitmap index of ID numbers
Index IDIndex [Extent, Type = bitmap];
}