NewPostgresStore opens a Postgres-backed ledger using lib/pq (connection string / DSN).
(dsn string)
| 55 | |
| 56 | // NewPostgresStore opens a Postgres-backed ledger using lib/pq (connection string / DSN). |
| 57 | func NewPostgresStore(dsn string) (Store, error) { |
| 58 | db, err := sql.Open("postgres", dsn) |
| 59 | if err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | db.SetMaxOpenConns(8) |
| 63 | if _, err := db.Exec(postgresSchema); err != nil { |
| 64 | _ = db.Close() |
| 65 | return nil, fmt.Errorf("postgres migrate: %w", err) |
| 66 | } |
| 67 | return &postgresStore{db: db}, nil |
| 68 | } |
| 69 | |
| 70 | func (s *postgresStore) CreateRequest(ctx context.Context, row RequestRow) error { |
| 71 | _, err := s.db.ExecContext(ctx, ` |