Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d26b78f
Updated README with new N1QL syntax
janober Jan 27, 2015
69ba1cc
-Added save
janober Jan 28, 2015
4e65c86
Now does not use N1QL anymore when the document id is already given
janober Feb 3, 2015
6d3e980
Removed not needed parameters from prepareCreateData
janober Feb 3, 2015
7093a2a
Create returns now just the id like the connector expect it to. So th…
janober Feb 3, 2015
11dcf6e
Do not error anymore when an id does not exist
janober Feb 4, 2015
c9961c8
Fixed issue that it did return an empty array instead of null when id…
janober Feb 4, 2015
7f8078b
Does now not anymore query the document before it gets saved
janober Feb 5, 2015
979fa87
Removed all the N1QL code and made it work with views instead
janober Feb 10, 2015
08707a7
Removed the cas-data till the rest is also there
janober Feb 10, 2015
7856a67
Now returns and uses the CAS. Will only update if it matches. To make…
janober Feb 10, 2015
9b96b0d
Removed not needed constants (was needed in part for N1QL)
janober Feb 10, 2015
305e8ed
Fixed issue which makes loopback crash when view returns and empty re…
janober Feb 10, 2015
4f6bc21
Added password support
janober Feb 10, 2015
53bc5bc
Updated readme to example with password
janober Feb 10, 2015
535c458
Now converts data on load into the correct format (Date & Boolean) wh…
janober Feb 10, 2015
e39faf0
Removed debug code which I left behind by accident
janober Feb 10, 2015
6cb3512
Now just creates the bucket-connection once and then reuses it #4
janober Feb 13, 2015
07fbeb9
Now supports deleteById
janober Feb 25, 2015
8b5f1a0
Renamed package
janober May 23, 2015
854e012
Updated to use new name
janober May 23, 2015
ee5814e
Fixed a bug which caused connector to crash when a database operation…
janober May 26, 2015
338cbbb
Removed docType
janober Oct 27, 2015
2355f99
Update to latest couchbase library version
janober Feb 5, 2016
7c810de
Upversion to 0.4.0
janober Feb 5, 2016
04ec919
Fix issue when ids are now given as arrays
janober Feb 9, 2016
01e594a
Upversion to 0.4.1
janober Feb 9, 2016
8888ad4
Fix bug
janober Feb 19, 2016
599b544
Upversion to 0.4.2
janober Feb 19, 2016
a623491
Fix typo
janober May 29, 2016
e409787
Allow where queries for id no matter if limit is set (becaus can just…
janober Feb 9, 2017
215c392
Upversion to 0.4.3
janober Feb 9, 2017
b85cd8a
Allow to set document expiry date by setting "_expiry" on the document
janober May 14, 2017
41cbe1e
Upversion to 0.5.0
janober May 14, 2017
e11308b
Allow to set document expiry date by setting "_expiry" on the documen…
janober May 15, 2017
f86c49c
Upversion to 0.6.0
janober May 15, 2017
8bd2357
Changes to make it work with new authentication in Couchbase Server 5.0
janober Nov 24, 2017
55f2569
Upversion to 0.7.0
janober Nov 24, 2017
3b6bf9c
Make destroyAll work as long as only one id is given
janober Jun 3, 2018
980a845
Fix error in previous commit
janober Jun 3, 2018
000ded4
Upversion to 0.8.0
janober Jun 3, 2018
d4bc356
Do not fail destroyAll when no id is given
janober Jun 3, 2018
f5452b9
Upversion to 0.8.1
janober Jun 3, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 54 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,85 @@

## loopback-connector-couchbase
## loopback-connector-couchbase without N1QL

The Couchbase Connector module for for [loopback-datasource-juggler](http://docs.strongloop.com/loopback-datasource-juggler/).

This connector does not use N1QL. That means you can not simply lookup data you do not have view setup and defined in the configuration. So you have to be very careful which data you query (that is why I put the expert in the name). If you for example have a relationship setup and you want to use it to query related data it will fail till you create * setup a view which allows it. Actually querying data will probably almost always fail if you do not use "findById". So you have to write your application a very specific way for it to work but the price for that effort is high performance. So for the most people using the N1QL implementation (from which I did fork) is probably better: https://github.com/guardly/loopback-connector-couchbase

Btw. is also not really well tested. Did just fork to work best for my own needs of high performance (and no random query need).

### What is Couchbase Server?
Couchbase Server is a NoSQL document database for interactive web applications. It has a flexible data model, is easily scalable, provides consistent high performance and is "always-on", meaning it can serve application data 24 hours, 7 days a week.


### What is N1QL?
N1QL (pronounced "Nickel") is a next generation query language for Couchbase Server. N1QL presents easy and familiar abstractions to quickly develop scalable applications that work with next generation database systems. It allows for joins, filter expressions, aggregate expressions and many other features to build a rich application.


### Getting Started
Before installing the connector module, make sure you've taken the appropriate steps to install and configure Couchbase Server and the N1QL Engine.
Before installing the connector module, make sure you've taken the appropriate steps to install and configure Couchbase Server.

* Download and install [Couchbase Server](http://www.couchbase.com/nosql-databases/downloads).
* After the install completes confirm the Couchbase Administrator is running at http://localhost:8091
* Download the [N1QL Binaries](http://www.couchbase.com/nosql-databases/downloads#PreRelease)


### N1QL Tutorial
N1QL has an interactive online tutorial and a N1QL cheatsheet. The online tutorial is a good way to get started and play with N1QL in an easy, fun environment. The cheatsheet is a quick glance and easy reference of the N1QL syntax. NOTE: Not all capabilities of the N1QL Engine are supported in this connector. For more information on N1QL, see:

* [N1QL Cheatsheet](http://docs.couchbase.com/files/Couchbase-N1QL-CheatSheet.pdf)
* [Couchbase Language Tutorial](http://query.pub.couchbase.com/tutorial/#1)


### Running N1QL
To run N1QL on your local system:

Step 1: Expand the package archive.
Step 2: On the command line, navigate to your local N1QL directory.
Step 3: Run ./start_tutorial.sh (Unix)
./start_tutorial.bat (Windows)
Step 4: Open http://localhost:8093/tutorial in your browser to use the tutorial on your local server.

To connect N1QL with your Couchbase Server:

./cbq-engine -couchbase http://[server_name]:8091/


To use the command-line interactive query tool:

./cbq-engine=http://[couchbase-query-engine-server-name]:8093/


Step 5: Before issuing queries against a Couchbase bucket, run the following command from the query command line:

CREATE PRIMARY INDEX ON [bucket-name]



### Installing the connector
```npm install couchbase```

```npm install loopback-connector-couchbase```
```npm install loopback-connector-couchbase-expert```


## Connector settings

The connector can be configured using the following settings from the data source.
* host (default to 'localhost'): The host name or ip address of the Couchbase server
* port (default to 8091): The port number of the Couchbase server
* n1qlport (default to 8093): The port number of the N1QL Engine
* database: The Couchbase bucket
* user: The user to access Couchbase cluster
* password: The password to access Couchbase cluster
* connectionTimeout (default to 20000): The connection timeout value
* operationTimeout (default to 15000): The operation timeout value
* mappings: Prefixes for values which get used as key (example below)
* views: Views which can be used to loopup data

**NOTE**: Unlike other datasources, Couchbase does not require user credentials to access a bucket/database. Buckets can be protected with a password, however, the N1QL Developer Pre-release 3 currently does not support querying password protected buckets. As this capability is released for N1QL, we will update the connector settings.

## Example Configuration

```json
{
"couchbase": {
"host": "localhost",
"port": "8091",
"database": "myBucket",
"name": "couchbase-expert",
"user": "my-user",
"password": "my-password",
"connector": "couchbase-expert",
"mappings": {
"user": {
"email": "u::"
}
},
"views": {
"Orders": {
"userId": {
"designDocument": "loopback",
"viewName": "orders_userid"
}
}
}
}
}

```

Everything should be clear the only interesting parts are mappings & views.

* "mappings" defines id-prefixes. So if somebody queries for a user by email then the query will be rewritten to a lookup by id. So if I look for {"email": "test@example.com"} it will do instead a look for the id: "u::test@example.com"
* "views" defines views which can be used to loopup specific values. The example bellow allows to lookup "order" by "userId" by using the view "orders_userid" under a design-document called "loopback". For it to work a view like this has to be setup:

```
function (doc, meta) {
if (doc.docType && doc.docType == "Order" && doc.userId) {
emit(doc.userId, null);
}
}
```


## Model definition for Couchbase Documents
Expand Down Expand Up @@ -112,17 +123,12 @@ The model definition consists of the following properties:

```

### Example Application
We have also put together a small example application which uses the **beer-sample** bucket which is an optional add-on when installing Couchbase Server. There is currently no client front-end for the example app, however you can use the LoopBack Explorer to interact with the API and connector.

* [loopback-example-couchbase](https://github.com/guardly/loopback-example-couchbase): Example application

### Working with data
Please refer to the official [LoopBack Documentation](http://docs.strongloop.com/display/public/LB/Working+with+data) for how to work with models and data.


### More to come!!!
* Write additional tests
* Write tests
* Improve debugging and logging
* etc!!!

17 changes: 0 additions & 17 deletions lib/base/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,7 @@ function define(name, value) {
});
}

define("KEYWORD_LEVEL1_WHERE", "where");
define("KEYWORD_LEVEL1_FIELDS", "fields");
define("KEYWORD_LEVEL1_INCLUDE", "include");
define("KEYWORD_LEVEL1_LIMIT", "limit");
define("KEYWORD_LEVEL1_ORDER", "order");
define("KEYWORD_LEVEL1_SKIP", "skip");
define("KEYWORD_LEVEL1_OFFSET", "offset");

define("KEYWORD_LEVEL2_AND", "and");
define("KEYWORD_LEVEL2_OR", "or");

define("KEYWORD_LEVEL3_GREAT_THAN", "gt");
define("KEYWORD_LEVEL3_LESS_THAN", "lt");
define("KEYWORD_LEVEL3_BETWEEN", "between");
define("KEYWORD_LEVEL3_LIKE", "like");

define("KEYWORD_CONVENTION_DOCID", "id");
define("KEYWORD_CONVENTION_DOCTYPE", "docType");

define("KEYWORD_PRESERVED_COUCHBASE", "couchbase");
define("KEYWORD_PRESERVED_KEYNAME", "preserve");
Expand Down
Loading