Senior
Which databases have you worked with the most?
sobes.tech AI
Answer from AI
In working with Golang, I most often used the following databases:
- PostgreSQL — due to its reliability and support for complex queries, often used with libraries
database/sqlandpgx. - MySQL — for projects with a simpler data structure and high load.
- Redis — for caching and session storage, used the
go-redisclient.
Example of connecting to PostgreSQL using pgx:
import (
"context"
"github.com/jackc/pgx/v4"
"log"
)
func main() {
conn, err := pgx.Connect(context.Background(), "postgres://user:password@localhost:5432/dbname")
if err != nil {
log.Fatal(err)
}
defer conn.Close(context.Background())
var greeting string
err = conn.QueryRow(context.Background(), "SELECT 'Hello, world!' ").Scan(&greeting)
if err != nil {
log.Fatal(err)
}
log.Println(greeting)
}
This stack allows for efficient work with different data types and scenarios.