From df33a221302b5b021d2cfb6292683e8c08477511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 28 Feb 2020 11:21:18 +0100 Subject: [PATCH] Improve formatting of "Connecting to a database" section --- SQLInterface.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/SQLInterface.md b/SQLInterface.md index 4ac73495..ba9d389e 100644 --- a/SQLInterface.md +++ b/SQLInterface.md @@ -1,19 +1,20 @@ # Introduction -The database/sql package provides a generic interface around SQL (or SQL-like) databases. See the [official documentation](http://golang.org/pkg/database/sql/) for details. +The `database/sql` package provides a generic interface around SQL (or SQL-like) databases. See the [official documentation](https://golang.org/pkg/database/sql/) for details. This page provides example usage patterns. # Database driver -The database/sql package must be used in conjunction with a database driver. +The `database/sql` package must be used in conjunction with a database driver. See http://golang.org/s/sqldrivers for a list of drivers. The documentation below assumes a driver has been imported. # Connecting to a database -Open is used to create a database handle: +[`Open`](https://golang.org/pkg/database/sql/#Open) + is used to create a database handle: ```go db, err := sql.Open(driver, dataSourceName) @@ -23,7 +24,11 @@ Where driver specifies a database driver and dataSourceName specifies database-specific connection information such as database name and authentication credentials. -Note that Open does not directly open a database connection: this is deferred until a query is made. To verify that a connection can be made before making a query, use the PingContext function: +Note that `Open` does not directly open a database connection: this is deferred +until a query is made. To verify that a connection can be made +before making a query, use the +[`PingContext`](https://golang.org/pkg/database/sql/#DB.PingContext) +method: ```go if err := db.PingContext(ctx); err != nil { @@ -31,7 +36,7 @@ if err := db.PingContext(ctx); err != nil { } ``` -After use, the database is closed using Close. +After use, the database is closed using `Close`. # Executing queries