'use strict';

const g = require('strong-globalize')();
const util = require('util');

const couchbase = require('couchbase');
const n1qlQuery = couchbase.N1qlQuery;

const SqlConnector = require('loopback-connector').SqlConnector;
const ParameterizedSQL = SqlConnector.ParameterizedSQL;

const debug = require('debug')('loopback:connector:couchbase');

exports.initialize = function initializeDataSource(dataSource, callback) {
  if (!couchbase) {
    return;
  }

  dataSource.connector = new Couchbase(dataSource, dataSource.settings);

  if (callback) {
    if (dataSource.settings.lazyConnect) {
      process.nextTick(function() {
        callback();
      });
    } else {
      dataSource.connector.connect(callback);
    }
  }
};

exports.Couchbase = Couchbase;

function Couchbase(dataSource, settings) {
	this.dataSource = dataSource;
  SqlConnector.call(this, 'couchbase', settings);
}

util.inherits(Couchbase, SqlConnector);

function configurationOptions(settings) {
  return {
    host: settings.host || 'localhost',
    port: settings.port || 8091,
    bucket: settings.bucket || 'default'
    password : settings.password || '',
  };
}
@@ -975,16 +975,84 @@
 ings) %7B%0A
+  const url = 'couchbase://' + settings.host + ':' + settings.port;%0A
   return
@@ -1214,8 +1214,727 @@
 ,%0A  
+  url: url%0A  %7D;%0A%7D%0A%0ACouchbase.prototype.connect = function(callback) %7B%0A  let self = this;%0A  const options = configurationOptions(self.settings);%0A%0A  if (self.bucket) %7B%0A    process.nextTick(function() %7B%0A      callback && callback(null, self.bucket);%0A    %7D);%0A  %7D else %7B%0A    let error = null;%0A    self.cluster = new couchbase.Cluster(settings.url);%0A    self.bucket = cluster.openBucket(settings.bucket, settings.password, function(err) %7B%0A      if (!err) %7B%0A        debug('Couchbase connection is established: %25j', self.settings %7C%7C %7B%7D);%0A      %7D else %7B%0A        error = err;%0A        debug('Couchbase connection is failed: %25j', self.settings %7C%7C %7B%7D, err);%0A        %7D%0A      %7D%0A    %7D);%0A    callback && callback(error, self.bucket);%0A  %7D%0A
 %7D;
-%0A%7D

Connect method added