Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

PostgreSQL multi schema support with @computed #614

@lsmith77

Description

@lsmith77

It appears that when using PostgreSQL multi schema with @computed the generated SQL uses the default schema, rather than the schema specified in the computedField configuration (ie. selectFrom('myschema.table_name').

That being said, I am struggling to get the same results in my codebase using ORM 3.2.1. It keeps defaulting to the public schema rather than using my configuration.

import { ZenStackClient } from '@zenstackhq/orm';
import { PostgresDialect } from '@zenstackhq/orm/dialects/postgres';
import { schema, type SchemaType } from '../../zenstack/schema';
import { Pool } from 'pg';

export class DbService extends ZenStackClient<SchemaType> {
  constructor() {
    const computedFields = {
      Notice: {
        project_number: (eb) =>
          eb
            .selectFrom('myschema.project')
            .select('project.project_number')
            .whereRef('project.id', '=', 'project_id')
            .limit(1),
        source: (eb) =>
          eb
            .selectFrom('myschema.project')
            .select('project.source')
            .whereRef('project.id', '=', 'project_id')
            .limit(1),
      },
    };

    const options = {
      dialect: new PostgresDialect({
        pool: new Pool({ connectionString: process.env.POSTGRESQL_DB }),
      }),
      computedFields,
    };
    super(schema, options);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions