diff src/view_loader.ts @ 97:26c55d5d5202

WIP on views & joins
author drewp@bigasterisk.com
date Fri, 11 Feb 2022 20:27:02 -0800
parents 47d3b5a5bd5e
children
line wrap: on
line diff
--- a/src/view_loader.ts	Thu Jan 13 21:32:18 2022 -0800
+++ b/src/view_loader.ts	Fri Feb 11 20:27:02 2022 -0800
@@ -12,6 +12,13 @@
   throw new Error("no elems");
 }
 
+export interface TableDesc {
+  uri: NamedNode;
+  primary: NamedNode;
+  joins: NamedNode[];
+}
+
+
 export class View {
   graph: Store;
   ready: Promise<null>;
@@ -42,11 +49,16 @@
   }
 
   // filtered+ordered list of types to show at the top level
-  typesToShow(typesPresent: NamedNode[]): NamedNode[] {
-    const ret: NamedNode[] = [];
+  toplevelTables(typesPresent: NamedNode[]): TableDesc[] {
+    const ret: TableDesc[] = [];
     for (let table of this.graph.getObjects(this.viewRoot, EX("table"), null)) {
-      const tableType = uriValue(this.graph, table, EX("showsType"));
-      ret.push(tableType);
+      const tableType = uriValue(this.graph, table, EX("primaryType"));
+      const joins: NamedNode[] = [];
+      for (let joinType of this.graph.getObjects(table, EX("joinType"), null)) {
+        joins.push(joinType as NamedNode);
+      }
+      joins.sort();
+      ret.push({ uri: table as NamedNode, primary: tableType, joins: joins });
     }
     ret.sort();
     return ret;