ottoman
Enumerations
Classes
- ArrayType
- BooleanType
- BuildSchemaError
- CoreType
- DateType
- Document
- EmbedType
- FindByIdOptions
- FindOptions
- IOttomanType
- IndexParamsOnExceptions
- IndexParamsUsingGSIExceptions
- ManyQueryResponse
- MixedType
- Model
- MultipleQueryTypesException
- NumberType
- Ottoman
- Query
- QueryGroupByParamsException
- QueryOperatorNotFoundException
- ReferenceType
- Schema
- SelectClauseException
- StringType
- ValidationError
- ViewIndexOptions
- WhereClauseException
Interfaces
- CreateModelOptions
- FindOneAndUpdateOption
- IConditionExpr
- IField
- IIndexOnParams
- IIndexWithParams
- IManyQueryResponse
- IModel
- IStatusExecution
- ModelOptions
- UpdateManyOptions
- ValidatorOption
- saveOptions
Type Aliases
AggType
Ƭ AggType: "$arrayAgg"
| "$avg"
| "$mean"
| "$count"
| "$countn"
| "$max"
| "$median"
| "$min"
| "$stddev"
| "$stddevPop"
| "$stddevSamp"
| "$sum"
| "$variance"
| "$variancePop"
| "$varianceSamp"
| "$varPop"
| "$varSamp"
List of aggregation functions.
Defined in
query/interface/query.types.ts:13
ComparisonEmptyOperatorType
Ƭ ComparisonEmptyOperatorType: "$isNull"
| "$isNotNull"
| "$isMissing"
| "$isNotMissing"
| "$isValued"
| "$isNotValued"
List of Boolean comparison operators.
Defined in
query/interface/query.types.ts:35
ComparisonMultipleOperatorType
Ƭ ComparisonMultipleOperatorType: "$btw"
| "$notBtw"
List of Range comparison operators.
Defined in
query/interface/query.types.ts:53
ComparisonSingleOperatorType
Ƭ ComparisonSingleOperatorType: "$eq"
| "$neq"
| "$gt"
| "$gte"
| "$lt"
| "$lte"
List of Numeric comparison operators.
Defined in
query/interface/query.types.ts:45
ComparisonSingleStringOperatorType
Ƭ ComparisonSingleStringOperatorType: "$like"
| "$notLike"
List of String comparison operators.
Defined in
query/interface/query.types.ts:49
ComparisonWhereExpr
Ƭ ComparisonWhereExpr: { [key in ComparisonEmptyOperatorType | ComparisonSingleOperatorType | ComparisonMultipleOperatorType | ComparisonSingleStringOperatorType]?: string | number | boolean | (number | string)[] } | { [key in CollectionDeepSearchOperatorType]?: string | any[] }
Structure of the comparison operators.
Example
{ operator: value } -> e.g { $like: '%ottoman%' }
Defined in
query/interface/query.types.ts:129
IDocument
Ƭ IDocument<T
>: CleanDocument
& T
Type parameters
Name | Type |
---|---|
T | any |
Defined in
ISelectAggType
Ƭ ISelectAggType: { [key in AggType]?: ISelectFieldType }
SELECT aggregation expression
Example
{ $count: { $field: { name: 'address' }, as: 'addr' } } | { $count: { $field: 'address' } }
Defined in
query/interface/query.types.ts:194
ISelectType
Ƭ ISelectType: ISelectReturnResultType
| ISelectResultExprType
| ISelectAggType
| ISelectFieldType
SELECT expression
Example
{ $all: { $field: { name: 'address' }, as: 'addr' }, $field: 'type', $field: { name: 'count' } }
Defined in
query/interface/query.types.ts:246
IndexType
Ƭ IndexType: "CREATE"
| "BUILD"
| "DROP"
| "CREATE PRIMARY"
Types of supported index statements
Defined in
query/interface/query.types.ts:277
LetExprType
Ƭ LetExprType: Record
<string
, unknown
>
LET expression
Defined in
query/interface/query.types.ts:251
LogicalOperatorType
Ƭ LogicalOperatorType: "$and"
| "$or"
| "$not"
List of Logical operators.
Defined in
query/interface/query.types.ts:58
LogicalWhereExpr
Ƭ LogicalWhereExpr<T
>: CollectionRangePredicateType
| { [key in LogicalOperatorType]?: (FieldWhereExpr<T> | CollectionRangePredicateType)[] } | FieldWhereExpr
<T
>
Structure of Logical WHERE expression
Example
{ field: { operator: value } } -> e.g { $or: [{ address: { $like: '%ottoman%' } }] }
Type parameters
Name | Type |
---|---|
T | any |
Defined in
query/interface/query.types.ts:164
ModelTypes
Ƭ ModelTypes<T
, R
>: WhateverTypes
& IModel
<T
, R
> & (data
: T
, options?
: CastOptions
) => IDocument
<T
>
Type parameters
Name | Type |
---|---|
T | any |
R | any |
Defined in
MutationFunctionOptions
Ƭ MutationFunctionOptions: Object
Desc
Used by the mutation functions to apply the defined strategy.
Type declaration
Name | Type |
---|---|
enforceRefCheck? | boolean | "throw" |
maxExpiry? | number |
strict? | ApplyStrategy |
transactionContext? | TransactionAttemptContext |
Defined in
ResultExprType
Ƭ ResultExprType: "$raw"
| "$element"
| "$value"
Result expressions of RAW | ELEMENT | VALUE type.
Defined in
query/interface/query.types.ts:9
ReturnResultType
Ƭ ReturnResultType: "$all"
| "$distinct"
Result expressions of ALL | DISTINCT type.
Defined in
query/interface/query.types.ts:5
SortType
Ƭ SortType: "ASC"
| "DESC"
Defined in
query/interface/query.types.ts:1
Variables
AggDict
• Const
AggDict: Record
<AggType
, string
>
Dictionary for handling aggregation functions.
Defined in
query/helpers/dictionary.ts:18
ResultExprDict
• Const
ResultExprDict: Record
<ResultExprType
, string
>
Dictionary for handling result expressions of RAW | ELEMENT | VALUE type.
Defined in
query/helpers/dictionary.ts:41
ReturnResultDict
• Const
ReturnResultDict: Record
<ReturnResultType
, string
>
Dictionary for handling result expressions of ALL | DISTINCT type.
Defined in
query/helpers/dictionary.ts:46
Functions
addValidators
▸ addValidators(validators
): void
Register custom validators to Schema validators register.
Function
Throws
Error
Example
addValidators({
email: (value) => {
regexp = new RegExp(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
if (!regexp.test(value)) {
throw new Error('Email address is invalid.')
}
}
});
const ContactSchema = new Schema({
name: String,
contact: { type: String, validator: 'email' }
});
Parameters
Name | Type |
---|---|
validators | CustomValidations |
Returns
void
Defined in
schema/helpers/fn-schema.ts:240
applyDefaultValue
▸ applyDefaultValue(obj
, schema
): any
Apply default values defined on schema to an object instance.
Example
const schema = { name: { type: String, default: 'John' }, hasChild: { type: Boolean, default: true } };
const obj: any = applyDefaultValue(obj, schema)
console.log(obj);
Parameters
Name | Type | Description |
---|---|---|
obj | any | reference to object instance |
schema | Schema | SchemaDef | definition will be used to determine default definitions |
Returns
any
Defined in
schema/helpers/fn-schema.ts:196
buildIndexExpr
▸ buildIndexExpr(collection
, type
, name
, on?
, where?
, usingGSI?
, withExpr?
): string
Build a INDEX N1QL query from user-specified parameters. https://docs.couchbase.com/server/6.5/n1ql/n1ql-language-reference/createindex.html
Parameters
Name | Type | Description |
---|---|---|
collection | string | Collection name |
type | IndexType | INDEX clause types ('CREATE' | 'BUILD' | 'DROP' | 'CREATE PRIMARY') |
name | string | - |
on? | IIndexOnParams [] | ON Clause |
where? | LogicalWhereExpr <any > | WHERE Clause |
usingGSI? | boolean | use a Global Secondary Index (GSI) |
withExpr? | IIndexWithParams | WITH Clause |
Returns
string
N1QL INDEX Query
Defined in
buildSelectExpr
▸ buildSelectExpr(n1ql
, clause
): string
Recursive function to create N1QL queries.
Parameters
Name | Type | Description |
---|---|---|
n1ql | string | N1QL Query String |
clause | ISelectType | SELECT Clause |
Returns
string
N1QL SELECT Query
Defined in
buildWhereClauseExpr
▸ buildWhereClauseExpr(n1ql
, clause
, ignoreCase?
): string
Recursive function to create WHERE N1QL expressions.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
n1ql | string | undefined | N1QL Query String |
clause | LogicalWhereExpr <any > | undefined | WHERE Clause param |
ignoreCase | boolean | false | Apply ignoreCase |
Returns
string
N1QL WHERE expression
Defined in
close
▸ close(): Promise
<void
>
Returns
Promise
<void
>
Defined in
connect
▸ connect(connectOptions
): Promise
<void
>
Parameters
Name | Type |
---|---|
connectOptions | string | ConnectOptions |
Returns
Promise
<void
>
Defined in
getCollection
▸ getCollection(collectionName?
, scopeName?
): Collection
Parameters
Name | Type | Default value |
---|---|---|
collectionName | string | DEFAULT_COLLECTION |
scopeName | string | DEFAULT_SCOPE |
Returns
Collection
Defined in
getDefaultInstance
▸ getDefaultInstance(): Ottoman
Returns
Defined in
getModel
▸ getModel(name
): ModelTypes
<any
, any
>
Parameters
Name | Type |
---|---|
name | string |
Returns
ModelTypes
<any
, any
>
Defined in
getModelMetadata
▸ getModelMetadata(modelConstructor
): ModelMetadata
Parameters
Name | Type |
---|---|
modelConstructor | any |
Returns
ModelMetadata
Defined in
getOttomanInstances
▸ getOttomanInstances(): Ottoman
[]
Returns
Ottoman
[]
Defined in
getProjectionFields
▸ getProjectionFields(selectDot
, select?
, options?
, modelKey?
): Object
Parameters
Name | Type | Default value |
---|---|---|
selectDot | string | undefined |
select | string | string [] | ISelectType [] | '' |
options | Object | {} |
options.noCollection? | boolean | undefined |
modelKey | string | MODEL_KEY |
Returns
Object
Name | Type |
---|---|
fields | string [] |
projection | string |
Defined in
utils/query/extract-select.ts:23
getValueByPath
▸ getValueByPath<T
>(obj
, path
): any
Type parameters
Name | Type |
---|---|
T | Record <string , any > |
Parameters
Name | Type |
---|---|
obj | T |
path | string |
Returns
any
Defined in
is
▸ is(val
, type
): boolean
Checking if a value is a specific type or constructor
Parameters
Name | Type |
---|---|
val | any |
type | any |
Returns
boolean
Defined in
isDocumentNotFoundError
▸ isDocumentNotFoundError(exception
): boolean
Return a boolean value if an exception is DocumentNotFoundError.
Parameters
Name | Type |
---|---|
exception | any |
Returns
boolean
Defined in
isSchemaFactoryType
▸ isSchemaFactoryType(value
, factory
): boolean
Checking if a value is a factory supported by Ottoman.
Parameters
Name | Type | Description |
---|---|---|
value | any | |
factory | any | List of Schema Factories |
Returns
boolean
Defined in
isSchemaTypeSupported
▸ isSchemaTypeSupported(val
): boolean
Checking if a value is a type supported by Ottoman.
Parameters
Name | Type |
---|---|
val | any |
Returns
boolean
Defined in
model
▸ model<T
, R
>(name
, schema
, options?
): ModelTypes
<T
, R
>
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
parseStringSelectExpr
▸ parseStringSelectExpr(expr
): string
[]
Convert select expression into an Array of selection keys
Parameters
Name | Type |
---|---|
expr | string |
Returns
string
[]
Defined in
registerGlobalPlugin
▸ registerGlobalPlugin(...plugins
): void
Register a global plugin.
Parameters
Name | Type |
---|---|
...plugins | any [] |
Returns
void
Defined in
plugins/global-plugin-handler.ts:13
registerType
▸ registerType(name
, factory
): void
Register a custom type to Schema supported types.
Function
Throws
Error
Example
registerType(Int8.name, (fieldName, opts) => new Int8(fieldName, opts.required));
Parameters
Name | Type |
---|---|
name | string |
factory | FactoryFunction |
Returns
void
Defined in
schema/helpers/fn-schema.ts:211
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
selectBuilder
▸ selectBuilder(collection
, select
, letExpr?
, where?
, orderBy?
, limit?
, offset?
, useExpr?
, groupByExpr?
, lettingExpr?
, havingExpr?
, plainJoinExpr?
, ignoreCase?
): string
Build a SELECT N1QL query from user-specified parameters. https://docs.couchbase.com/server/6.5/n1ql/n1ql-language-reference/select-syntax.html
Parameters
Name | Type | Description |
---|---|---|
collection | string | Collection name |
select | string | ISelectType [] | SELECT Clause |
letExpr? | LetExprType | LET Clause |
where? | LogicalWhereExpr <any > | WHERE Clause |
orderBy? | Record <string , SortType > | ORDER BY Clause |
limit? | number | LIMIT Clause |
offset? | number | OFFSET Clause |
useExpr? | string [] | USE Clause |
groupByExpr? | IGroupBy [] | GROUP BY Clause |
lettingExpr? | LetExprType | LETTING Clause |
havingExpr? | LogicalWhereExpr <any > | HAVING Clause |
plainJoinExpr? | string | PLAIN JOIN string definition |
ignoreCase? | boolean | boolean to ignore case |
Returns
string
N1QL SELECT Query
Defined in
set
▸ set(key
, value
): void
Parameters
Name | Type |
---|---|
key | string |
value | string | number | boolean |
Returns
void
Defined in
setValueByPath
▸ setValueByPath<T
>(object
, path
, value
): void
Type parameters
Name | Type |
---|---|
T | Record <string , any > |
Parameters
Name | Type |
---|---|
object | T |
path | string |
value | any |
Returns
void
Defined in
start
▸ start(): Promise
<void
>
Returns
Promise
<void
>
Defined in
validate
▸ validate(data
, schema
, options?
): any
Validate data using the schema definition.
Throws
BuildSchemaError, ValidationError
Example
const data = {
name: "John",
age: "50"
};
const schema = new Schema({
name: String,
age: {type: Number, intVal: true}
});
const strictSchema = new Schema({
name: String,
age: {type: Number, intVal: true}
},
{
validationStrategy: VALIDATION_STRATEGY.STRICT
});
console.log(castSchema(data, schema)); // Print { name: "John", age: 50 }
console.log(castSchema(data, strictSchema)); // Throw "Property age must be of type Number"
Parameters
Name | Type | Description |
---|---|---|
data | any | that is going to be validated |
schema | Schema | SchemaDef | that will be used to validate |
options | CastOptions |
Returns
any