Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created May 22, 2013 17:35
Show Gist options
  • Save odrobnik/5629373 to your computer and use it in GitHub Desktop.
Save odrobnik/5629373 to your computer and use it in GitHub Desktop.
DTSQLiteDatabase.h
//
// DTSQLiteDatabase.h
// DTFoundation
//
// Created by Oliver Drobnik on 5/22/13.
// Copyright (c) 2013 Drobnik.com. All rights reserved.
//
/**
A wrapper for SQLite databases which offers threadsafe concurrency and support for cancelling long-running operations.
*/
@interface DTSQLiteDatabase : NSObject
/**
@name Creating a Database
*/
/**
Opens the sqlite3 database file at the given path
@param path The file path to the database file
*/
- (id)initWithFileAtPath:(NSString *)path;
/**
Queries
*/
/**
Fetches the result rows for a query.
You can call this from any queue/thread as long as it is the only one. For background operations you should call it exclusively via performBlock: or performBlockAndWait: for synchronization.
@param query The SQL query to execute
@param error If an error occurs this output parameter will contain it
@returns An array of `NSDictionary` instances
*/
- (NSArray *)fetchRowsForQuery:(NSString *)query error:(NSError **)error;
/**
Cancels all currently queued queries
*/
- (void)cancelAllQueries;
/**
@name Block Operations
*/
/**
@param block The block to perform
*/
- (void)performBlock:(void (^)())block;
/**
@param block The block to perform
*/
- (void)performBlockAndWait:(void (^)())block;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment