PHPackages                             bowlofsoup/couchbase-access-layer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. bowlofsoup/couchbase-access-layer

ActiveLibrary[Database &amp; ORM](/categories/database)

bowlofsoup/couchbase-access-layer
=================================

A simple Couchbase query builder.

v2.0.1(1y ago)54.6k1[2 issues](https://github.com/BowlOfSoup/couchbase-access-layer/issues)1MITPHPPHP ^8.3

Since Feb 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/BowlOfSoup/couchbase-access-layer)[ Packagist](https://packagist.org/packages/bowlofsoup/couchbase-access-layer)[ RSS](/packages/bowlofsoup-couchbase-access-layer/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (3)Versions (8)Used By (1)

[![Minimum PHP Version](https://camo.githubusercontent.com/673c7edc68e400d93b03ac0efe8d58d63bc90169086ca191e2f37236be94eeaa/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545253230372e302d626c75652e7376673f6e6f2d63616368653d31)](https://php.net/)[![Build Status](https://camo.githubusercontent.com/ceac857def9999868334b7e62a318a963aac68f86c8fa43d70acb6c073c5948e/68747470733a2f2f7472617669732d63692e6f72672f426f776c4f66536f75702f636f756368626173652d6163636573732d6c617965722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/BowlOfSoup/couchbase-access-layer)[![Coverage Status](https://camo.githubusercontent.com/da9278a7e5713607a5410c3a42f49b6a87a5572a221ed8bd31a927069332bf03/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f426f776c4f66536f75702f636f756368626173652d6163636573732d6c617965722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/BowlOfSoup/couchbase-access-layer?branch=master)

- [Installation](#installation)
- [Usage](#usage)
    - [Do use Parameters](#do-use-parameters)
    - [The query builder supports the following N1QL clauses](#the-query-builder-supports-the-following-n1ql-clauses)
    - [Examples](#examples)
    - [Using a sub query in a FROM statement](#using-a-sub-query-in-a-from-statement)
- [Unit tests](#unit-tests)

Installation
------------

[](#installation)

```
composer require bowlofsoup/couchbase-access-layer

```

Couchbase Access Layer
======================

[](#couchbase-access-layer)

A **simple** layer on top of the PHP Couchbase SDK. Basically you get a *bucket* repository class which acts as a layer between your code and Couchbase.

The repository helps you to:

- Quickly setup a Couchbase connection.
- A handy to use BucketRepository to quickly query a **single** bucket.
- Create queries with a so called '**query builder**', this helps you build maintainable and easy to read N1ql queries.
- Processes the differences in result syntax you can get back from Couchbase into a consistent query result.
- See below for more examples!

Usage
-----

[](#usage)

#### Do use Parameters

[](#do-use-parameters)

Important: When building a query, always try to use parameters.

Incorrect:

```
$queryBuilder
    ->where('data.creationDate >= ' . $creationDate);

```

Correct:

```
$queryBuilder
    ->where('data.creationDate >= $creationDate')
    ->setParameter('creationDate', '2019-01-10');

```

This will prevent injection.

#### The query builder supports the following N1QL clauses

[](#the-query-builder-supports-the-following-n1ql-clauses)

- `SELECT` with optional `DISTINCT` and `RAW`
- `FROM` with optional alias, subquery also implemented (= mandatory alias)
- `USE` which means: `USE KEYS` and `USE INDEX`
- `WHERE`
- `GROUP BY`
- `ORDER BY`
- `LIMIT`
- `OFFSET`

Documentation for clauses can be found [On the Couchbase site](https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/selectintro.html).

#### Examples

[](#examples)

```
