Sobes.tech
Intern — Junior

What actions have you performed in the database as part of your tasks?

sobes.tech AI

Answer from AI

In working with databases in Go, I usually perform the following actions:

  • Connecting to the database using standard libraries (e.g., database/sql) and drivers (e.g., pq for PostgreSQL).
  • Executing SQL queries for data retrieval (SELECT), insertion (INSERT), updating (UPDATE), and deletion (DELETE).
  • Processing query results, mapping rows from the database into Go structures.
  • Using transactions to ensure data integrity.
  • Optimizing queries and indexes to improve performance.

Example of a simple query in Go:

import (
    "database/sql"
    _ "github.com/lib/pq"
)

func getUserByID(db *sql.DB, id int) (string, error) {
    var name string
    err := db.QueryRow("SELECT name FROM users WHERE id = $1", id).Scan(&name)
    if err != nil {
        return "", err
    }
    return name, nil
}