Skip to Content

CRUD Cram Rule

In Vinyl you can create what is called a CRUD Cram Rule in the Business Logic Layer to insert new records into a data source, but not affect existing records if they violate a Primary Key constraint.

This rule is like a CRUD Insert, but it won't fail if a Primary Key already exists. Meaning that it will only create a new record if the Primary Key does not exist in the data source, otherwise it will do nothing.

This feature is well-suited to tables fed by an API or other server connection imports, as it will not fail when existing records are imported but will still add new records to the table.

To create a CRUD Cram Rule

In order to create a CRUD Cram Rule, start by choosing the Table you wish to target with the Cram Rule and create a Business Rule for that Table.

  1. Navigate to the App Workbench > + Rule
  2. Select the desired data source
  3. Assign the rule Name, which should include information on the rule's purpose
  4. Choose CRUD for the Purpose

    • If you are cramming from an external data source, choose XP CRUD as the Purpose
    • Choose the external data source as the Source Data Source
    • Choose the data source you are cramming into as Target Data Source
    • Further instructions on linking data sources are available in the linked article
  5. Choose Cram for Action

  6. Click Save

Next you define the mvSQL logic required for the rule, which involves specifying the Columns you wish to Cram into the Target Table.

  1. Click the Columns navigation tab
  2. Add the Columns from the source Table and set the Target Column (set an Alias to match Target Columns if necessary).
    • For XP CRUD Rules, there is an additional configuration step required here. You also need to specify a Column's Target Type as either Bind or Target. Target Type provides instruction on whether to target the column to Bind between query and table or target to update the field.

This completes the creation of the CRUD Cram rule.

If you would like to use this CRUD Cram rule every time the external data source imports new data, add this rule to Schedules by navigating to IDE > Monitoring > Schedules to create a new schedule or add this rule to an existing Schedule.