package pq

import (
	
	
	nurl 
	
	
)
ParseURL no longer needs to be used by clients of this library since supplying a URL as a connection string to sql.Open() is now supported: sql.Open("postgres", "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full") It remains exported here for backwards-compatibility. ParseURL converts a url to a connection string for driver.Open. Example: "postgres://bob:secret@1.2.3.4:5432/mydb?sslmode=verify-full" converts to: "user=bob password=secret host=1.2.3.4 port=5432 dbname=mydb sslmode=verify-full" A minimal example: "postgres://" This will be blank, causing driver.Open to use all of the defaults
func ( string) (string, error) {
	,  := nurl.Parse()
	if  != nil {
		return "", 
	}

	if .Scheme != "postgres" && .Scheme != "postgresql" {
		return "", fmt.Errorf("invalid connection protocol: %s", .Scheme)
	}

	var  []string
	 := strings.NewReplacer(` `, `\ `, `'`, `\'`, `\`, `\\`)
	 := func(,  string) {
		if  != "" {
			 = append(, +"="+.Replace())
		}
	}

	if .User != nil {
		 := .User.Username()
		("user", )

		, _ = .User.Password()
		("password", )
	}

	if , ,  := net.SplitHostPort(.Host);  != nil {
		("host", .Host)
	} else {
		("host", )
		("port", )
	}

	if .Path != "" {
		("dbname", .Path[1:])
	}

	 := .Query()
	for  := range  {
		(, .Get())
	}

	sort.Strings() // Makes testing easier (not a performance concern)
	return strings.Join(, " "), nil