Type | Read/write | Author | Availability |
Write | Finbourne | Provided with LUSID |
The Lusid.Calendar.Writer
provider enables you to write a Luminesce SQL query that creates, updates, or deletes one or more calendars in LUSID. Note that a calendar is just a repository for holiday dates; to add dates themselves to the calendar, use Lusid.Calendar.Date.Writer.
Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and interact with calendars 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 calendar per record. Lusid.Calendar.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 calendar; that is, create a calendar if it does not exist, and update certain fields if it does. This is the default operation if you omit
WriteAction
.Insert (create) a calendar. This operation fails if the calendar already exists.
Update a calendar. This operation fails if the calendar does not already exist.
Delete a calendar.
See also: Lusid.Calendar, Lusid.Calendar.Date.Writer
Basic usage
@table_of_data = <select-statement>;
select * from Lusid.Calendar.Writer where toWrite = @table_of_data;
Query parameters
Lusid.Calendar.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.Calendar.Writer' and FieldType = 'Parameter';
Data fields
Lusid.Calendar.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:
Operation | Mandatory fields |
Upsert, Insert |
|
Update |
|
Delete |
|
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.Calendar.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.Calendar.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 'HolidayCalendars' as Scope, 'my_csv' as SourceProvider, 'UTC' as WeekendMaskTimeZone, 'Saturday, Sunday' as WeekendMaskDays, 'Holiday' as Type;
select WriteErrorCode, WriteError, WriteErrorDetail from Lusid.Calendar.Writer where toWrite = @table_of_data;
... fails because a Code
is not specified.
Examples
Note: For more example Luminesce SQL queries, visit our Github repo.
Example 1: Create a calendar
You can create a calendar in your LUSID domain by supplying all mandatory fields and using 'insert' as WriteAction
.
@table_of_data = select 'HolidayCalendars' as Scope, 'MyNewHolidayCalendar' as Code, 'my_csv' as SourceProvider,
'UTC' as WeekendMaskTimeZone, 'Saturday, Sunday' as WeekendMaskDays, 'Holiday' as Type, 'insert' as WriteAction;
select WriteError, WriteErrorCode, WriteErrorDetail from Lusid.Calendar.Writer where ToWrite = @table_of_data;
Example 2: Update a calendar with additional details
You can update an existing calendar, such as updating the WeekendMaskDays
, by supplying the mandatory fields, the fields you want to update, and by using 'update' as WriteAction
.
@table_of_data = select 'HolidayCalendars' as Scope, 'MyNewHolidayCalendar' as Code, 'my_csv' as SourceProvider, 'UTC' as WeekendMaskTimeZone,
'Friday, Saturday' as WeekendMaskDays, 'Holiday' as Type, 'update' as WriteAction;
select WriteError, WriteErrorCode, WriteErrorDetail from Lusid.Calendar.Writer where ToWrite = @table_of_data;
Example 3: Delete an existing calendar
You can delete an existing calendar by supplying the mandatory fields and using 'delete' as WriteAction
.
@table_of_data = select 'HolidayCalendars' as Scope, 'MyNewHolidayCalendar' as Code, 'delete' as WriteAction;
select * from Lusid.Calendar.Writer where ToWrite = @table_of_data;
Example 4: Create multiple calendars at the same time
You can create all your calendars 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
('HolidayCalendars', 'USD', 'my_csv_usd', 'UTC', 'Saturday, Sunday', 'Holiday'),
('HolidayCalendars', 'AUD', 'my_csv_aud', 'UTC', 'Saturday, Sunday', 'Holiday'),
('TradingHours', 'EUR', 'my_csv_eur_trading_hours', 'UTC', 'Saturday, Sunday', 'TradingHours');
@table_of_data = select column1 as Scope, column2 as Code, column3 as SourceProvider, column4 as WeekendMaskTimeZone,
column5 as WeekendMaskDays, column6 as Type from @vals;
select * from Lusid.Calendar.Writer where ToWrite = @table_of_data;