FMPQuery.Builder

Description

The FMPQuery.Builder class is a builder for the FMPQuery class.

class Builder

Methods

Method Description

database(_:)

Save object of the database, with which FMPQuery will work, to variable.
func database(_ database: FMPDatabase) -> Builder

Parameters:

  • database. Database.

select(_:) Add the SELECT statement to SQL query.
func select(_ columns: [String] = ["*"]) -> Builder

Parameters:

  • columns. List of column names.

from(_:) Add the FROM statement to SQL query.
func from(_ table: FMPTable) -> Builder

Parameters:

  • table. Table.

join(_:type:) Add the JOIN statement to SQL query.
func join(_ table: FMPTable, type: JoinType = .inner) -> Builder

Parameters:

  • table. Table.

  • type. Type of join query.

on(_:) Add the ON statement to SQL query.
func on(_ conditions: [String]) -> Builder

Parameters:

  • conditions. Conditions.

using(_:) Add the USING statement to SQL query.
func using(_ column: String) -> Builder

Parameters:

  • column. Column name.

where(_:) Add the WHERE statement to SQL query.
func where(_ conditions: [String]) -> Builder

Parameters:

  • conditions. Conditions.

order(by:) Add the ORDER BY statement to SQL query.
func order(by columns: [(column: String, asc: Bool)]) -> Builder

Parameters:

  • columns. Sorting conditions that form an array of tuples with the 'column' column name and corresponding 'order' sorting direction.

limit(_:offset:) Add the LIMIT statement to SQL query.
func limit(_ limit: Int, offset: Int? = nil) -> Builder

Parameters:

  • limit. The number of requested rows.

  • offset. The number of skipped rows.

group(by:) Add the GROUP BY statement to SQL query.
func group(by columns: [String]) -> Builder

Parameters:

  • columns. List of column names.

having(_:) Add the HAVING statement to SQL query.
func having(_ conditions: [String]) -> Builder

Parameters:

  • conditions. Conditions.

isResumable(_:) It sets the use of download resumption on data request from server.
func isResumable(_ isResumable: Bool = true) -> Builder

Parameters:

  • isResumable. If the value is true, download resumption is used on request to server. If the value is false, download resumption is not used.

pathForResume(_:) Save the path to folder in application directory, which will store download resumption settings, to variable.
func pathForResume(_ path: String) -> Builder

Parameters:

  • path. The path to folder in application directory, which will store download resumption files.

build() Build an instance of the FMPQuery class. It returns the object of the FMPQuery type.
func build() -> FMPQuery

Example

Build an instance of the FMPQuery class:

// Build an instance of the FMPDatabase class. For details see examples for FMPDatabase.Builder.
let database: FMPDatabase = fmp.database.build()
  
// Build instances of the FMPTable class. For details see examples for FMPTable.Builder.
let table1: FMPTable = fmp.table.build()
let table2: FMPTable = fmp.table.build()
 
// Build an instance of the FMPQuery class with the query expression: SELECT column from table1 LEFT JOIN table2 USING(column) WHERE id = 0 AND key = all ORDER BY column ASC
let query: FMPQuery = fmp.query
    .database(database) // By default nil
    .select(["column"])
    .from(table1)
    .join(table: table2, type: .left)
    .using("column")
    .where(["id = 0", "key = all"])
    .order(by: [(column: "column", asc: true)])
    .isResumable(false) // By default false
    .pathForResume("path") // By default ""
    .build()

See also:

FMPWrapper Framework | Classes