pq

command
v0.0.0-...-9366683 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 4 Imported by: 0

README

Go PostgreSQL Connection Example using pq client

This example shows you how to connect to PostgreSQL using lib/pq client in Go programming language. Two scripts are provided, one with sslmode=verify-full and one without.

Prerequisites

Ensure you have the following installed on your machine:

  • Go (You can install Go from here)

Usage

  1. Clone this repository:
git clone https://github.com/danieltprice/postgresql-connection-examples.git
  1. Navigate to the directory:
cd postgresql-connection-examples/go/pq
  1. Create a mod file
go mod init example/gopostgressql
  1. Get the pq package:
go get github.com/lib/pq
  1. Run the program:
go run main.go

or

go run main-ssl.go

This will print the PostgreSQL version and the current timestamp.

Always remember to handle database credentials securely in your applications. In a real-world scenario, you should not hardcode your credentials in the code. Instead, consider using environment variables or secure configuration files to handle such sensitive data.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL