trunkless/db/db.go
2024-08-18 15:45:40 -05:00

33 lines
601 B
Go

package db
import (
"context"
"crypto/sha1"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)
func StrToID(s string) string {
return fmt.Sprintf("%x", sha1.Sum([]byte(s)))[0:6]
}
func Connect() (*pgx.Conn, error) {
conn, err := pgx.Connect(context.Background(), "")
if err != nil {
return nil, fmt.Errorf("Unable to connect to database: %w", err)
}
return conn, nil
}
func Pool() (*pgxpool.Pool, error) {
pool, err := pgxpool.New(context.Background(), "")
if err != nil {
return nil, fmt.Errorf("Unable to connect to database: %w", err)
}
return pool, nil
}