def expr(self, s : 'Schema')->CQLExpr: a = self.realize(s) if isinstance(a,Attr): dtype = a.dtype.name elif isinstance(a,FK): dtype = a.tar else: raise TypeError g = CQLGen(self.obj,self.obj) return CQLGenAttr(self.attr,dtype,g)
def fk_constraints(self) -> L[Constraint]: '''Constraints that enforce the FK relations, to be used in an CQL chase''' g1,g2 = [CQLGen(x,self.name) for x in ['x0','x1']] s = 'where x0.uid=x1.uid -> where x0=x1' out = Constraint([g1,g2],s.format(self.name)) s2 = '-> exists unique y0:{1} where x0.{2}=y0.uid' out2 = [Constraint([g1],s2.format(self.name,fk.tar,fk.name)) for fkn,fk in self.fks.items()] return [out] + out2
def genattr(self) -> 'CQLGenAttr': g = CQLGen(self.obj,self.obj) return CQLGenAttr(self.name,self.dtype.name,g)
def gen(self)->CQLGen: return CQLGen(self.name,self.ent.name)