| 
					
				 | 
			
			
				@@ -2,6 +2,7 @@ package main 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"context" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"database/sql" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"fmt" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"io/ioutil" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"path/filepath" 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -36,7 +37,7 @@ func main() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	db.SetMaxOpenConns(8) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	// 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( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		context.Background(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		"INSERT INTO users (id, name) VALUES ($1, $2)", 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -45,7 +46,7 @@ func main() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		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( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		context.Background(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		"SELECT id, name FROM users ORDER BY id ASC", 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -69,7 +70,7 @@ func main() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		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 := tx.Exec(ctx, "UPDATE users SET name=$1 WHERE id=$2", "John", 1); err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			return err 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -82,7 +83,7 @@ func main() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		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( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		context.Background(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		"SELECT id, name FROM users ORDER BY id ASC", 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -101,6 +102,21 @@ func main() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		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 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if err := db.Close(); err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		panic(fmt.Sprintf("%s", err)) 
			 |