# Class: Ottoman
# Hierarchy
- Ottoman
# Constructors
# constructor
+ new Ottoman(config
: OttomanConfig): Ottoman
Parameters:
Name | Type | Default |
---|---|---|
config | OttomanConfig | {} |
Returns: Ottoman
# Properties
# Optional
bucket
• bucket? : Bucket
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.
# indexOnline
• indexOnline: Error | boolean = false
# indexOnlinePromise
• indexOnlinePromise: Promise‹any› | undefined
# models
• models: object
Dictionary for all models registered on this connection.
# Type declaration:
# Accessors
# bucketManager
• get bucketManager(): BucketManager
Gets a bucket manager for this cluster.
Check the Bucket Manager Couchbase SDK API (opens new window) documentation for more details.
Returns: BucketManager
# cluster
• get cluster(): Cluster
Cluster represents an entire Couchbase Server cluster.
Returns: Cluster
# collectionManager
• get collectionManager(): CollectionManager
CollectionManager allows the management of collections within a Bucket.
Check the Collection Manager Couchbase SDK API (opens new window) documentation for more details.
Returns: CollectionManager
# indexReadyHooks
• get indexReadyHooks(): NodeCallback‹Ottoman‹››[]
Retrieve all register callbacks to "IndexOnline" event
Returns: NodeCallback‹Ottoman‹››[]
# queryIndexManager
• get queryIndexManager(): QueryIndexManager
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: QueryIndexManager
# 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 (opens new window)
documentation for more details.
Returns: ViewIndexManager
# Methods
# close
▸ close(): Promise‹void›
Closes the current connection.
example
connection.close().then(() => console.log('connection closed'));
Returns: Promise‹void›
# connect
▸ connect(connectOptions
: ConnectOptions | string): Promise‹Ottoman›
Connect to Couchbase server.
example
import { connect } from "ottoman";
const connection = connect("couchbase://localhost/travel-sample@admin:password");
2
Parameters:
Name | Type |
---|---|
connectOptions | ConnectOptions | string |
Returns: Promise‹Ottoman›
# dropBucket
▸ dropBucket(bucketName
: string, options
: DropBucketOptions): Promise‹boolean | undefined | void›
dropBucket drops a bucket from the cluster.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
bucketName | string | - | - |
options | DropBucketOptions | {} |
Returns: Promise‹boolean | undefined | void›
# dropCollection
▸ dropCollection(collectionName
: string, scopeName
: string, options
: DropCollectionOptions): Promise‹boolean | undefined | void›
dropCollection drops a collection from a scope in a bucket.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
collectionName | string | - | - |
scopeName | string | - | - |
options | DropCollectionOptions | {} |
Returns: Promise‹boolean | undefined | void›
# dropScope
▸ dropScope(scopeName
: string, options
: DropScopeOptions): Promise‹boolean | undefined | void›
dropScope drops a scope from a bucket.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
scopeName | string | - | - |
options | DropScopeOptions | {} |
Returns: Promise‹boolean | undefined | void›
# 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(options
: EnsureIndexesOptions): Promise‹any›
ensureIndexes
will attempt to create indexes defined in your schema if they do not exist.
- @param options
ignoreWatchIndexes
: by defaultensureIndexes
function will wait for indexes, but you can disabled it setting ignoreWatchIndexes to true.
Parameters:
Name | Type | Default |
---|---|---|
options | EnsureIndexesOptions | {} |
Returns: Promise‹any›
# getCollection
▸ getCollection(collectionName
: string, scopeName
: string): Collection
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: Collection
# getModel
▸ getModel‹T›(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
▸ model‹T, R›(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
▪ R
Parameters:
Name | Type | Default |
---|---|---|
name | string | - |
schema | Schema | Record‹string, unknown› | - |
options | ModelOptions | {} |
Returns: ModelTypes‹T›
# on
▸ on(event
: OttomanEvents, fn
: NodeCallback‹Ottoman›): void
Register Ottoman events
Parameters:
Name | Type | Description |
---|---|---|
event | OttomanEvents | 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
: string, options
: QueryOptions): 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 ))
2
3
4
5
6
7
8
9
10
11
12
The above example will run this query:
SELECT address
FROM `travel-sample`
WHERE (address LIKE '%57-59%' OR free_breakfast = true)
2
3
Parameters:
Name | Type | Default |
---|---|---|
query | string | - |
options | QueryOptions | {} |
Returns: Promise‹QueryResult‹any››
# start
▸ start(options
: StartOptions): Promise‹void›
start
method is just a shortcut to run ensureCollections
and ensureIndexes
.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
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›