ADTableStore
public class ADTableStore
Represents an in-memory SQL Data Store table used to hold both the table’s schema and the data it represents.
Remark
Since aADTableStore
holds all data in-memory, care should be taken not to overload memory. As a result, an ADTableStore
is not a good choice for working with large amounts of data.
-
Holds the schema defining this table as the columns for each row, the column types and any constraints applied to those columns.
Declaration
Swift
public var schema: ADTableSchema!
-
Returns the value of the primary key for the last record added to the table. If there are no records in the table or no primary key defined,
nil
is returned.Declaration
Swift
public var lastPrimaryKeyValue: Any?
-
Returns the next ID value for auto incrementing integer primary keys else returns zero (0).
Declaration
Swift
public var nextAutoIncrementingID: Int
-
For data sources that provide in-memory data storage (such as JSON, SPON and XML) this property holds all of the rows in the table as
ADRecord
objects.Declaration
Swift
public var rows: ADRecordSet = []
-
Initializes a new table storage instance.
Declaration
Swift
public init(tableName: String)
Parameters
tableName
The name of the table to be stored in the instance.
-
Initializes a new table storage instance.
Declaration
Swift
public init(fromInstance dictionary: ADInstanceDictionary)
Parameters
dictionary
A
ADInstanceDictionary
to initialize the table storage from.
-
Test to see if the table contains a row with the given primary key value.
Declaration
Swift
public func hasRow(withPrimaryKeyValue value: Any) -> Bool
Parameters
withPrimaryKeyValue
The value to find in the table.
Return Value
true
if the table contains a row with the given primary key value, elsefalse
if not. -
Attempts to insert the given record in the table.
Declaration
Swift
public func insertRow(_ record: ADRecord, action: ADSQLInsertInstruction.Action = .insert) throws
Parameters
record
The
ADRecord
to add to the table.action
The
ADSQLInsertInstruction.Action
to use when the insert fails. The default isinsert
only. -
Checks the given record to ensure it is valid in the context of the table.
Declaration
Swift
public func validateRecord(_ record: ADRecord) -> ADSQLExecutionError?
Parameters
record
The
ADRecord
to validate.Return Value
nil
if there were no issues with the record, else returns aADSQLExecutionError
describing any found issues. -
Returns the first row matching the given record on the given list of columns.
Declaration
Parameters
record
An
ADRecord
containing the values to match against.columnNames
An array of columns names to match on.
Return Value
An
ADRecord
representing the first row matched in the table ornil
if none was found. -
Returns all rows matching the given record on the given list of columns.
Declaration
Swift
public func findRows(matching record: ADRecord, onColumns columnNames: [String]) -> ADRecordSet
Parameters
record
An
ADRecord
containing the values to match against.columnNames
An array of columns names to match on.
Return Value
An
ADRecordSet
representing the all rows matched in the table or an empty set if none were found. -
Returns the first row matching the values in the given record using the given expression.
Declaration
Swift
public func findRow(matching record: ADRecord, on expression: ADSQLExpression, alias: String = "") throws -> ADRecord?
Parameters
record
An
ADRecord
containing the values to match against.expression
A
ADSQLExpression
used to compare rows in the table against the passed in record’s values.alias
An option alias for the table’s name.
Return Value
An
ADRecord
representing the first row matched ornil
if none was found. -
Returns the all rows matching the values in the given record using the given expression.
Declaration
Swift
public func findRows(matching record: ADRecord, on expression: ADSQLExpression, alias: String = "") throws -> ADRecordSet
Parameters
record
An
ADRecord
containing the values to match against.expression
A
ADSQLExpression
used to compare rows in the table against the passed in record’s values.alias
An option alias for the table’s name.
Return Value
An
ADRecordSet
representing the all rows matched or an empty set if none were found. -
Encodes the table store into an Instance Dictionary for storage in a Swift Portable Object Notation (SPON) format. -Returns: The table store represented as an Instance Dictionary.
Declaration
Swift
public func encode() -> ADInstanceDictionary
-
Decodes the table store from an Instance Dictionary that has been read from a Swift Portable Object Notation (SPON) stream.
Declaration
Swift
public func decode(fromInstance dictionary: ADInstanceDictionary)
Parameters
dictionary
A
ADInstanceDictionary
representing the values for the table store.