aboutsummaryrefslogtreecommitdiff
path: root/_content/doc/tutorial/database-access.md
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-11-18 10:51:11 -0500
committerRuss Cox <rsc@golang.org>2021-11-22 16:43:17 +0000
commit61fc64f2024b3366363d7c623862d0ab6542a1ff (patch)
treeb8a1ed915d58d6cc6420d9e8c3a0a23051ebe76d /_content/doc/tutorial/database-access.md
parent9d77df7a831fbde9ba62c77c9cd5dc3dd6f6a1c7 (diff)
downloadgo-x-website-61fc64f2024b3366363d7c623862d0ab6542a1ff.tar.xz
_content: update links to tour
Now the tour is just /tour, not https://tour.golang.org. Change-Id: Iebb2f7a5218b747896250815f4f46f62755e6a88 Reviewed-on: https://go-review.googlesource.com/c/website/+/365101 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Jamal Carvalho <jamal@golang.org>
Diffstat (limited to '_content/doc/tutorial/database-access.md')
-rw-r--r--_content/doc/tutorial/database-access.md24
1 files changed, 12 insertions, 12 deletions
diff --git a/_content/doc/tutorial/database-access.md b/_content/doc/tutorial/database-access.md
index cdb62127..cd0cfb8f 100644
--- a/_content/doc/tutorial/database-access.md
+++ b/_content/doc/tutorial/database-access.md
@@ -111,7 +111,7 @@ but most DBMSes have their own CLI with similar features.
$ mysql -u root -p
Enter password:
- mysql>
+ mysql>
```
3. At the `mysql` command prompt, create a database.
@@ -141,9 +141,9 @@ but most DBMSes have their own CLI with similar features.
PRIMARY KEY (`id`)
);
- INSERT INTO album
- (title, artist, price)
- VALUES
+ INSERT INTO album
+ (title, artist, price)
+ VALUES
('Blue Train', 'John Coltrane', 56.99),
('Giant Steps', 'John Coltrane', 63.99),
('Jeru', 'Gerry Mulligan', 17.99),
@@ -155,10 +155,10 @@ but most DBMSes have their own CLI with similar features.
* Delete (drop) a table called `album`. Executing this command first makes
it easier for you to re-run the script later if you want to start over
with the table.
-
+
* Create an `album` table with four columns: `title`, `artist`, and `price`.
Each row's `id` value is created automatically by the DBMS.
-
+
* Add three rows with values.
7. From the `mysql` command prompt, run the script you just created.
@@ -228,7 +228,7 @@ With the driver imported, you'll start writing code to access the database.
Now write some Go code that gives you database access with a database handle.
You'll use a pointer to an `sql.DB` struct, which represents access to a
-specific database.
+specific database.
#### Write the code
@@ -271,7 +271,7 @@ specific database.
production, you'd avoid the global variable, such as by passing the
variable to functions that need it or by wrapping it in a struct.
- * Use the MySQL driver's [`Config`](https://pkg.go.dev/github.com/go-sql-driver/mysql#Config)
+ * Use the MySQL driver's [`Config`](https://pkg.go.dev/github.com/go-sql-driver/mysql#Config)
-- and the type's [`FormatDSN`](https://pkg.go.dev/github.com/go-sql-driver/mysql#Config.FormatDSN)
-– to collect connection properties and format them into a DSN for a connection string.
@@ -294,7 +294,7 @@ specific database.
`sql.Open` might not immediately connect, depending on the
driver. You're using `Ping` here to confirm that the
`database/sql` package can connect when it needs to.
-
+
* Check for an error from `Ping`, in case the connection failed.
* Print a message if `Ping` connects successfully.
@@ -473,7 +473,7 @@ learn how to query for a single row later, in the section
* Call the `albumsByArtist` function you added, assigning its return value to
a new `albums` variable.
-
+
* Print the result.
#### Run the code
@@ -520,7 +520,7 @@ For SQL statements you know will return at most a single row, you can use
* Use [`DB.QueryRow`](https://pkg.go.dev/database/sql#DB.QueryRow)
to execute a `SELECT` statement to query for an album with the
- specified ID.
+ specified ID.
It returns an `sql.Row`. To simplify the calling code
(your code!), `QueryRow` doesn't return an error. Instead,
@@ -659,7 +659,7 @@ Suggested next topics:
* If you're new to Go, you'll find useful best practices described in
[Effective Go](/doc/effective_go) and [How to write Go code](/doc/code).
-* The [Go Tour](https://tour.golang.org/welcome/1) is a great step-by-step
+* The [Go Tour](/tour/) is a great step-by-step
introduction to Go fundamentals.
## Completed code {#completed_code}