forked from couchbaselabs/hotel-lister-cordova
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4de16cf
commit 674823b
Showing
1 changed file
with
44 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 44 additions & 1 deletion
45
modules/hotel-lister/examples/cordova-plugin-hotel-lister/src/ios/HotelLister.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] | ||
|
||
} |