Tsugi

OrgScope
in package

One organization and its ancestors or descendants, as a SQL relation.

This is not a list of ids. Embed cte() in a larger statement, then filter with in() or join the relation with join(). params() are the bound values. The caller writes WITH RECURSIVE. Two scopes in one statement need different CTE names so the aliases and parameter names do not collide.

The anchor limits the walk to one tenant key. The recursive step repeats that limit by joining key_id, so the walk cannot cross tenants.

Table of Contents

Properties

$anchorSql  : string
$maxDepth  : int
$name  : string
$orgTable  : string
$params  : array<string, int>
$upward  : bool

Methods

__construct()  : mixed
checkColumn()  : string
checkName()  : string
cte()  : string
Recursive CTE body, without the WITH RECURSIVE keyword.
in()  : string
Filter a column against this set.
join()  : string
Join this set to a column.
name()  : string
params()  : array<string, int>

Properties

$params

private array<string, int> $params

Methods

__construct()

public __construct(string $name, string $anchorSql, bool $upward, string $orgTable, int $maxDepth, array<string, int> $params) : mixed
Parameters
$name : string

CTE alias, already checked

$anchorSql : string

anchor SELECT, already limited to one tenant

$upward : bool

true walks parents, false walks children

$orgTable : string

prefixed lti_org table

$maxDepth : int
$params : array<string, int>

checkColumn()

public static checkColumn(string $column) : string
Parameters
$column : string
Return values
string

checkName()

public static checkName(string $name) : string
Parameters
$name : string
Return values
string

cte()

Recursive CTE body, without the WITH RECURSIVE keyword.

public cte() : string
Return values
string

in()

Filter a column against this set.

public in(string $column) : string

d.org_id becomes: d.org_id IN (SELECT org_id FROM org_ancestors)

Parameters
$column : string

table alias and column, such as d.org_id

Return values
string

join()

Join this set to a column.

public join(string $column) : string

d.org_id becomes: INNER JOIN org_ancestors ON org_ancestors.org_id = d.org_id

Parameters
$column : string

table alias and column, such as d.org_id

Return values
string

name()

public name() : string
Return values
string —

CTE name

params()

public params() : array<string, int>
Return values
array<string, int>

        
On this page

Search results