Type | Read/write | Author | Availability |
Data provider | Write | Finbourne | Provided with LUSID |
The Lusid.Relationship.Definition.Writer
provider enables you to write a Luminesce SQL query that either upserts or deletes relationship types between entity types that support relationships.
Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and interact with relationship type data in LUSID. This should automatically be the case if you are the domain owner.
You must construct a valid table of data to write, one relationship type per record. Lusid.Relationship.Definition.Writer
lists the fields (columns) available to populate with values for each record, and has a set of parameters to help you construct a valid table.
Your query can use the WriteAction
field to perform one of the following operations:
- Upsert a relationship type; that is, create one if it does not exist, and update it if it does. This is the default operation if you omit
WriteAction
. - Insert (create) a relationship type. This operation fails if the relationship type already exists.
- Update a relationship type. Note it is only possible to update the
DisplayName
,OutwardDescription
andInwardDescription
fields. This operation fails if the relationship type does not exist. - Delete a relationship type.
See also: Lusid.Relationship.Definition
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.Relationship.Definition.Writer where toWrite = @table_of_data;
Query parameters
Lusid.Relationship.Definition.Writer
has parameters that help you construct a valid table of data to write.
Note: The toWrite
parameter is mandatory and used to actually write the table of data into LUSID.
To list available parameters, their data types, default values, and an explanation for each, run the following query using a suitable tool:
select FieldName, DataType, ParamDefaultValue, Description from Sys.Field where TableName = 'Lusid.Relationship.Definition.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Relationship.Definition.Writer
lists the fields you can populate in your table of data to write.
Depending on the operation you want to perform, the following fields are mandatory to include in the table of data to write:
Operation | Specify using... | Mandatory fields | Notes |
Upsert | 'Upsert' as WriteAction (or omit) | Scope Code DisplayName SourceEntityType TargetEntityType OutwardDescription InwardDescription Lifetime RelationshipCardinality |
|
Insert | 'Insert' as WriteAction | ||
Update | 'Update' as WriteAction | Scope Code SourceEntityType TargetEntityType Lifetime RelationshipCardinality | You can update the OutwardDescription , InwardDescription and DisplayName fields. |
Delete | 'Delete' as WriteAction | Scope Code |
To list all available fields, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a suitable tool:
select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Lusid.Relationship.Definition.Writer' and FieldType = 'Column';
Write errors
We recommend examining the results of every write query using one or more of the WriteError
, WriteErrorCode
and WriteErrorDetail
fields.
For each record in the table of data to write, Lusid.Relationship.Definition.Writer
returns an error code. If the operation is successful, the error code is 0
. If unsuccessful, a positive error code and explanation help you discover why LUSID considers the operation invalid.
For example, the query:
@table_of_data = select 'PortfolioManagementTeam' as Scope, 'Managers' as Code, 'Portfolio' as SourceEntityType, 'Person' as TargetEntityType,
'TimeVariant' as Lifetime, 'ManyToOne' as RelationshipCardinality;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.Relationship.Definition.Writer where toWrite = @table_of_data;
...fails because no DisplayName
, OutwardDescription
and InwardDescription
were provided in the query.
Examples
Note: For more example Luminesce SQL queries, visit our Github repo.
Example 1: Create a relationship type between portfolio entities and person entities
You can create a relationship type by supplying the mandatory fields and using 'Insert' as WriteAction
.
@table_of_data = select 'PortfolioManagementTeam' as Scope, 'Managers' as Code, 'Authorised managers for portfolios' as DisplayName,
'Portfolio' as SourceEntityType, 'Person' as TargetEntityType, 'Is managed by' as OutwardDescription, 'Manages' as InwardDescription,
'TimeVariant' as Lifetime, 'ManyToOne' as RelationshipCardinality, 'insert' as WriteAction;
select * from Lusid.Relationship.Definition.Writer where ToWrite = @table_of_data;
Example 2: Create a relationship type between custom entities
If either SourceEntityType
or TargetEntityType
are custom entities, specify the custom entity type name:
@table_of_data = select 'Locations' as Scope, 'Branches' as Code, 'Regional offices and local branches' as DisplayName,
'Office' as SourceEntityType, 'Office' as TargetEntityType, 'Responsible for' as OutwardDescription, 'Reports to' as InwardDescription,
'TimeVariant' as Lifetime, 'ManyToOne' as RelationshipCardinality, 'insert' as WriteAction;
select * from Lusid.Relationship.Definition.Writer where ToWrite = @table_of_data;
Example 3: Update a relationship type with additional details
You can update an existing relationship type, perhaps to change the DisplayName
, by supplying the mandatory fields, the field(s) you want to update, and by using 'Update' as WriteAction
.
@table_of_data = select 'PortfolioManagementTeam' as Scope, 'Managers' as Code, 'These are the authorised managers for portfolios' as DisplayName,
'Portfolio' as SourceEntityType, 'Person' as TargetEntityType, 'Is managed by' as OutwardDescription, 'Manages' as InwardDescription,
'TimeVariant' as Lifetime, 'ManyToOne' as RelationshipCardinality, 'update' as WriteAction;
select * from Lusid.Relationship.Definition.Writer where ToWrite = @table_of_data;
Example 4: Delete a relationship type
You can delete an existing relationship type by specifying a Scope
and Code
and by using 'Delete' as WriteAction
:
@table_of_data = select 'PortfolioManagementTeam' as Scope, 'Managers' as Code, 'delete' as WriteAction;
select * from Lusid.Relationship.Definition.Writer where ToWrite = @table_of_data;
Example 5: Create multiple relationship types at the same time
You can create all your relationship types at the same time in one Luminesce query. In this example, the query defaults to an upsert operation as no explicit WriteAction
is specified.
@vals = values
('PortfolioManagementTeam', 'Managers', 'Authorised managers for portfolios', 'Portfolio', 'Person', 'Is managed by', 'Manages', 'TimeVariant', 'ManyToOne'),
('Instruments', 'InstrumentLegalEntities', 'Issuers for instruments', 'Instrument', 'LegalEntity', 'Is issued by', 'Issues', 'Perpetual', 'ManyToOne');
@table_of_data = select column1 as Scope, column2 as Code, column3 as DisplayName, column4 as SourceEntityType, column5 as TargetEntityType,
column6 as OutwardDescription, column7 as InwardDescription, column8 as Lifetime, column9 as RelationshipCardinality from @vals;
select * from Lusid.Relationship.Definition.Writer where ToWrite = @table_of_data;