RBORMObject Class Reference

Inherits from RBIntrospectiveObject : NSObject
Declared in RBORMObject.h

Overview

Provides a managed ORM (Object relationship management) object for use with SQLite.

  • Note: NSDates are automatically serialized and deserialized. Dates are stored on disk in the ISO 8601 format.

+ tableName

Returns the table name to be used. The default implementation returns the name of the class stripping any non alphanumeric characters.

+ (nonnull NSString *)tableName

Return Value

The name of the table.

Declared In

RBORMObject.h

+ nullableProperties

A list of the nullable properties for this object.

+ (nonnull NSArray<NSString*> *)nullableProperties

Return Value

A list of the properites that are permitted to be null or nil.

Declared In

RBORMObject.h

+ propertiesToColumnNames

A mapping of property names to database column names when the names differ.

+ (nonnull NSDictionary<NSString*,NSString*> *)propertiesToColumnNames

Return Value

A mapping of the property names and their corresponding database column names.

Declared In

RBORMObject.h

  pk

The primary key assigned to this object by SQLite. Will be set to a value < 1 if the object has not yet been saved.

@property (readonly) NSInteger pk

Declared In

RBORMObject.h

  hasPrimaryKey

Indiciates that a valid primary key value has been set and assigned by SQLite.

@property (nonatomic, readonly) BOOL hasPrimaryKey

Declared In

RBORMObject.h

  databaseIdentifier

The database identifier this object is associated it. This allows multiple databases to be used at once.

@property (readonly, nonnull) NSString *databaseIdentifier

Declared In

RBORMObject.h

– init

Initializes a new RBORMObject object with the default database identifier (DEFAULT_DATABASE_IDENTIFIER).

- (nonnull instancetype)init

Return Value

A newly initialized RBORMObject object.

Declared In

RBORMObject.h

– initWithDatabaseIdentifier:

Initializes a new RBORMObject object with a specific database identifier.

- (nonnull instancetype)initWithDatabaseIdentifier:(nonnull NSString *)identifier

Parameters

identifier

The database identifier.

Return Value

A newly initialized RBORMObject object.

Declared In

RBORMObject.h

– deleteFromDatabase

Deletes this object from the database. Do not override this method.

- (BOOL)deleteFromDatabase

Return Value

Returns YES if successful.

Declared In

RBORMObject.h

– save

Saves this object. An insert or update occurs as needed.

- (BOOL)save

Return Value

Returns YES if successful.

Declared In

RBORMObject.h

– willInsert

This method is called before inserting.

- (void)willInsert

Declared In

RBORMObject.h

– willUpdate

This method is called before updating.

- (void)willUpdate

Declared In

RBORMObject.h

– didInsert:

Called after inserting.

- (void)didInsert:(BOOL)success

Parameters

success

If YES then the object has been saved successfully.

Declared In

RBORMObject.h

– didUpdate:

Called after updating.

- (void)didUpdate:(BOOL)success

Parameters

success

If YES then the object has been saved successfully.

Declared In

RBORMObject.h

– willDeleteFromDatabase

This method is called before deletion.

- (void)willDeleteFromDatabase

Declared In

RBORMObject.h

– didDeleteFromDatabase:

Called after deletion.

- (void)didDeleteFromDatabase:(BOOL)success

Parameters

success

If YES then the object has been saved deleted.

Declared In

RBORMObject.h

– willPopulate

This method is called before populating the data in the object instance.

- (void)willPopulate

Declared In

RBORMObject.h

– didPopulate:

Called after population.

- (void)didPopulate:(BOOL)success

Parameters

success

If YES then the object has been saved populated.

Declared In

RBORMObject.h

+ objectWithDefaultDatabaseIdentifier

Initializes a new RBORMObject object with the default database identifier (DEFAULT_DATABASE_IDENTIFIER).

+ (nonnull instancetype)objectWithDefaultDatabaseIdentifier

Return Value

A newly initialized RBORMObject object.

Declared In

RBORMObject.h

+ objectWithDatabaseIdentifier:

Initializes a new RBORMObject object with a specific database identifier.

+ (nonnull instancetype)objectWithDatabaseIdentifier:(nonnull NSString *)identifier

Parameters

identifier

The database identifier.

Return Value

A newly initialized RBORMObject object.

Declared In

RBORMObject.h

+ populateWithDictionary:databaseIdentifier:

Initializes a new RBORMObject object using the specified NSDictionary to populate it with and a database identifier.

+ (nonnull instancetype)populateWithDictionary:(nonnull NSDictionary<NSString*,id> *)record databaseIdentifier:(nonnull NSString *)identifier

Parameters

record

The data to used for populating.

identifier

The database identifier.

Return Value

