-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pgpool. manually set search_path (schema parameter)
- Loading branch information
Showing
13 changed files
with
61 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package pg | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/jackc/pgx/v5/pgxpool" | ||
"regexp" | ||
) | ||
|
||
var schemaRegex = regexp.MustCompile(`(?:search_path|schema)=([^$]+)`) | ||
|
||
func extractSchema(url string) string { | ||
parts := schemaRegex.FindStringSubmatch(url) | ||
if len(parts) == 2 { | ||
return parts[1] | ||
} else { | ||
return "" | ||
} | ||
} | ||
|
||
func NewPGPool(url string) (*pgxpool.Pool, error) { | ||
pgCfg, err := pgxpool.ParseConfig(url) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unable to create postgres connection pool: %v\n", err) | ||
} | ||
schema := extractSchema(url) | ||
if schema != "" { | ||
pgCfg.ConnConfig.RuntimeParams["search_path"] = schema | ||
} | ||
dbpool, err := pgxpool.NewWithConfig(context.Background(), pgCfg) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unable to create postgres connection pool: %v\n", err) | ||
} | ||
return dbpool, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters