Class: Ottoman
Constructors
constructor
• new Ottoman(config?
)
Parameters
Name | Type |
---|---|
config | OttomanConfig |
Defined in
Properties
_cluster
• Private
Optional
_cluster: Cluster
Defined in
bucket
• Optional
bucket: Bucket
Bucket represents a storage grouping of data within a Couchbase Server cluster.
Defined in
bucketName
• bucketName: string
= ''
Contains the name of the current bucket.
Defined in
config
• config: OttomanConfig
Defined in
couchbase
• couchbase: any
Stores a reference to couchbase instance.
Defined in
events
• Private
events: Record
<"IndexOnline"
, NodeCallback
<Ottoman
>[]>
Defined in
id
• Private
Readonly
id: string
Defined in
indexOnline
• indexOnline: boolean
| Error
= false
Defined in
indexOnlinePromise
• indexOnlinePromise: undefined
| Promise
<any
>
Defined in
models
• models: Object
= {}
Dictionary for all models registered on this connection.
Defined in
n1qlIndexes
• Private
n1qlIndexes: Record
<string
, { fields
: string
[] ; modelName
: string
}> = {}
Defined in
refdocIndexes
• Private
refdocIndexes: Record
<string
, { fields
: string
[] }[]> = {}
Defined in
viewIndexes
• Private
viewIndexes: Record
<string
, { views
: { map?
: string
} }> = {}
Defined in
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
cluster
• get
cluster(): Cluster
Cluster represents an entire Couchbase Server cluster.
Returns
Cluster
Defined in
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
indexReadyHooks
• get
indexReadyHooks(): NodeCallback
<Ottoman
>[]
Retrieve all register callbacks to "IndexOnline" event
Returns
NodeCallback
<Ottoman
>[]
Defined in
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
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
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
Name | Type | Description |
---|---|---|
transactionFn | (attempt : TransactionAttemptContext ) => 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
>
Defined in
close
▸ close(): Promise
<void
>
Closes the current connection.
Example
connection.close().then(() => console.log('connection closed'));
Returns
Promise
<void
>
Defined in
connect
▸ connect(connectOptions
): Promise
<Ottoman
>
Connect to Couchbase server.
Example
import { connect } from "ottoman";
const connection = connect("couchbase://localhost/travel-sample@admin:password");
Parameters
Name | Type |
---|---|
connectOptions | string | ConnectOptions |
Returns
Promise
<Ottoman
>
Defined in
dropBucket
▸ dropBucket(bucketName
, options?
): Promise
<undefined
| boolean
| void
>
dropBucket drops a bucket from the cluster.
Parameters
Name | Type |
---|---|
bucketName | string |
options | DropBucketOptions |
Returns
Promise
<undefined
| boolean
| void
>
Defined in
dropCollection
▸ dropCollection(collectionName
, scopeName
, options?
): Promise
<undefined
| boolean
| void
>
dropCollection drops a collection from a scope in a bucket.
Parameters
Name | Type |
---|---|
collectionName | string |
scopeName | string |
options | DropCollectionOptions |
Returns
Promise
<undefined
| boolean
| void
>
Defined in
dropScope
▸ dropScope(scopeName
, options?
): Promise
<undefined
| boolean
| void
>
dropScope drops a scope from a bucket.
Parameters
Name | Type |
---|---|
scopeName | string |
options | DropScopeOptions |
Returns
Promise
<undefined
| boolean
| void
>
Defined in
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
ensureIndexes
▸ ensureIndexes(options?
): Promise
<any
>
ensureIndexes
will attempt to create indexes defined in your schema if they do not exist.
Parameters
Name | Type | Description |
---|---|---|
options | EnsureIndexesOptions | ignoreWatchIndexes : by default ensureIndexes function will wait for indexes, but you can disabled it setting ignoreWatchIndexes to true. |
Returns
Promise
<any
>
Defined in
getCollection
▸ getCollection(collectionName?
, scopeName?
): Collection
Return a collection from the given collectionName in this bucket or default collection if collectionName is missing.
Parameters
Name | Type | Default value |
---|---|---|
collectionName | string | DEFAULT_COLLECTION |
scopeName | string | DEFAULT_SCOPE |
Returns
Collection
Defined in
getIndexes
▸ getIndexes(): Promise
<SearchIndex
[]>
Returns
Promise
<SearchIndex
[]>
Defined in
getModel
▸ getModel<T
>(name
): ModelTypes
<T
, any
>
Returns a Model constructor from the given model name.
Example
const User = connection.getModel('User');
Type parameters
Name | Type |
---|---|
T | any |
Parameters
Name | Type |
---|---|
name | string |
Returns
ModelTypes
<T
, any
>
Defined in
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
Name | Type |
---|---|
T | any |
R | T |
Parameters
Name | Type |
---|---|
name | string |
schema | Schema | Record <string , unknown > |
options | ModelOptions |
Returns
ModelTypes
<T
, R
>
Defined in
on
▸ on(event
, fn
): void
Register Ottoman events
Parameters
Name | Type | Description |
---|---|---|
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
Defined in
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
Name | Type |
---|---|
query | string |
options | QueryOptions & { transactionContext? : TransactionAttemptContext } |
Returns
Promise
<TransactionQueryResult
<any
> | QueryResult
<any
>>
Defined in
searchQuery
▸ searchQuery(indexName
, query
, options?
): StreamableRowPromise
<SearchResult
, SearchRow
, SearchMetaData
>
Parameters
Name | Type |
---|---|
indexName | string |
query | SearchQuery |
options? | SearchQueryOptions |
Returns
StreamableRowPromise
<SearchResult
, SearchRow
, SearchMetaData
>
Defined in
start
▸ start(options?
): Promise
<void
>
start
method is just a shortcut to run ensureCollections
and ensureIndexes
.
Parameters
Name | Type | 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
>