A newly initialized and populated RBORMObject object.

Declared In

RBORMObject.h

+ populateWithResultSet:atRow:databaseIdentifier:

Initializes a new RBORMObject object from a RBSQLiteResultSet given the row index and a database identifier.

+ (nonnull instancetype)populateWithResultSet:(nonnull RBSQLiteResultSet *)results atRow:(NSUInteger)row databaseIdentifier:(nonnull NSString *)identifier

Parameters

results

The RBSQLiteResultSet to be used for populating.

row

The row index within the RBSQLiteResultSet to use.

identifier

The database identifier.

Return Value

A newly initialized and populated RBORMObject object.

Declared In

RBORMObject.h

+ tableExistsWithDatabaseIdentifier:

Determines whether a table exists for this object type in the database who’s identifier is provided.

+ (BOOL)tableExistsWithDatabaseIdentifier:(nonnull NSString *)identifier

Parameters

identifier

The identifier of the database.

Return Value

Whether or not the table exists.

Declared In

RBORMObject.h

+ createTableIfMissingWithDatabaseIdentifier:

Creates the table for this object type in the database who’s identifier is provided, only if the table is missing.

+ (BOOL)createTableIfMissingWithDatabaseIdentifier:(nonnull NSString *)identifier

Parameters

identifier

The identifier of the database.

Return Value

Whether or not the table exists or was created.

Declared In

RBORMObject.h

+ forPk:

Returns the object for the given primary key value.

+ (nullable instancetype)forPk:(NSInteger)pk

Parameters

pk

The primary key. Must be > 0.

Return Value

The object matching the primary key or nil if not found.

Declared In

RBORMObject.h

+ executeQueryWithString:bindings:databaseIdentifier:

Executes a given SQL query string with the given bindings on the database who’s identifier is given. Expects the results to be of the receiver type, which are then deserialised and an array of objects is returned.

+ (nullable NSArray<__kindofRBORMObject*> *)executeQueryWithString:(nonnull NSString *)queryString bindings:(nullable NSArray *)bindings databaseIdentifier:(nonnull NSString *)databaseIdentifier

Parameters

queryString

The SQL query string to execute.

bindings

The corresponding bindings for the SQL query string given.

databaseIdentifier

The identifier of the database to query.

Return Value

An array of the resulting objects of the receiver’s type or nil on error.

Declared In

RBORMObject.h

+ select

Creates a new RBORMQuery as an SQL ‘SELECT * FROM [table name]’ query.

+ (nonnull RBORMQuery *)select

Return Value

A newly initialized RBORMQuery object. When executing this query an array of 0 or more typed objects will be returned.

Declared In

RBORMObject.h

+ delete

Creates a new RBORMQuery as an SQL ‘DELETE FROM [table name]’ query.

+ (nonnull RBORMQuery *)delete

Return Value

A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber containing a boolean value will be returned.

Declared In

RBORMObject.h

+ countOf:

Creates a new RBORMQuery as an SQL ‘SELECT COUNT(*)’ query.

+ (nonnull RBORMQuery *)countOf:(nonnull NSString *)propertyName

Parameters

propertyName

The property corresponding to the database column that should be counted.

Return Value

A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber will be returned.

Declared In

RBORMObject.h

+ sumOf:

Creates a new RBORMQuery as an SQL ‘SELECT SUM([property]) FROM [table name]’ query.

+ (nonnull RBORMQuery *)sumOf:(nonnull NSString *)propertyName

Parameters

propertyName

The property corresponding to the database column that should be summed.

Return Value

A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or `[NSNull null] will be returned.

Declared In

RBORMObject.h

+ averageOf:

Creates a new RBORMQuery as an SQL ‘SELECT AVG([property]) FROM [table name]’ query.

+ (nonnull RBORMQuery *)averageOf:(nonnull NSString *)propertyName

Parameters

propertyName

The property corresponding to the database column that should be averaged.

Return Value

A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or `[NSNull null] will be returned.

Declared In

RBORMObject.h

+ minOf:

Creates a new RBORMQuery as an SQL ‘SELECT MIN([property]) FROM [table name]’ query.

+ (nonnull RBORMQuery *)minOf:(nonnull NSString *)propertyName

Parameters

propertyName

The property corresponding to the database column that should be averaged.

Return Value

A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or `[NSNull null] will be returned.

Declared In

RBORMObject.h

+ maxOf:

Creates a new RBORMQuery as an SQL ‘SELECT MAX([property]) FROM [table name]’ query.

+ (nonnull RBORMQuery *)maxOf:(nonnull NSString *)propertyName

Parameters

propertyName

The property corresponding to the database column that should be averaged.

Return Value

A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or `[NSNull null] will be returned.

Declared In

RBORMObject.h