Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying schema for DB connection #45

Open
w00ing opened this issue Oct 27, 2022 · 4 comments
Open

Specifying schema for DB connection #45

w00ing opened this issue Oct 27, 2022 · 4 comments
Labels
feature request New feature or request

Comments

@w00ing
Copy link

w00ing commented Oct 27, 2022

Our project has several schemas in a single postgres database. Is there an option to target only specific schema? I already tried to set schema in database url like below,

DATABASE_URL=postgres://username:password@yourdomain.com/database?schema=my_schema
and
DATABASE_URL=postgres://username:password@yourdomain.com/database?search_path=my_schema

but neither worked. Is there any idea?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@w00ing w00ing changed the title Specifying schema Specifying schema for DB connection Oct 27, 2022
@RobinBlomberg
Copy link
Owner

It should be doable with --include-pattern=my_schema.*. That option appears to be broken at the moment, but it should be fixed for the next release.

@RobinBlomberg
Copy link
Owner

Try it out in kysely-codegen@0.8.0!

@RobinBlomberg RobinBlomberg added the question Further information is requested label Nov 4, 2022
@eGust
Copy link
Contributor

eGust commented Jan 28, 2023

Just tried with kysely-codegen@0.9.0 and didn't work.

Created a schema named demo and created table test_foo in both public and demo

CREATE TABLE demo.test_foo (
	id bigserial NOT NULL,
	"name" varchar(64) NULL,
	is_enabled bool NOT NULL DEFAULT true,
	CONSTRAINT test_foo_pk PRIMARY KEY (id)
);

Generated without --include-pattern:

export interface DemoTestFoo {
  id: Generated<Int8>;
  name: string | null;
  isEnabled: Generated<Boolean>;
}

export interface TestFoo {
  id: Generated<Int8>;
  name: string | null;
  isEnabled: Generated<Boolean>;
}

export interface DB {
  "demo.testFoo": DemoTestFoo;
  testFoo: TestFoo;
}

Generated with --include-pattern 'demo.*':

export interface DemoTestFoo {
  id: Generated<Int8>;
  name: string | null;
  isEnabled: Generated<Boolean>;
}

export interface DB {
  "demo.testFoo": DemoTestFoo;
}

In my use case, there will be multiple schemas with the same structure. I don't want the Demo or demo. prefixes at all.

@RobinBlomberg RobinBlomberg added feature request New feature or request and removed question Further information is requested labels Feb 6, 2023
@maslennikov
Copy link

Right now filtering by schema and removing schema prefixes is possible due to #56 like that:

kysely-codegen --schema auth --include-pattern 'auth.*' 

But passing schema name like this is a bit awkward and inconsistent with .env file config when we define DATABASE_URL.

Maybe we could support another .env var to enable filtering with setting of something like DATABASE_SCHEMA=auth?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants