RLS DSL - v0.1.0
    Preparing search index...

    Class ColumnBuilder

    Column builder class for fluent condition building

    Index

    Constructors

    Methods

    • Contains operator (for arrays/JSONB)

      Parameters

      • value:
            | string
            | number
            | boolean
            | Date
            | (string | number | boolean | Date | null)[]
            | null

      Returns ConditionChain

      // Check if array column contains values
      column('tags').contains(['important', 'urgent'])

      // Check if JSONB contains value
      column('metadata').contains({ status: 'active' })
    • Check if column equals current user ID (owner check)

      Shorthand for .eq(auth.uid()) - commonly used for user ownership checks.

      Returns ConditionChain

      // Users can only see their own documents
      policy('user_docs')
      .on('documents')
      .read()
      .when(column('user_id').isOwner());

      // Users can only update their own profile
      policy('update_profile')
      .on('profiles')
      .update()
      .when(column('user_id').isOwner());
    • Check if column equals true (public visibility check)

      Shorthand for .eq(true) - commonly used for public visibility.

      Returns ConditionChain

      // Anyone can see public documents
      policy('public_docs')
      .on('documents')
      .read()
      .when(column('is_public').isPublic());

      // Users can see their own docs OR public docs
      policy('view_docs')
      .on('documents')
      .read()
      .when(
      column('user_id').isOwner()
      .or(column('is_public').isPublic())
      );
    • Check if column equals the tenant ID from session variable (multi-tenant isolation)

      Shorthand for .eq(session.get(sessionKey, 'integer')) - used for tenant isolation.

      Parameters

      • sessionKey: string = "app.current_tenant_id"

        Session variable key (default: 'app.current_tenant_id')

      Returns ConditionChain

      // 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.

      Parameters

      • joinTable: string

        The join/membership table name

      • foreignKey: string

        The foreign key column in the join table

      • localKey: string = "id"

        The local key column in the current table (default: 'id')

      Returns ConditionChain

      // 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')
      );