title: Referring to an open database connection inside a function - Golang
body: <p>My main function opens a database connection:</p>
  
  <pre><code>func main() {
      db, err := sql.Open("sqlite3", "./house.db")
      checkErr(err)
  
      ...
  }
  </code></pre>
  
  <p>Then, I want to create a function that allows me to add a row to the database based on a passed struct:</p>
  
  <pre><code>func addRow(row Room) error {
      stmt, err := db.Prepare("INSERT INTO Rooms (Name, Size, WindowCount, WallDecorationType, Floor) VALUES(?, ?, ?, ?, ?)")
      _, err = stmt.Exec(row.Name , row.Size , row.WindowCount , row.WallDecorationType , row.Floor)
      return err
  }
  </code></pre>
  
  <p>But obviously I can't do that because the <code>addRow()</code> function has no idea what <code>db</code> is.</p>
  
  <p>How would I make this function work? Should I perhaps, open the database outside of the main function?</p>