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 ¶
- func AddAlbum(alb Album) (int64, error)
- func CloseDB()
- func CreateOrder(ctx context.Context, albumId, quantity, customerID int) (orderID int64, err error)
- func OpenDB()
- func PingDB()
- func QueryWithTimeout(ctx context.Context)
- func ShowConnectionPoolProperties()
- func ShowOpenDBHanlde()
- func UpdateAlbum(alb Album) (int64, error)
- type Album
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddAlbum ¶
AddAlbum adds the specific album to the database, returning the album ID of the new entry
func CreateOrder ¶
CreateOrder creates an order for an album and returns the new order ID.
func QueryWithTimeout ¶
QueryWithTimeout cancelling database operations after a timeout
func ShowConnectionPoolProperties ¶
func ShowConnectionPoolProperties()
func ShowOpenDBHanlde ¶
func ShowOpenDBHanlde()
func UpdateAlbum ¶
UpdateAlbum updates the specific album to the database, returning the affected rows of the update entry