Skip to main content

Class: Ottoman

Constructors

constructor

new Ottoman(config?)

Parameters

NameType
configOttomanConfig

Defined in

ottoman/ottoman.ts:221

Properties

_cluster

Private Optional _cluster: Cluster

Defined in

ottoman/ottoman.ts:202


bucket

Optional bucket: Bucket

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

Defined in

ottoman/ottoman.ts:150


bucketName

bucketName: string = ''

Contains the name of the current bucket.

Defined in

ottoman/ottoman.ts:214


config

config: OttomanConfig

Defined in

ottoman/ottoman.ts:145


couchbase

couchbase: any

Stores a reference to couchbase instance.

Defined in

ottoman/ottoman.ts:219


events

Private events: Record<"IndexOnline", NodeCallback<Ottoman>[]>

Defined in

ottoman/ottoman.ts:84


id

Private Readonly id: string

Defined in

ottoman/ottoman.ts:83


indexOnline

indexOnline: boolean | Error = false

Defined in

ottoman/ottoman.ts:87


indexOnlinePromise

indexOnlinePromise: undefined | Promise<any>

Defined in

ottoman/ottoman.ts:88


models

models: Object = {}

Dictionary for all models registered on this connection.

Defined in

ottoman/ottoman.ts:200


n1qlIndexes

Private n1qlIndexes: Record<string, { fields: string[] ; modelName: string }> = {}

Defined in

ottoman/ottoman.ts:80


refdocIndexes

Private refdocIndexes: Record<string, { fields: string[] }[]> = {}

Defined in

ottoman/ottoman.ts:82


viewIndexes

Private viewIndexes: Record<string, { views: { map?: string } }> = {}

Defined in

ottoman/ottoman.ts:81

Accessors

bucketManager

get bucketManager(): BucketManager

Gets a bucket manager for this cluster.

Check the Bucket Manager Couchbase SDK API documentation for more details.

Returns

BucketManager

Defined in

ottoman/ottoman.ts:170


cluster

get cluster(): Cluster

Cluster represents an entire Couchbase Server cluster.

Returns

Cluster

Defined in

ottoman/ottoman.ts:207


collectionManager

get collectionManager(): CollectionManager

CollectionManager allows the management of collections within a Bucket.

Check the Collection Manager Couchbase SDK API documentation for more details.

Returns

CollectionManager

Defined in

ottoman/ottoman.ts:159


indexReadyHooks

get indexReadyHooks(): NodeCallback<Ottoman>[]

Retrieve all register callbacks to "IndexOnline" event

Returns

NodeCallback<Ottoman>[]

Defined in

ottoman/ottoman.ts:93


queryIndexManager

get queryIndexManager(): QueryIndexManager

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

Check the Query Index Manager Couchbase SDK API documentation for more details.

Returns

QueryIndexManager

Defined in

ottoman/ottoman.ts:181


viewIndexManager

get viewIndexManager(): ViewIndexManager

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

Deprecated

Check the View Index Manager Couchbase SDK API documentation for more details.

Returns

ViewIndexManager

Defined in

ottoman/ottoman.ts:193

Methods

close

close(): Promise<void>

Closes the current connection.

Example

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

Returns

Promise<void>

Defined in

ottoman/ottoman.ts:377


connect

connect(connectOptions): Promise<Ottoman>

Connect to Couchbase server.

Example

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

Parameters

NameType
connectOptionsstring | ConnectOptions

Returns

Promise<Ottoman>

Defined in

ottoman/ottoman.ts:242


dropBucket

dropBucket(bucketName, options?): Promise<undefined | boolean | void>

dropBucket drops a bucket from the cluster.

Parameters

NameType
bucketNamestring
optionsDropBucketOptions

Returns

Promise<undefined | boolean | void>

Defined in

ottoman/ottoman.ts:327


dropCollection

dropCollection(collectionName, scopeName, options?): Promise<undefined | boolean | void>

dropCollection drops a collection from a scope in a bucket.

Parameters

NameType
collectionNamestring
scopeNamestring
optionsDropCollectionOptions

Returns

Promise<undefined | boolean | void>

Defined in

ottoman/ottoman.ts:297


dropScope

dropScope(scopeName, options?): Promise<undefined | boolean | void>

dropScope drops a scope from a bucket.

Parameters

NameType
scopeNamestring
optionsDropScopeOptions

Returns

Promise<undefined | boolean | void>

Defined in

ottoman/ottoman.ts:314


ensureCollections

ensureCollections(): Promise<void>

ensureCollections will attempt to create scopes and collections to map your models to in Couchbase Server.

Returns

Promise<void>

Defined in

ottoman/ottoman.ts:422


ensureIndexes

ensureIndexes(options?): Promise<any>

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

Parameters

NameTypeDescription
optionsEnsureIndexesOptionsignoreWatchIndexes: by default ensureIndexes function will wait for indexes, but you can disabled it setting ignoreWatchIndexes to true.

Returns

Promise<any>

Defined in

ottoman/ottoman.ts:474


getCollection

getCollection(collectionName?, scopeName?): Collection

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

Parameters

NameTypeDefault value
collectionNamestringDEFAULT_COLLECTION
scopeNamestringDEFAULT_SCOPE

Returns

Collection

Defined in

ottoman/ottoman.ts:351


getIndexes

getIndexes(): Promise<SearchIndex[]>

Returns

Promise<SearchIndex[]>

Defined in

ottoman/ottoman.ts:357


getModel

getModel<T>(name): ModelTypes<T, any>

Returns a Model constructor from the given model name.

Example

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

Type parameters

NameType
Tany

Parameters

NameType
namestring

Returns

ModelTypes<T, any>

Defined in

ottoman/ottoman.ts:343


model

model<T, R>(name, schema, options?): ModelTypes<T, R>

Creates a Model on this connection.

Example

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

Type parameters

NameType
Tany
RT

Parameters

NameType
namestring
schemaSchema | Record<string, unknown>
optionsModelOptions

Returns

ModelTypes<T, R>

Defined in

ottoman/ottoman.ts:260


on

on(event, fn): void

Register Ottoman events

Parameters

NameTypeDescription
event"IndexOnline"the name of the event you want to listen to.
fnNodeCallback<Ottoman>callback function to be executed when the event trigger up.

Returns

void

Defined in

ottoman/ottoman.ts:102


query

query(query, options?): Promise<QueryResult<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

NameType
querystring
optionsQueryOptions

Returns

Promise<QueryResult<any>>

Defined in

ottoman/ottoman.ts:415


searchQuery

searchQuery(indexName, query, options?): StreamableRowPromise<SearchResult, SearchRow, SearchMetaData>

Parameters

NameType
indexNamestring
querySearchQuery
options?SearchQueryOptions

Returns

StreamableRowPromise<SearchResult, SearchRow, SearchMetaData>

Defined in

ottoman/ottoman.ts:361


start

start(options?): Promise<void>

start method is just a shortcut to run ensureCollections and ensureIndexes.

Parameters

NameTypeDescription
optionsStartOptionsignoreWatchIndexes: by default start function will wait for indexes, but you can disabled it setting ignoreWatchIndexes to true. Notice: It's not required to execute the start method in order for Ottoman work.

Returns

Promise<void>

Defined in

ottoman/ottoman.ts:490