title: Is it a good practice to use database connection as static?
body: <p>I am using <strong>SQLite.swift</strong> framework for my iOS application. I have <code>DatabaseService</code> class where I create a database connection and perform all <code>CURD</code> operations. I was instantiating this class and creating a connection on each controller but recently I changed the database variable to <code>static</code> and create connection once for all controllers. I am not sure if it's a good practice. Here is how I perform this:</p>
  
  <pre><code>static var db: Connection?
  
  init() {
      if DatabaseService.db != nil {
          return
      }
      let path = NSSearchPathForDirectoriesInDomains(
          .documentDirectory, .userDomainMask, true
          ).first!
      do {
          let fileManager = FileManager()
          try fileManager.copyfileToUserDocumentDirectory(forResource: "db", ofType: "sqlite3")
  
          // Empty database will be created if file does not exist
          DatabaseService.db = try? Connection("\(path)/db.sqlite3")
  
          print("Connection successful")
      } catch let error {
          print("Unable to connect with the database. \(error)")
      }
  }
  </code></pre>