Senior
Milliste andmebaasidega olete kõige tihedamalt töötanud?
sobes.tech AI
Vastus AI-lt
While working with Golang, I most frequently used the following databases:
- PostgreSQL — due to its reliability and support for complex queries, I often used it with the
database/sqlandpgxlibraries. - MySQL — for projects with simpler data structures and high load.
- Redis — for caching and session storage, using 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.