| 
														
															@@ -2,6 +2,7 @@ package main 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 import ( 
														 | 
														
														 | 
														
															 import ( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"context" 
														 | 
														
														 | 
														
															 	"context" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	"database/sql" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"fmt" 
														 | 
														
														 | 
														
															 	"fmt" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"io/ioutil" 
														 | 
														
														 | 
														
															 	"io/ioutil" 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	"path/filepath" 
														 | 
														
														 | 
														
															 	"path/filepath" 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -36,7 +37,7 @@ func main() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	db.SetMaxOpenConns(8) 
														 | 
														
														 | 
														
															 	db.SetMaxOpenConns(8) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	// DB struct here ./db/migrations/20220527233113_test_migration.sql 
														 | 
														
														 | 
														
															 	// DB struct here ./db/migrations/20220527233113_test_migration.sql 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	fmt.Println("Insert some data to users table") 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	fmt.Println("Inserting some data to users table") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	if _, err := db.Exec( 
														 | 
														
														 | 
														
															 	if _, err := db.Exec( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		context.Background(), 
														 | 
														
														 | 
														
															 		context.Background(), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		"INSERT INTO users (id, name) VALUES ($1, $2)", 
														 | 
														
														 | 
														
															 		"INSERT INTO users (id, name) VALUES ($1, $2)", 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -45,7 +46,7 @@ func main() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
														
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	} 
														 | 
														
														 | 
														
															 	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	fmt.Println("Select all rows from users table") 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	fmt.Println("Selecting all rows from users table") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	if rows, err := db.Query( 
														 | 
														
														 | 
														
															 	if rows, err := db.Query( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		context.Background(), 
														 | 
														
														 | 
														
															 		context.Background(), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		"SELECT id, name FROM users ORDER BY id ASC", 
														 | 
														
														 | 
														
															 		"SELECT id, name FROM users ORDER BY id ASC", 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -69,7 +70,7 @@ func main() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
														
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	} 
														 | 
														
														 | 
														
															 	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	fmt.Println("Update inside transaction") 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	fmt.Println("Updating inside transaction") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	if err := db.Transaction(context.Background(), func(ctx context.Context, tx *gosql.Tx) error { 
														 | 
														
														 | 
														
															 	if err := db.Transaction(context.Background(), func(ctx context.Context, tx *gosql.Tx) error { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		if _, err := tx.Exec(ctx, "UPDATE users SET name=$1 WHERE id=$2", "John", 1); err != nil { 
														 | 
														
														 | 
														
															 		if _, err := tx.Exec(ctx, "UPDATE users SET name=$1 WHERE id=$2", "John", 1); err != nil { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			return err 
														 | 
														
														 | 
														
															 			return err 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -82,7 +83,7 @@ func main() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
														
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	} 
														 | 
														
														 | 
														
															 	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	fmt.Println("Select all rows from users again") 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	fmt.Println("Selecting all rows from users again") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	if err := db.Each( 
														 | 
														
														 | 
														
															 	if err := db.Each( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		context.Background(), 
														 | 
														
														 | 
														
															 		context.Background(), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		"SELECT id, name FROM users ORDER BY id ASC", 
														 | 
														
														 | 
														
															 		"SELECT id, name FROM users ORDER BY id ASC", 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -101,6 +102,21 @@ func main() { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
														
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	} 
														 | 
														
														 | 
														
															 	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	fmt.Println("Selecting specific user with ID: 5") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	var row struct { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		ID   int64 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		Name string 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	err = db.QueryRow(context.Background(), "SELECT id, name FROM users WHERE id=$1", 5).Scans(&row) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	if err != nil && err != sql.ErrNoRows { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		panic(fmt.Sprintf("%s", err)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	if err != sql.ErrNoRows { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		fmt.Printf("ID: %d, Name: %s\n", row.ID, row.Name) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	} else { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		fmt.Printf("Record not found\n") 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	// Close DB connection 
														 | 
														
														 | 
														
															 	// Close DB connection 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	if err := db.Close(); err != nil { 
														 | 
														
														 | 
														
															 	if err := db.Close(); err != nil { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 | 
														
														 | 
														
															 		panic(fmt.Sprintf("%s", err)) 
														 |