···22import * as driz from "drizzle-orm";
33import { Fact } from ".";
44import { replicache_clients } from "../drizzle/schema";
55+import { Attributes } from "./attributes";
5666-export function FactWithIndexes(f: Fact) {
77+export function FactWithIndexes(f: Fact<keyof typeof Attributes>) {
78 let indexes: {
89 eav: string;
910 aev: string;
···1213 eav: `${f.entity}-${f.attribute}-${f.id}`,
1314 aev: `${f.attribute}-${f.entity}-${f.id}`,
1415 };
1515- if (f.data.type === "reference")
1616+ if (f.data.type === "reference" || f.data.type === "ordered-reference")
1617 indexes.vae = `${f.data.value}-${f.attribute}`;
1718 return { ...f, indexes };
1819}
+4-6
supabase/migrations/20240519231512_init.sql
···32323333CREATE UNIQUE INDEX entities_pkey ON public.entities USING btree (id);
34343535-CREATE INDEX facts_expr_idx ON public.facts USING btree (((data ->> 'value'::text))) WHERE ((data ->> 'type'::text) = 'reference'::text);
3535+CREATE INDEX facts_reference_idx ON public.facts USING btree (((data ->> 'value'::text))) WHERE (((data ->> 'type'::text) = 'reference'::text) OR ((data ->> 'type'::text) = 'ordered-reference'::text));
36363737CREATE UNIQUE INDEX facts_pkey ON public.facts USING btree (id);
3838···5151CREATE OR REPLACE FUNCTION public.get_facts(root uuid)
5252 RETURNS SETOF facts
5353 LANGUAGE sql
5454-AS $function$
5555- WITH RECURSIVE all_facts as (
5454+AS $function$WITH RECURSIVE all_facts as (
5655 select
5756 *
5857 from
···6665 facts f
6766 inner join all_facts f1 on (
6867 uuid(f1.data ->> 'value') = f.entity
6969- ) where f1.data ->> 'type' = 'reference'
6868+ ) where f1.data ->> 'type' = 'reference' or f1.data ->> 'type' = 'ordered-reference'
7069 )
7170select
7271 *
7372from
7474- all_facts;
7575- $function$
7373+ all_facts;$function$
7674;
77757876grant delete on table "public"."entities" to "anon";