# Class: Ottoman

# Hierarchy

  • Ottoman

# Constructors

# constructor

+ new Ottoman(config: OttomanConfig): Ottoman

Parameters:

Name Type Default
config OttomanConfig {}

Returns: Ottoman

# Properties

# bucket

bucket: any

Bucket represents a storage grouping of data within a Couchbase Server cluster.


# bucketName

bucketName: string = ""

Contains the name of the current bucket.


# config

config: OttomanConfig


# couchbase

couchbase: any

Stores a reference to couchbase instance.


# models

models: object

Dictionary for all models registered on this connection.

# Type declaration:

# Accessors

# bucketManager

get bucketManager(): any

Gets a bucket manager for this cluster

Returns: any


# cluster

get cluster(): any

Cluster represents an entire Couchbase Server cluster.

Returns: any


# collectionManager

get collectionManager(): any

CollectionManager allows the management of collections within a Bucket.

Returns: any


# queryIndexManager

get queryIndexManager(): any

QueryIndexManager provides an interface for managing the query indexes on the cluster.

Returns: any


# viewIndexManager

get viewIndexManager(): any

ViewIndexManager is an interface which enables the management of view indexes on the cluster.

Returns: any

# Methods

# close

close(): void

Closes the current connection

example

connection.close().then(() => console.log('connection closed'));

Returns: void


# connect

connect(connectOptions: ConnectOptions | string): Ottoman

Connect to Couchbase server

example

 import { connect } from "ottoman";
 const connection = connect("couchbase://localhost/travel-sample@admin:password");

Parameters:

Name Type
connectOptions ConnectOptions | string

Returns: Ottoman


# dropBucket

dropBucket(bucketName: string, options: object): Promise‹boolean | undefined›

dropBucket drops a bucket from the cluster.

Parameters:

bucketName: string

Default value options: object= {}

Name Type
timeout? undefined | number

Returns: Promise‹boolean | undefined›


# dropCollection

dropCollection(collectionName: string, scopeName: string, options: object): Promise‹boolean | undefined›

dropCollection drops a collection from a scope in a bucket.

Parameters:

collectionName: string

scopeName: string

Default value options: object= {}

Name Type
timeout? undefined | number

Returns: Promise‹boolean | undefined›


# dropScope

dropScope(scopeName: string, options: object): Promise‹boolean | undefined›

dropScope drops a scope from a bucket.

Parameters:

scopeName: string

Default value options: object= {}

Name Type
timeout? undefined | number

Returns: Promise‹boolean | undefined›


# ensureCollections

ensureCollections(): Promise‹void›

ensureCollections will attempt to create scopes and collection to map your models into Couchbase Server.

Returns: Promise‹void›


# ensureIndexes

ensureIndexes(): Promise‹void›

ensureIndexes will attempt to create indexes defined in your schemas

Returns: Promise‹void›


# getCollection

getCollection(collectionName: string, scopeName: string): any

Return a collection from the given collectionName in this bucket Or default collection if collectionName is missing

Parameters:

Name Type Default
collectionName string DEFAULT_COLLECTION
scopeName string DEFAULT_SCOPE

Returns: any


# getModel

getModel(name: string): ModelTypes

Returns a Model constructor from the given name

example

const User = connection.getModel('User');

Parameters:

Name Type
name string

Returns: ModelTypes


# model

model(name: string, schema: Schema | Record‹string, unknown›, options: ModelOptions): ModelTypes

Creates a Model on this connection.

example

const User = connection.model('User', { name: String }, {collectionName: 'users'});

Parameters:

Name Type Default
name string -
schema Schema | Record‹string, unknown› -
options ModelOptions {}

Returns: ModelTypes


# query

query(query: string): Promise‹any›

Executes N1QL Queries.

Ottoman provides a powerful Query Builder system to create valid N1QL queries in a easier way. See the example below:

example

const expr_where = {$or: [{ address: { $like: '%57-59%' } }, { free_breakfast: true }]};
const query = new Query({}, 'travel-sample');
const n1qlQuery = query.select([{$field: 'address'}]).where(expr_where).build()

connection.query(n1qlQuery).then(result => console.log(result))

The above example will run this query:

SELECT address FROM travel-sample WHERE (address LIKE '%57-59%' OR free_breakfast = true)

Parameters:

Name Type
query string

Returns: Promise‹any›


# start

start(): Promise‹void›

start method is just a shortcut to run ensureCollections and ensureIndexes. Notice: It's not required to execute the start method to Ottoman work.

Returns: Promise‹void›