     public func addTransactionObserver(transactionObserver: TransactionObserverType) {
         preconditionValidQueue()
         transactionObservers.append(transactionObserver)
+        if transactionObservers.count == 1 {
+            installTransactionObserverHooks()
+        }
     }
     
     public func removeTransactionObserver(transactionObserver: TransactionObserverType) {
         preconditionValidQueue()
         if let index = transactionObservers.indexOf({ observer in observer === transactionObserver}) {
             transactionObservers.removeAtIndex(index)
+        }
+        if transactionObservers.isEmpty {
+            uninstallTransactionObserverHooks()
         }
     }
     

        
        sqlite3_rollback_hook(sqliteConnection, { dbPointer in
            let db = unsafeBitCast(dbPointer, Database.self)
            
            switch db.statementCompletion {
            case .TransactionErrorRollback:
                // A transactionObserver has rollbacked the transaction.

        
        try setupForeignKeys()
        setupBusyMode()
    }
    
    // Initializes an in-memory database
