# 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.

Check the Bucket Manager Couchbase SDK API (opens new window) documentation for more details.

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.

Check the Collection Manager Couchbase SDK API (opens new window) documentation for more details.

Returns: any


# queryIndexManager

get queryIndexManager(): any

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

Check the Query Index Manager Couchbase SDK API (opens new window) documentation for more details.

Returns: any


# viewIndexManager

get viewIndexManager(): any

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

Check the View Index Manager Couchbase SDK API (opens new window) documentation for more details.

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 collections to map your models to in Couchbase Server.

Returns: Promise‹void›


# ensureIndexes

ensureIndexes(): Promise‹void›

ensureIndexes will attempt to create indexes defined in your schema if they do not exist.

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

getModelT›(name: string): ModelTypes‹T›

Returns a Model constructor from the given model name.

example

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

Type parameters:

T

Parameters:

Name Type
name string

Returns: ModelTypes‹T›


# model

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

Creates a Model on this connection.

example

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

Type parameters:

T

Parameters:

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

Returns: ModelTypes‹T›


# query

query(query: string): Promise‹any›

Executes N1QL Queries.

Ottoman provides a powerful Query Builder system to create valid N1QL queries using method chaining. 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 in order for Ottoman work.

Returns: Promise‹void›