title: In the sqlite.swift framework is there a way to prepare the statement once ahead of time and then bind the variable just before execution?
body: <p>I use SQLite for my persistent store.
  I use a dictionary based off the primary key for an in-memory store: <code>var localContext = [String: GrandLite]()</code>.</p>
  
  <p>I use the function below to retrieve an object from the dictionary, or from  the database and then store in the dictionary. This function is called frequently, and I'm trying to optimize it.</p>
  
  <pre><code>class func retrieveByKey&lt;T: GrandLite&gt;(aType: [T], thisKey: String) -&gt; T? {
      let thisStack = FoodysLiteStack.thisDataStack
      if let thisObject = thisStack.localContext[thisKey] as? T {
          return thisObject
      } else {
          do {
              let db = thisStack.localDatabase
              let thisTable = T.getTable()
              if let thisRow = try db.pluck(thisTable.filter(uuidKeyLite == thisKey)) {
                  let thisObject = T(withRow: thisRow)
                  thisStack.localContext[thisKey] = thisObject
                  return thisObject
              } else {
                  return nil
              }
          } catch {
              NSLog("WARNING: Unhandled error for T retrieveByKey")
              return nil
          }
      }
  }
  </code></pre>
  
  <p>As I understand sqlite.swift pluck is basically a prepare with limit 1. Also, prepare compiles the SQL statement, binds the variable, and executes it. I'm trying to avoid the SQLite compile time every time this function is called.</p>
  
  <p>In the sqlite.swift framework is there a way to prepare the statement once ahead of time and then bind the variable just before execution? You can do this for inserts and updates with db.prepare and db.run, but I don't see a way to bind a variable for an already prepared select statement. I may be overthinking this, the SQLite compile time on <code>thisTable.filter(uuidKeyLite == thisKey)</code> is probably quite small.</p>