Skip to main content

Class: Ottoman

Defined in: ottoman/ottoman.ts:81

Constructors​

Constructor​

new Ottoman(config): Ottoman

Defined in: ottoman/ottoman.ts:223

Parameters​

config​

OttomanConfig = {}

Returns​

Ottoman

Properties​

bucket?​

optional bucket: Bucket

Defined in: ottoman/ottoman.ts:152

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


bucketName​

bucketName: string = ''

Defined in: ottoman/ottoman.ts:216

Contains the name of the current bucket.


config​

config: OttomanConfig

Defined in: ottoman/ottoman.ts:147


couchbase​

couchbase: any

Defined in: ottoman/ottoman.ts:221

Stores a reference to couchbase instance.


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 = {}

Defined in: ottoman/ottoman.ts:202

Dictionary for all models registered on this connection.

Accessors​

bucketManager​

Get Signature​

get bucketManager(): BucketManager

Defined in: ottoman/ottoman.ts:172

Gets a bucket manager for this cluster.

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

Returns​

BucketManager


cluster​

Get Signature​

get cluster(): Cluster

Defined in: ottoman/ottoman.ts:209

Cluster represents an entire Couchbase Server cluster.

Returns​

Cluster


collectionManager​

Get Signature​

get collectionManager(): CollectionManager

Defined in: ottoman/ottoman.ts:161

CollectionManager allows the management of collections within a Bucket.

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

Returns​

CollectionManager


indexReadyHooks​

Get Signature​

get indexReadyHooks(): NodeCallback<Ottoman>[]

Defined in: ottoman/ottoman.ts:95

Retrieve all register callbacks to "IndexOnline" event

Returns​

NodeCallback<Ottoman>[]


queryIndexManager​

Get Signature​

get queryIndexManager(): QueryIndexManager

Defined in: ottoman/ottoman.ts:183

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


viewIndexManager​

Get Signature​

get viewIndexManager(): ViewIndexManager

Defined in: ottoman/ottoman.ts:195

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

Methods​

$transactions()​

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

Defined in: ottoman/ottoman.ts:517

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

Parameters​

transactionFn​

(attempt) => Promise<void>

The function to be executed as a transaction.

config?​

TransactionOptions

durabilityLevel: Specifies the level of synchronous durability level.

  • timeout: Specifies the timeout for the transaction.

Returns​

Promise<void>

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.


close()​

close(): Promise<void>

Defined in: ottoman/ottoman.ts:379

Closes the current connection.

Returns​

Promise<void>

Example​

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

connect()​

connect(connectOptions): Promise<Ottoman>

Defined in: ottoman/ottoman.ts:244

Connect to Couchbase server.

Parameters​

connectOptions​

string | ConnectOptions

Returns​

Promise<Ottoman>

Example​

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

dropBucket()​

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

Defined in: ottoman/ottoman.ts:329

dropBucket drops a bucket from the cluster.

Parameters​

bucketName​

string

options​

DropBucketOptions = {}

Returns​

Promise<undefined | boolean | void>


dropCollection()​

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

Defined in: ottoman/ottoman.ts:299

dropCollection drops a collection from a scope in a bucket.

Parameters​

collectionName​

string

scopeName​

string

options​

DropCollectionOptions = {}

Returns​

Promise<undefined | boolean | void>


dropScope()​

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

Defined in: ottoman/ottoman.ts:316

dropScope drops a scope from a bucket.

Parameters​

scopeName​

string

options​

DropScopeOptions = {}

Returns​

Promise<undefined | boolean | void>


ensureCollections()​

ensureCollections(): Promise<void>

Defined in: ottoman/ottoman.ts:427

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

Returns​

Promise<void>


ensureIndexes()​

ensureIndexes(options): Promise<any>

Defined in: ottoman/ottoman.ts:479

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

Parameters​

options​

EnsureIndexesOptions = {}

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

Returns​

Promise<any>


getCollection()​

getCollection(collectionName, scopeName): Collection

Defined in: ottoman/ottoman.ts:353

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

Parameters​

collectionName​

string = DEFAULT_COLLECTION

scopeName​

string = DEFAULT_SCOPE

Returns​

Collection


getIndexes()​

getIndexes(): Promise<SearchIndex[]>

Defined in: ottoman/ottoman.ts:359

Returns​

Promise<SearchIndex[]>


getModel()​

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

Defined in: ottoman/ottoman.ts:345

Returns a Model constructor from the given model name.

Type Parameters​

T​

T = any

Parameters​

name​

string

Returns​

ModelTypes<T>

Example​

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

model()​

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

Defined in: ottoman/ottoman.ts:262

Creates a Model on this connection.

Type Parameters​

T​

T = any

R​

R = T

Parameters​

name​

string

schema​

Schema | Record<string, unknown>

options​

ModelOptions = {}

Returns​

ModelTypes<T, R>

Example​

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

on()​

on(event, fn): void

Defined in: ottoman/ottoman.ts:104

Register Ottoman events

Parameters​

event​

"IndexOnline"

the name of the event you want to listen to.

fn​

NodeCallback<Ottoman>

callback function to be executed when the event trigger up.

Returns​

void


query()​

query(query, options): Promise<TransactionQueryResult<any> | QueryResult<any>>

Defined in: ottoman/ottoman.ts:417

Executes N1QL Queries.

Ottoman provides a powerful Query Builder system to create valid N1QL queries using method chaining. See the example below:

Parameters​

query​

string

options​

QueryOptions & object = {}

Returns​

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

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)

searchQuery()​

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

Defined in: ottoman/ottoman.ts:363

Parameters​

indexName​

string

query​

SearchQuery

options?​

SearchQueryOptions

Returns​

StreamableRowPromise<SearchResult, SearchRow, SearchMetaData>


start()​

start(options): Promise<void>

Defined in: ottoman/ottoman.ts:495

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

Parameters​

options​

StartOptions = {}

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