Skip to main content

Class: Ottoman

Constructors

constructor

new Ottoman(config?)

Parameters

NameType
configOttomanConfig

Defined in

ottoman/ottoman.ts:223

Properties

_cluster

Private Optional _cluster: Cluster

Defined in

ottoman/ottoman.ts:204


bucket

Optional bucket: Bucket

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

Defined in

ottoman/ottoman.ts:152


bucketName

bucketName: string = ''

Contains the name of the current bucket.

Defined in

ottoman/ottoman.ts:216


config

config: OttomanConfig

Defined in

ottoman/ottoman.ts:147


couchbase

couchbase: any

Stores a reference to couchbase instance.

Defined in

ottoman/ottoman.ts:221


events

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

Defined in

ottoman/ottoman.ts:86


id

Private Readonly id: string

Defined in

ottoman/ottoman.ts:85


indexOnline

indexOnline: boolean | Error = false

Defined in

ottoman/ottoman.ts:89


indexOnlinePromise

indexOnlinePromise: undefined | Promise<any>

Defined in

ottoman/ottoman.ts:90


models

models: Object = {}

Dictionary for all models registered on this connection.

Defined in

ottoman/ottoman.ts:202


n1qlIndexes

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

Defined in

ottoman/ottoman.ts:82


refdocIndexes

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

Defined in

ottoman/ottoman.ts:84


viewIndexes

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

Defined in

ottoman/ottoman.ts:83

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:172


cluster

get cluster(): Cluster

Cluster represents an entire Couchbase Server cluster.

Returns

Cluster

Defined in

ottoman/ottoman.ts:209


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:161


indexReadyHooks

get indexReadyHooks(): NodeCallback<Ottoman>[]

Retrieve all register callbacks to "IndexOnline" event

Returns

NodeCallback<Ottoman>[]

Defined in

ottoman/ottoman.ts:95


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:183


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:195

Methods

$transactions

$transactions(transactionFn, config?): Promise<void>

The $transactions function passes a TransactionAttemptContext object to the transaction function.

Example

await otttoman.$transactions(async (ctx: TransactionAttemptContext) => {
const user = await User.create({ name: "John Doe" }, { transactionContext: ctx });
});

Notice: You MUST pass the transactionContext option in the model methods to execute the operation(s) as a transaction.

Parameters

NameTypeDescription
transactionFn(attempt: TransactionAttemptContext) => Promise<void>The function to be executed as a transaction.
config?TransactionOptionsdurabilityLevel: Specifies the level of synchronous durability level. - timeout: Specifies the timeout for the transaction.

Returns

Promise<void>

Defined in

ottoman/ottoman.ts:517


close

close(): Promise<void>

Closes the current connection.

Example

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

Returns

Promise<void>

Defined in

ottoman/ottoman.ts:379


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:244


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:329


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:299


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:316


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:427


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:479


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:353


getIndexes

getIndexes(): Promise<SearchIndex[]>

Returns

Promise<SearchIndex[]>

Defined in

ottoman/ottoman.ts:359


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:345


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:262


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:104


query

query(query, options?): Promise<TransactionQueryResult<any> | 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 & { transactionContext?: TransactionAttemptContext }

Returns

Promise<TransactionQueryResult<any> | QueryResult<any>>

Defined in

ottoman/ottoman.ts:417


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:363


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:495