Inherits from NSObject
Conforms to AGStore
Declared in AGSQLiteStorage.h
AGSQLiteStorage.m

Overview

An AGStore implementation that uses a SQLite for storage. The storage is a key value store. The content is serialized in JSON output.

NOTE: You must adhere to the rules governing the serialization of data types for each respective field type.

IMPORTANT: Users are not required to instantiate this class directly, instead an instance of this class is returned automatically when an DataStore with the type config option is set to “SQLITE”. See AGDataManager and AGStore class documentation for more information.

Create a DataManager with a SQLite store backend

Below is a small example on how to use SQLite:

// initialize SQLite store (if the file does not exist it will be created)
AGDataManager* manager = [AGDataManager manager];
id<AGStore> store = [manager store:^(id<AGStoreConfig> config) {
  [config setName:@"secrets"]; // will be used as the filename for the sqlite database.
  [config setType:@"SQLITE"];  // specify you want to use SQLite store.
}];

// the object to save (e.g. a dictionary)
NSDictionary *otp = [NSDictionary dictionaryWithObjectsAndKeys:@"19a01df0281afcdbe", @"otp", @"1", @"id", nil];

// save it
NSError *error;

if (![store save:otp error:&error])
NSLog(@"Save: An error occurred during save! \n%@", error);

The read, reset or remove methods found in AGStore behave the same, as on the default (“in memory”) store.

Instance Methods

filter:

Reads all, based on a filter, from the underlying storage system.

- (NSArray *)filter:(NSPredicate *)predicate

Parameters

predicate

The NSPredicate to apply to the data from the underlying storage system.

Return Value

A collection (NSArray), containing all stored objects, matching the given predicate. This method only returns a copy of the data and leaves the underlying storage system intact.

Discussion

Reads all, based on a filter, from the underlying storage system.

Declared In

AGStore.h

isEmpty

Checks if the storage system contains no stored elements.

- (BOOL)isEmpty

Return Value

YES if the storage is empty, otherwise NO.

Discussion

Checks if the storage system contains no stored elements.

Declared In

AGStore.h

read:

Reads a specific object/record from the underlying storage system.

- (id)read:(id)recordId

Parameters

recordId

id from the desired object.

Return Value

The object (or nil) read from the underlying storage.

Discussion

Reads a specific object/record from the underlying storage system.

Declared In

AGStore.h

readAll

Reads all the data from the underlying storage system.

- (NSArray *)readAll

Return Value

A collection (NSArray), containing all stored objects.

Discussion

Reads all the data from the underlying storage system.

Declared In

AGStore.h

remove:error:

Removes a specific object/record from the underlying storage system.

- (BOOL)remove:(id)record error:(NSError **)error

Parameters

record

the desired object

error

An error object containing details of why the remove failed.

Return Value

YES if the operation succeeds, otherwise NO.

Discussion

Removes a specific object/record from the underlying storage system.

Declared In

AGStore.h

reset:

Resets the entire storage system.

- (BOOL)reset:(NSError **)error

Parameters

error

An error object containing details of why the reset failed.

Return Value

YES if the operation succeeds, otherwise NO.

Discussion

Resets the entire storage system.

Declared In

AGStore.h

save:error:

Saves the given object in the underlying storage system.

- (BOOL)save:(id)data error:(NSError **)error

Parameters

data

A mutable dictionary representing key/value, dictionary must be mutable as id is optional and can be added after being saved. Data can also be a collection (e.g. NSArray) of mutable dictionary. This parameter is the object being persisted.

error

An error object containing details of why the save failed.

Return Value

YES if the operation succeeds, otherwise NO.

Discussion

Saves the given object in the underlying storage system.

Declared In

AGStore.h