18 lines
382 B
Go
18 lines
382 B
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v4"
|
|
)
|
|
|
|
// Connect to a database
|
|
func Connect(server string, user string, password string, database string) (*Queries, error) {
|
|
conn, err := pgx.Connect(context.Background(), fmt.Sprintf("postgresql://%s:%s@%s/%s", user, password, server, database))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return New(conn), nil
|
|
}
|