Index

RBORMObject.swift

Classes


RBORMObject

Provides a managed ORM (Object relationship management) object for use with SQLite. Note: Only properties recognized by the Obj-C runtime can be recognized i.e. Swift nilable types such as Int? will be ignored. - Note: NSDates are automatically serialized and deserialized. Dates are stored on disk in the ISO 8601 format.

Properties

The primary key assigned to this object by SQLite. Will be set to a value < 1 if the object has not yet been saved.
public var pk Int { get set }

Indiciates that a valid primary key value has been set and assigned by SQLite.
public var hasPrimaryKey Bool { get }

The database identifier for the database this object is associated with.
public var databaseIdentifier String { get }

Functions

A list of the nullable properties for this object.
@returns A list of the properites that are permitted to be null or nil.
class open func nullableProperties() -> [String]?

A mapping of property names to database column names when the names differ. Format [ propertyName : databaseColumnName ]
@returns A mapping of the property names and their corresponding database column names.
class open func propertiesToColumnNames() -> [String: String]?

Returns the table name to be used. The default implementation returns the name of the class (removes module names i.e. Module.ClassName -> ClassName) and strips any non alphanumeric characters.
@returns The name of the table.
class open func tableName() -> String

Deletes this object from the database.
@returns Returns true if successful.
public func delete() -> Bool

Saves this object. An insert or update occurs as needed.
@returns Returns true if successful.
public func save() -> Bool

This method is called before inserting.
open func willInsert()

This method is called before updating.
open func willUpdate()

Called after inserting.
@param success : If YES then the object has been saved successfully.
open func didInsert(_ success: Bool)

Called after updating.
@param success : If YES then the object has been saved successfully.
open func didUpdate(_ success: Bool)

This method is called before deletion.
open func willDelete()

Called after deletion.
@param success : If YES then the object has been saved deleted.
open func didDelete(_ success: Bool)

This method is called before populating the data in the object instance.
open func willPopulate()

Called after population.
@param success : If YES then the object has been saved populated.
open func didPopulate(_ success: Bool)

Executes a given SQL query string with the given bindings using the default database identifier. Expects the query is setup to return a list of objects.
@param queryString : The SQL query string to execute.
@param bindings : The corresponding bindings for the SQL query string given.
@returns The result
public class func executeQuery(queryString: String, bindings: [Any]?) -> RBORMResult

Executes a given SQL query string with the given bindings on the database who's identifier is given. Expects the query is setup to return a list of objects.
@param queryString : The SQL query string to execute.
@param bindings : The corresponding bindings for the SQL query string given.
@param databaseIdentifier : The identifier of the database to query.
@returns The result
public class func executeQuery(queryString: String, bindings: [Any]?, databaseIdentifier: String) -> RBORMResult

Creates a new RBORMQuery as an SQL 'SELECT FROM [table name]' query for the default database identifier.
@returns A newly initialized RBORMQuery object. When executing this query an array of 0 or more typed objects will be returned.
public class func select() -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT FROM [table name]' query for the default database identifier.
@param databaseIdentifier : The identifier of the database to use.
@returns A newly initialized RBORMQuery object. When executing this query an array of 0 or more typed objects will be returned.
public class func select(databaseIdentifier: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'DELETE FROM [table name]' query for the default database identifier.
@returns 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.
public class func delete() -> RBORMQuery

Creates a new RBORMQuery as an SQL 'DELETE FROM [table name]' query.
@param databaseIdentifier : The identifier of the database to use.
@returns 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.
public class func delete(databaseIdentifier: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT COUNT' query for the default database identifier.
@param propertyName : The property corresponding to the database column that should be counted or *.
@returns A newly initialized *
RBORMQuery
object. When executing this query an array containing a single item of type NSNumber will be returned.
public class func countOf(_ propertyName: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT COUNT' query.
@param propertyName : The property corresponding to the database column that should be counted or *.
@param databaseIdentifier : The identifier of the database to use.
@returns A newly initialized *
RBORMQuery
object. When executing this query an array containing a single item of type NSNumber will be returned.
public class func countOf(_ propertyName: String, databaseIdentifier: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT SUM([property]) FROM [table name]' query for the default database identifier.
@param propertyName : The property corresponding to the database column that should be summed.
@returns A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or **[NSNull null] will be returned.
public class func sumOf(_ propertyName: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT SUM([property]) FROM [table name]' query.
@param propertyName : The property corresponding to the database column that should be summed.
@param databaseIdentifier : The identifier of the database to use.
@returns A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or **[NSNull null] will be returned.
public class func sumOf(_ propertyName: String, databaseIdentifier: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT AVG([property]) FROM [table name]' query for the default database identifier.
@param propertyName : The property corresponding to the database column that should be averaged.
@returns A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or **[NSNull null] will be returned.
public class func averageOf(_ propertyName: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT AVG([property]) FROM [table name]' query.
@param propertyName : The property corresponding to the database column that should be averaged.
@param databaseIdentifier : The identifier of the database to use.
@returns A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or **[NSNull null] will be returned.
public class func averageOf(_ propertyName: String, databaseIdentifier: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT MIN([property]) FROM [table name]' query for the default database identifier.
@param propertyName : The property corresponding to the database column that should be averaged.
@returns A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or **[NSNull null] will be returned.
public class func minOf(_ propertyName: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT MIN([property]) FROM [table name]' query.
@param propertyName : The property corresponding to the database column that should be averaged.
@param databaseIdentifier : The identifier of the database to use.
@returns A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or **[NSNull null] will be returned.
public class func minOf(_ propertyName: String, databaseIdentifier: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT MAX([property]) FROM [table name]' query for the default database identifier.
@param propertyName : The property corresponding to the database column that should be averaged.
@returns A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or **[NSNull null] will be returned.
public class func maxOf(_ propertyName: String) -> RBORMQuery

Creates a new RBORMQuery as an SQL 'SELECT MAX([property]) FROM [table name]' query.
@param propertyName : The property corresponding to the database column that should be averaged.
@param databaseIdentifier : The identifier of the database to use.
@returns A newly initialized RBORMQuery object. When executing this query an array containing a single item of type NSNumber or **[NSNull null] will be returned.
public class func maxOf(_ propertyName: String, databaseIdentifier: String) -> RBORMQuery

Returns the object for the given primary key value.
@param pk : The primary key. Must be > 0.
@returns The object matching the primary key or nil if not found.
public class func forPk(_ pk: Int) -> RBORMObject?

Returns the object for the given primary key value.
@param pk : The primary key. Must be > 0.
@returns The object matching the primary key or nil if not found.
public class func forPk(_ pk: Int, databaseIdentifier: String) -> RBORMObject?

Determines whether a table exists for this object type in the database for the default database identifier.
@returns Whether or not the table exists.
public class func tableExists() -> Bool

Determines whether a table exists for this object type for the database identifier provided.
@param databaseIdentifier : The identifier of the database to use.
@returns Whether or not the table exists.
public class func tableExists(databaseIdentifier: String) -> Bool

Creates the table for this object type for the default database identifier if the table is missing.
@returns Whether or not the table exists or was created.
public class func createTableIfMissing() -> Bool

Creates the table for this object type for the database identifier provided if the table is missing.
@param databaseIdentifier : The identifier of the database to use.
@returns Whether or not the table exists or was created.
public class func createTableIfMissing(databaseIdentifier: String) -> Bool