diff --git a/couchbase.android.ts b/couchbase.android.ts
index e2fe7e4..3fd8f52 100644
--- a/couchbase.android.ts
+++ b/couchbase.android.ts
@@ -11,11 +11,21 @@ export class Couchbase {
private manager: any;
private database: any;
- public constructor(databaseName: string) {
+
+ public constructor(databaseName: string, encryptionKey?:string) {
this.context = utils.ad.getApplicationContext();
try {
this.manager = new com.couchbase.lite.Manager(new com.couchbase.lite.android.AndroidContext(this.context), null);
- this.database = this.manager.getDatabase(databaseName);
+ if(!encryptionKey){
+ this.database = this.manager.getDatabase(databaseName);
+ }else{
+ let databaseOptions:any = new com.couchbase.lite.DatabaseOptions();
+ databaseOptions.setCreate(true);
+ databaseOptions.setEncryptionKey(encryptionKey);
+ this.database = this.manager.openDatabase(databaseName, databaseOptions);
+ }
+
+
} catch (exception) {
console.error("MANAGER ERROR:", exception.message);
}
diff --git a/couchbase.d.ts b/couchbase.d.ts
index b26a734..c348c46 100644
--- a/couchbase.d.ts
+++ b/couchbase.d.ts
@@ -1,12 +1,14 @@
declare module "nativescript-couchbase" {
export class Couchbase {
- constructor(databaseName: string);
+ constructor(databaseName: string, encryptionKey?: string);
createDocument(data: Object, documentId?: string);
getDocument(documentId: string);
updateDocument(documentId: string, data: any);
deleteDocument(documentId: string);
destroyDatabase();
+ closeDatabase():boolean;
+ openDatabase(name: string, key?: string);
createView(viewName: string, viewRevision: string, callback: any);
executeQuery(viewName: string, options?: any);
createPullReplication(remoteUrl: string);
diff --git a/couchbase.ios.ts b/couchbase.ios.ts
index d55b572..3cc70cc 100644
--- a/couchbase.ios.ts
+++ b/couchbase.ios.ts
@@ -13,14 +13,19 @@ export class Couchbase {
private manager: any;
private database: any;
- constructor(databaseName: String){
+ constructor(databaseName: String, encryptionKey?:string){
this.manager = CBLManager.sharedInstance();
if (!this.manager){
console.log("MANAGER ERROR:Can not create share instance of CBLManager");
}
var errorRef = new interop.Reference();
-
- this.database = this.manager.databaseNamedError(databaseName, errorRef);
+ if(!encryptionKey){
+ this.database = this.manager.databaseNamedError(databaseName, errorRef);
+ } else {
+ this.database = this.manager.registerEncryptionKeyForDatabaseNamed(databaseName, encryptionKey);
+ this.database = this.manager.databaseNamedError(databaseName, errorRef);
+ }
+
if (!this.database){
console.log(errorRef.value);
@@ -190,6 +195,10 @@ export class Couchbase {
}
}
+ closeDatabase(){
+ return this.database.close();
+ }
+
private mapToJson(properties: Object){
var errorRef = new interop.Reference();
var result = "";
diff --git a/ng-demo/app/app.routing.ts b/ng-demo/app/app.routing.ts
index 97ed102..1736e8b 100644
--- a/ng-demo/app/app.routing.ts
+++ b/ng-demo/app/app.routing.ts
@@ -1,13 +1,16 @@
import { Routes } from "@angular/router";
import { ListComponent } from "./components/list/list.component";
import { CreateComponent } from "./components/create/create.component";
+import { EncryptionComponent } from "./components/encryption/encryption.component";
export const appRoutes: Routes = [
{ path: '', component: ListComponent },
- { path: "create", component: CreateComponent }
+ { path: "create", component: CreateComponent },
+ { path: "encryption", component: EncryptionComponent }
];
export const appComponents: any = [
ListComponent,
- CreateComponent
+ CreateComponent,
+ EncryptionComponent
];
\ No newline at end of file
diff --git a/ng-demo/app/components/encryption/encryption.component.html b/ng-demo/app/components/encryption/encryption.component.html
new file mode 100644
index 0000000..d96da32
--- /dev/null
+++ b/ng-demo/app/components/encryption/encryption.component.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ng-demo/app/components/encryption/encryption.component.ts b/ng-demo/app/components/encryption/encryption.component.ts
new file mode 100644
index 0000000..801572d
--- /dev/null
+++ b/ng-demo/app/components/encryption/encryption.component.ts
@@ -0,0 +1,47 @@
+import {Component} from "@angular/core";
+import {Location} from "@angular/common";
+import {CouchbaseInstance} from "../../couchbaseinstance";
+
+@Component({
+ selector: "encryption",
+ templateUrl: "./components/encryption/encryption.component.html"
+})
+export class EncryptionComponent {
+
+ //private couchbaseInstance: CouchbaseInstance;
+ private database: any;
+ logs: Array;
+ state: string;
+
+ constructor(location: Location,private couchbaseInstance: CouchbaseInstance) {
+
+ this.logs= new Array();
+ //if(this.couchbaseInstance && th)
+ }
+
+ save() {
+ // if(this.firstname != "" && this.lastname != "") {
+ // this.database.createDocument({
+ // "firstname": this.firstname,
+ // "lastname": this.lastname
+ // });
+ // this.location.back();
+ // }
+ }
+
+ open(name:string, key: string){
+ this.database = this.couchbaseInstance.openDatabase(name, key);
+ if(!this.database){
+ this.logs.push("Error on open database")
+ }
+ }
+
+ close(){
+ if(this.couchbaseInstance.closeDatabase()){
+ this.logs.push("closed database")
+ }else {
+ this.logs.push("Error closing database");
+ }
+ }
+
+}
diff --git a/ng-demo/app/components/list/list.component.html b/ng-demo/app/components/list/list.component.html
index 8559616..309f64a 100644
--- a/ng-demo/app/components/list/list.component.html
+++ b/ng-demo/app/components/list/list.component.html
@@ -1,10 +1,21 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ng-demo/app/components/list/list.component.ts b/ng-demo/app/components/list/list.component.ts
index 7532967..6baad9d 100644
--- a/ng-demo/app/components/list/list.component.ts
+++ b/ng-demo/app/components/list/list.component.ts
@@ -1,4 +1,4 @@
-import {Component, NgZone} from "@angular/core";
+import { Component, NgZone, OnInit } from '@angular/core';
import {Router} from "@angular/router";
import {Location} from "@angular/common";
import {CouchbaseInstance} from "../../couchbaseinstance";
@@ -7,20 +7,31 @@ import {CouchbaseInstance} from "../../couchbaseinstance";
selector: "my-app",
templateUrl: "./components/list/list.component.html",
})
-export class ListComponent {
+export class ListComponent implements OnInit{
private database: any;
private router: Router;
private ngZone: NgZone;
public personList: Array