Skip to content

Commit

Permalink
update plugin's HotelLister.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnocentini committed Oct 28, 2018
1 parent 4de16cf commit 674823b
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
import CouchbaseLiteSwift

@objc(HotelLister) class HotelLister : CDVPlugin {

var database: Database?

// tag::initialize[]
override func pluginInitialize() {
self.database = DatabaseManager.sharedInstance().database
}
// end::initialize[]

// tag::query-hotels[]
@objc(queryHotels:)
func queryHotels(command: CDVInvokedUrlCommand) {
let DOC_TYPE = "hotel";

}
let query = QueryBuilder
.select(
SelectResult.expression(Meta.id),
SelectResult.property("address"),
SelectResult.property("phone"),
SelectResult.property("name")
)
.from(DataSource.database(database!))
.where(
Expression.property("type")
.equalTo(Expression.string(DOC_TYPE))
)

do {
let resultSet = try query.execute()
let resultSetArray = resultSet.allResults()
var array = [Any]()
for item in resultSetArray {
array.append(item.toDictionary())
}
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: array)
self.commandDelegate.send(pluginResult, callbackId: command.callbackId)
} catch {
fatalError(error.localizedDescription);
}
}
// end::query-hotels[]

}

0 comments on commit 674823b

Please sign in to comment.