The FMPDatabase class is used to describe a local database.
class FMPDatabase
Property | Description |
path |
The full path to database in the application directory. var path: String { get } |
Method | Description |
open() |
Open database connection. In case of successful opening of database connection, the true value is returned. func open() -> Bool |
close() | Close database connection. func close() |
query(_:) | It sends SQL query to local database. func query(_ query: String) -> [NSDictionary]? Parameters:
|
getTableName(for:) | Get real table name in local database. It returns the table name in local database. func getTableName(for table: FMPTable) -> String? Parameters:
|
dropCache(for:) | Delete cached tables from database for the specified resource. In case of successful deletion of tables from database, the true value is returned. func dropCache(for resource: FMPResource) -> Bool Parameters:
|
drop() | Delete database file from application directory. func drop() throws |
copy() | Get instance of builder class for copying FMPDatabase. It returns the instance of the FMPDatabase.Builder builder class. func copy() -> FMPDatabase.Builder |
Open database connection:
// Build an instance of the FMPDatabase class. For details see examples for FMPDatabase.Builder.
let database: FMPDatabase = fmp.database
.path("path")
.build()
// Open database connection
let openSuccess: Bool = database.open()
Close database connection:
// Build an instance of the FMPDatabase class. For details see examples for FMPDatabase.Builder.
let database: FMPDatabase = fmp.database
.path("path")
.build()
// Close database connection
database.close()
SQL query to database:
// Build an instance of the FMPDatabase class. For details see examples for FMPDatabase.Builder.
let database: FMPDatabase = fmp.database.build()
// Get result of SQL query to database
let queryResult: [NSDictionary]? = database.performQuery("SELECT * FROM table")
Get real table name in local database:
// Build an instance of the FMPDatabase class. For details see examples for FMPDatabase.Builder.
let database: FMPDatabase = fmp.database.build()
// Build an instance of the FMPResource class that describes the required mobile platform resource. For details see examples for FMPResource.Builder.
let resource: FMPResource = fmp.resource
.name(resourceName)
.params(inputParams)
.build()
// Build an instance of the FMPTable class that describes the required mobile platform resource table. For details see examples for FMPTable.Builder.
let table: FMPTable = fmp.table
.name("tableName")
.resource(resource)
.build()
// Get real table name in database
let realTableName: String = database.getTableName(for: table)
Delete cached tables from database for the specified resource:
// Build an instance of the FMPDatabase class. For details see examples for FMPDatabase.Builder.
let database: FMPDatabase = fmp.database.build()
// Build an instance of the FMPResource class that describes the required mobile platform resource. For details see examples for FMPResource.Builder.
let resource: FMPResource = fmp.resource
.name(resourceName)
.params(inputParams)
.build()
// Delete all cached tables for the specified resource from database
let dropSuccess: Bool = database.dropCache(for: resource)
Delete database file from application directory:
// Build an instance of the FMPDatabase class. For details see examples for FMPDatabase.Builder.
let database: FMPDatabase = fmp.database.build()
// Delete database file from application directory
do {
try database.drop()
} catch let error {
// Display error description
print(error.localizedDescription)
}
Copy FMPDatabase:
// Build an instance of the FMPDatabase class. For details see examples for FMPDatabase.Builder.
let database: FMPDatabase = fmp.database.build()
// Copy instance of the FMPScheme class.
let databaseCopy: FMPDatabase = database.copy().build()
See also: