     }
 
     func dataForKey(key: String) -> NSData? {
-        
+
         let result = dataAndLastUpdateDateForKey(key)
         return result?.0
     }
-    
+
     func dataAndLastUpdateDateForKey(recordId: String) -> (NSData, NSDate)? {
-        
+
         let linkIndex: Int32 = 0
         let dateIndex: Int32 = 1
-        
+
         let query = "SELECT file_link, update_time FROM records WHERE record_id='\(recordId)';";
-        
+
         var result: (NSData, NSDate)?
-        
+
         dispatch_sync(db.dispatchQueue, {
-            
+
             //var statement: UnsafeMutablePointer<Void> = nil
             var statement: COpaquePointer = nil
-            
+
             if self.db.prepareQuery(query, statement:&statement) {
                 if bridging_sqlite3_step(statement) == BRIDGING_SQLITE_ROW {
-                    
+
                     let str = bridging_sqlite3_column_text(statement, linkIndex)
                     let fileLink = String.fromCString(UnsafePointer<CChar>(str))!
                     let data = fileLink.cacheDBFileLinkDataWithFolder(self.db.folder)
-                    
+
                     if let data = data {
                         let dateInetrval = bridging_sqlite3_column_double(statement, dateIndex)
                         let updateDate = NSDate(timeIntervalSince1970:dateInetrval)

                }
            }
        }
        
        return fileSize
    }
}

private func getOrCreateDispatchQueueForFile(file: String) -> dispatch_queue_t {
    
    let queueName = "com.jff.embedded_sources.dynamic.\(file)"
    let result = dispatch_queue_get_or_create(label: queueName, attr: DISPATCH_QUEUE_CONCURRENT)
    return result
}

final private class JSQLiteDB {
    
    private var db: COpaquePointer = nil
    let dispatchQueue: dispatch_queue_t
    
    private let folder: String
    
    deinit {
        bridging_sqlite3_close(db)
    }
    
    init(dbName: String) {
        
        dispatchQueue = getOrCreateDispatchQueueForFile(dbName)
        
        let dbPath = String.documentsPathByAppendingPathComponent(dbName)
        
        folder = (dbPath as NSString).stringByDeletingLastPathComponent
        
        dispatch_barrier_sync(dispatchQueue, {
            
            let manager = NSFileManager.defaultManager()
            
            if !manager.fileExistsAtPath(self.folder) {
                
                do {
                    try manager.createDirectoryAtPath(
                        self.folder,

                bridging_sqlite3_finalize(statement)
            }
        })

        return result
    }

    private func removeRecordsForRecordId(recordId: AnyObject, fileLink: String) {

        fileLink.cacheDBFileLinkRemoveFileWithFolder(self.db.folder)

        let removeQuery = "DELETE FROM records WHERE record_id='\(recordId)';"

        dispatch_barrier_async(db.dispatchQueue, {

            var statement: COpaquePointer = nil
            if self.prepareQuery(removeQuery, statement:&statement) {
                if bridging_sqlite3_step(statement) != BRIDGING_SQLITE_DONE {
                    NSLog("\(removeQuery) - \(self.errorMessage)")
                }

                bridging_sqlite3_finalize(statement)
            }
        })
    }

    private func addData(data: NSData, forRecord recordId: String) {

        let fileLink = NSUUID().UUIDString

        let addQuery = "INSERT INTO records (record_id, file_link, update_time, access_time) VALUES ('\(recordId)', '\(fileLink)', '\(currentTime)', '\(currentTime)');"

        dispatch_barrier_async(db.dispatchQueue, {

            var statement: COpaquePointer = nil
            if self.prepareQuery(addQuery, statement:&statement) {
                if bridging_sqlite3_step(statement) == BRIDGING_SQLITE_DONE {
