Equals comparison
Not equals comparison
Greater than comparison
Greater than or equal comparison
Less than comparison
Less than or equal comparison
IN membership check
Contains operator (for arrays/JSONB)
IS NULL check
IS NOT NULL check
Check if column equals current user ID (owner check)
Shorthand for .eq(auth.uid()) - commonly used for user ownership checks.
Check if column equals true (public visibility check)
Shorthand for .eq(true) - commonly used for public visibility.
Check if column equals the tenant ID from session variable (multi-tenant isolation)
Shorthand for .eq(session.get(sessionKey, 'integer')) - used for tenant isolation.
Session variable key (default: 'app.current_tenant_id')
// Restrict all access to current tenant
policy('tenant_isolation')
.on('documents')
.all()
.requireAll()
.when(column('tenant_id').belongsToTenant());
// Custom session key
policy('org_isolation')
.on('projects')
.all()
.requireAll()
.when(column('org_id').belongsToTenant('app.current_org_id'));
Check if column value is in a subquery from a join table where user is a member
Generates an IN subquery to check membership in a join table.
The join/membership table name
The foreign key column in the join table
The local key column in the current table (default: 'id')
// Users can see projects they're members of
policy('member_projects')
.on('projects')
.read()
.when(column('id').isMemberOf('project_members', 'project_id'));
// Users can see organizations they belong to
policy('org_access')
.on('organizations')
.read()
.when(
column('id').isMemberOf('organization_members', 'organization_id')
);
Check if column value belongs to user via membership table
The membership table name
OptionalmembershipColumn: stringOptional column name in membership table (defaults to same as column)
Check if column (date) is less than or equal to a reference date
OptionalreferenceDate: DateOptional reference date (defaults to current date)
Column builder class for fluent condition building