<commit_before>﻿select dropIfExists('VIEW', 'item_substitute', 'xm');

-- return rule

create or replace view xm.item_substitute as

select
  itemsub_id as id,
  itemsub_parent_item_id as root_item,
  itemsub_sub_item_id as substitute_item,
  itemsub_uomratio as conversion_ratio,
  itemsub_rank as rank
from itemsub;

-- insert rule

create or replace rule "_CREATE" as on insert to xm.item_substitute
  do instead

insert into itemsub (
  itemsub_id,
  itemsub_parent_item_id,
  itemsub_sub_item_id,
  itemsub_uomratio,
  itemsub_rank )
values (
  new.id,
  new.root_item,
  new.substitute_item,
  new.conversion_ratio,
  new.rank );

-- update rule

create or replace rule "_UPDATE" as on update to xm.item_substitute
  do instead

update itemsub set
  itemsub_sub_item_id = new.substitute_item,
  itemsub_uomratio = new.conversion_ratio,
  itemsub_rank = new.rank
where ( itemsub_id = old.id );

-- delete rule

create or replace rule "_DELETE" as on delete to xm.item_substitute
  do instead

delete from itemsub
where ( itemsub_id = old.id );<commit_msg>updated xm.item_substitute to use private.create_model()<commit_after>﻿select private.create_model(

-- Model name, schema, table

'item_substitute', 'public', 'itemsub',

-- Columns

E'{
  "itemsub.itemsub_id as id",
  "itemsub.itemsub_parent_item_id as root_item",
  "itemsub.itemsub_sub_item_id as substitute_item",
  "itemsub.itemsub_uomratio as conversion_ratio",
  "itemsub.itemsub_rank as rank"
}',

-- Rules

E'{"

-- insert rule

create or replace rule \\"_CREATE\\" as on insert to xm.item_substitute
  do instead

insert into itemsub (
  itemsub_id,
  itemsub_parent_item_id,
  itemsub_sub_item_id,
  itemsub_uomratio,
  itemsub_rank )
values (
  new.id,
  new.root_item,
  new.substitute_item,
  new.conversion_ratio,
  new.rank );

","

-- update rule

create or replace rule \\"_UPDATE\\" as on update to xm.item_substitute
  do instead

update itemsub set
  itemsub_sub_item_id = new.substitute_item,
  itemsub_uomratio = new.conversion_ratio,
  itemsub_rank = new.rank
where ( itemsub_id = old.id );

","

-- delete rule

create or replace rule \\"_DELETE\\" as on delete to xm.item_substitute
  do instead

delete from itemsub
where ( itemsub_id = old.id );

"}',

-- Conditions, Comment, System

'{}', 'Item Substitute Model', true);
{'fraction_non_alphanumeric': 0.09303331890956296, 'fraction_numerical': 0.0, 'mean_word_length': 4.218961625282167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1885114', 'n_tokens_mistral': 847, 'n_tokens_neox': 824, 'n_words': 217}