<commit_before>-- the 
 comments are for sql2pas

create table if not exists node (
  ID integer primary key,
  name text unique );

--

create table if not exists edge (
   ID integer primary key,
   subID integer,
   relID integer,
   objID integer,
   seq   integer,
   began datetime default 'now',
   ended datetime default null );
--

create view if not exists trip as
  select
    arc.ID as ID,
    sub.name as sub,
    rel.name as rel,
    obj.name as obj
  from edge arc, node sub, node rel, node obj
  where arc.subID=sub.ID
    and arc.relID=rel.ID
    and arc.objID=obj.ID
    and ended is null;
--

-- management of the triplestore

create trigger if not exists del_triple
  instead of delete on trip
  begin
    update edge set ended = 'now' where edge.id = old.id;
  end;
--

create trigger if not exists new_triple
  instead of insert on trip
  begin
    replace into node (name) values (new.sub), (new.rel), (new.obj);
    insert into edge (subID, relID, objID, began)
    select (select ID from node where name=new.sub) as subID, 
           (select ID from node where name=new.rel) as relID,
           (select ID from node where name=new.obj) as objID,
	   'now' as began;
  end;<commit_msg>min/nodak.sql: capture last_insert_rowid when updating view<commit_after>-- the 
 comments are for sql2pas

create table if not exists node (
  ID integer primary key,
  name text unique );

--

create table if not exists edge (
   ID integer primary key,
   subID integer,
   relID integer,
   objID integer,
   seq   integer,
   began datetime default 'now',
   ended datetime default null );
--

create view if not exists trip as
  select
    arc.ID as ID,
    sub.name as sub,
    rel.name as rel,
    obj.name as obj
  from edge arc, node sub, node rel, node obj
  where arc.subID=sub.ID
    and arc.relID=rel.ID
    and arc.objID=obj.ID
    and ended is null;
--

-- management of the triplestore
create table if not exists meta (
  id integer primary key,
  k text unique,
  v variant );
--

create trigger if not exists del_triple
  instead of delete on trip
  begin
    update edge set ended = 'now' where edge.id = old.id;
  end;
--

create trigger if not exists new_triple
  instead of insert on trip
  begin
    replace into node (name) values (new.sub), (new.rel), (new.obj);
    insert into edge (subID, relID, objID, began)
    select (select ID from node where name=new.sub) as subID, 
           (select ID from node where name=new.rel) as relID,
           (select ID from node where name=new.obj) as objID,
	   'now' as began;
    replace into meta ('k','v')
      values ('last_insert_rowid', last_insert_rowid());
  end;
{'fraction_non_alphanumeric': 0.08182503770739065, 'fraction_numerical': 0.0007541478129713424, 'mean_word_length': 2.731364275668073, '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': '2074230', 'n_tokens_mistral': 845, 'n_tokens_neox': 839, 'n_words': 356}