SwiftyDB
public class SwiftyDB
A class wrapping an SQLite3 database abstracting the creation of tables, insertion, update, and retrieval
-
Creates a new instance of SwiftyDB using a database in the documents directory. If the database does not exist, it will be created.
Declaration
Swift
public init(databaseName: String)
Parameters
databaseName
name of the database
Return Value
an instance of SwiftyDB
-
Add an object to the database
Declaration
Swift
public func addObject <S: Storable> (object: S, update: Bool = true) -> Result<Bool>
Parameters
object
object to be added to the database
update
indicates whether the record should be updated if already present
Return Value
Result type indicating the success of the query
-
Add objects to the database
Declaration
Swift
public func addObjects <S: Storable> (objects: [S], update: Bool = true) -> Result<Bool>
Parameters
objects
objects to be added to the database
update
indicates whether the record should be updated if already present
Return Value
Result type indicating the success of the query
-
Add objects to the database
Declaration
Swift
public func addObjects <S: Storable> (object: S, _ moreObjects: S...) -> Result<Bool>
Parameters
object
object to be added to the database
moreObjects
more objects to be added to the database
Return Value
Result type indicating the success of the query
-
Remove objects of a specified type, matching a set of filters, from the database
Declaration
Swift
public func deleteObjectsForType (type: Storable.Type, matchingFilters filters: Filter? = nil) -> Result<Bool>
Parameters
filters
dictionary containing the filters identifying objects to be deleted
type
type of the objects to be deleted
Return Value
Result type indicating the success of the query
-
Get data for a specified type, matching a set of filters, from the database
Declaration
Swift
public func dataForType <S: Storable> (type: S.Type, matchingFilters filters: Filter? = nil) -> Result<[[String: SQLiteValue?]]>
Parameters
filters
dictionary containing the filters identifying objects to be retrieved
type
type of the objects for which to retrieve data
Return Value
Result type wrapping an array with the dictionaries representing objects, or an error if unsuccessful
-
Asynchronously add object to the database
Declaration
Swift
public func asyncAddObject <S: Storable> (object: S, update: Bool = true, withCompletionHandler completionHandler: ((Result<Bool>)->Void)? = nil)
Parameters
object
object to be added to the database
update
indicates whether the record should be updated if already present
-
Asynchronously add objects to the database
Declaration
Swift
public func asyncAddObjects <S: Storable> (objects: [S], update: Bool = true, withCompletionHandler completionHandler: ((Result<Bool>)->Void)? = nil)
Parameters
objects
objects to be added to the database
update
indicates whether the record should be updated if already present
-
Asynchronous retrieval of data for a specified type, matching a set of filters, from the database
Declaration
Swift
public func asyncDataForType <S: Storable> (type: S.Type, matchingFilters filters: Filter? = nil, withCompletionHandler completionHandler: ((Result<[[String: SQLiteValue?]]>)->Void))
Parameters
filters
dictionary containing the filters identifying objects to be retrieved
type
type of the objects to be retrieved
-
Asynchronously remove objects of a specified type, matching a set of filters, from the database
Declaration
Swift
public func asyncDeleteObjectsForType (type: Storable.Type, matchingFilters filters: Filter? = nil, withCompletionHandler completionHandler: ((Result<Bool>)->Void)? = nil)
Parameters
filters
dictionary containing the filters identifying objects to be deleted
type
type of the objects to be deleted
-
Asynchronous retrieval of objects of a specified type, matching a set of filters, from the database
Declaration
Swift
public func asyncObjectsForType <D where D: Storable, D: NSObject> (type: D.Type, matchingFilters filters: Filter? = nil, withCompletionHandler completionHandler: ((Result<[D]>)->Void))
Parameters
filters
dictionary containing the filters identifying objects to be retrieved
type
type of the objects to be retrieved
-
Get objects of a specified type, matching a set of filters, from the database
Declaration
Swift
public func objectsForType <D where D: Storable, D: NSObject> (type: D.Type, matchingFilters filters: Filter? = nil) -> Result<[D]>
Parameters
filters
dictionary containing the filters identifying objects to be retrieved
type
type of the objects to be retrieved
Return Value
Result wrapping the objects, or an error, if unsuccessful