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

tern psql #78

Merged
merged 6 commits into from
Mar 27, 2023
Merged

tern psql #78

merged 6 commits into from
Mar 27, 2023

Conversation

abs3ntdev
Copy link
Contributor

This PR adds a new command tern psql. the command launches psql with a connstring derived from the config files/arguments passed to the command. It will look for PSQL_BIN_PATH for an alternative binary, such as pgcli, to use otherwise it will just use psql connstring.

@jackc
Copy link
Owner

jackc commented Mar 24, 2023

I'm not sure if this feature is the best approach to sharing configuration between tern and other programs (personally, I use PGSERVICE). But would it make sense to generalize this to something like tern print-connstring?

Then it could be used with psql like this:

$ psql `tern print-connstring`

This would allow passing other arguments to psql as well and using it with other programs that need a connstring.


Also, I'm not sure that the conn string generation is correct. Unless I missed something, it will miss any other arguments like sslmode=require.

@abs3ntdev
Copy link
Contributor Author

abs3ntdev commented Mar 25, 2023

Yeah I totally overlooked arguments. This should account for the values you can provide via config/cli (ssl mode and cert) and it will just use the connstring if its available from the config file or passed via cli so you can pass anything.

As for restructuring to just print out the connstring, I personaly think being able to just use tern to connect is more usable than piping the output of a command to another program but its up to you, I can restructure.

@jackc
Copy link
Owner

jackc commented Mar 25, 2023

I realize that

$ psql `tern print-connstring`

is not as convenient to type as

$ tern psql

but I think it is worth it because of the additional flexibility to work with any program and even for psql it allows passing arguments.


But one caveat with this whole feature is it is impossible to create a connstring for all connection configurations tern supports. At the very least SSH tunneling will never work, and I suspect there may be other settings as well. The only way to definitely work with every connection config would be to act as a proxy like I considered in #47.

@abs3ntdev
Copy link
Contributor Author

I changed it to print-connstring instead. I see your points about flexability and the ability to pass additional arguments. Let me know if I can do anything else

main.go Outdated
@@ -958,6 +994,8 @@ func appendConfigFromFile(config *Config, path string) error {
}

if connString, ok := file.Get("database", "conn_string"); ok {
config.ConnString = connString
fmt.Println(config.ConnString)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fmt.Println intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No thanks for catching that. It was just a test print I forgot to delete. Removed in the newest push.

@jackc jackc merged commit 0c6f330 into jackc:master Mar 27, 2023
@abs3ntdev abs3ntdev deleted the psql branch March 28, 2023 16:56
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

Successfully merging this pull request may close these issues.

2 participants