Connecting & querying
Where the walkers actually live
So far your handlers have returned data you hard-coded in Go. A real PawWalk backend keeps walkers, bookings, and GPS fixes in a database β usually PostgreSQL β that survives restarts and serves many requests at once.
Go talks to SQL databases through one standard-library package: database/sql. It gives you a common API (Query, Exec, Scan) and you plug in a driver for your specific database. Import the package the usual way, and pull in the driver for its side effect of registering itself:
import (
"database/sql"
_ "github.com/lib/pq" // registers the postgres driver
)
The underscore _ means import this only for its side effects β the driver registers the name "postgres" in its init(), and you never call it directly.
lib/pqis perfectly fine for learningdatabase/sqlhere, but it's now in maintenance mode. For new projects the actively-developedjackc/pgxis the modern Postgres driver of choice β use it directly, or throughpgx/stdlibto keep this samedatabase/sqlAPI.