basic

package
v0.0.0-...-0f3a50a Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package basic The sql.DB database handle is safe for concurrent use by multiple goroutines (meaning the handle is what other languages might call "thread-safe"). Some other database access libraries are based on connections that can only be used for one operation at a time. To bridge that gap, each sql.DB manages a pool of active connections to the underlying database, creating new ones as needed for parallelism.

The connection pool is suitable for most data access needs. When you call an sql.DB Query or Exec method, the sql.DB implementation retrieves an available connection from the pool or, if needed, creates one. The package returns the connection to the pool when it's no longer needed. This supports a high level of parallelism for database access.

Package basic This tutorial introduce the basics of accessing a relational database with Go and its database/sql package in the standard library. The database/sql package includes types and functions for connecting to databases, execution transactions, canceling an operation in progress, and more. For more details on using the database/sql package, see https://go.dev/doc/database. Sections:

	1.Set up a database.
	2.Import the database driver.
	3.Get a database handle and connect.
	4.Query for multiple rows.
	5.Query for a single row.
 6.Add data.

With database/sql package, your code opens a database handle that represents a connection pool, then executes data access operations with the handle, calling a Close method only when needed to free resources, such as those held by retrieved rows or a prepared statement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAlbum

func AddAlbum(alb Album) (int64, error)

AddAlbum adds the specific album to the database, returning the album ID of the new entry

func CloseDB

func CloseDB()

func CreateOrder

func CreateOrder(ctx context.Context, albumId, quantity, customerID int) (orderID int64, err error)

CreateOrder creates an order for an album and returns the new order ID.

func OpenDB

func OpenDB()

func PingDB

func PingDB()

func QueryWithTimeout

func QueryWithTimeout(ctx context.Context)

QueryWithTimeout cancelling database operations after a timeout

func ShowConnectionPoolProperties

func ShowConnectionPoolProperties()

func ShowOpenDBHanlde

func ShowOpenDBHanlde()

func UpdateAlbum

func UpdateAlbum(alb Album) (int64, error)

UpdateAlbum updates the specific album to the database, returning the affected rows of the update entry

Types

type Album

type Album struct {
	ID     int64
	Title  string
	Artist string
	Price  float32
}

func AlbumById

func AlbumById(id int64) (Album, error)

AlbumById queries for the album with the specific ID.

func AlbumsByArtist

func AlbumsByArtist(name string) ([]Album, error)

AlbumsByArtist queries for albums that have the specific artist name

Jump to

Keyboard shortcuts

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