     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.

        }
    }
    
    private func installTransactionObserverHooks() {
        let dbPointer = unsafeBitCast(self, UnsafeMutablePointer<Void>.self)
        
        sqlite3_update_hook(sqliteConnection, { (dbPointer, updateKind, databaseName, tableName, rowID) in
            print("sqlite3_update_hook")
            let db = unsafeBitCast(dbPointer, Database.self)
            db.didChangeWithEvent(DatabaseEvent(
                kind: DatabaseEvent.Kind(rawValue: updateKind)!,
                databaseName: String.fromCString(databaseName)!,
                tableName: String.fromCString(tableName)!,
                rowID: rowID))
            }, dbPointer)
        
        
        sqlite3_commit_hook(sqliteConnection, { dbPointer in
            let db = unsafeBitCast(dbPointer, Database.self)
            do {
                try db.willCommit()
                db.statementCompletion = .TransactionCommit
