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

Is it possible to support setting username and password ? #401

Open
DemoLiang opened this issue Oct 19, 2024 · 1 comment
Open

Is it possible to support setting username and password ? #401

DemoLiang opened this issue Oct 19, 2024 · 1 comment

Comments

@DemoLiang
Copy link

Is it possible to support setting username and password like MySQL to allow connection to the database,and only this username/password can connect to the database

@0xOlias
Copy link
Contributor

0xOlias commented Oct 23, 2024

My mental model for PGlite is that when you run new PGlite(...), you establish a single connection / session. All queries to that PGlite instance use that connection. When you run instance.close(), it closes the connection.

As far as I can tell, PGlite supports the full Postgres user / role / permission system. However, you can only run one PGlite instance at a time for a given dataDir. So, unlike with a traditional Postgres server, only one database user can be connected at a time.

So, you can still create database users (as demonstrated in this test file) but to switch users, you have to close the current instance and open a new one, specifying the new username in the constructor.

I think it's technically possible to change users during a session with traditional Postgres, but it's uncommon and I doubt PGlite supports this.

Please correct me if I'm wrong @samwillis !

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

No branches or pull requests

2 participants