metronom / Modules / Model / default
Class: default
Model.default
Model Class
Indexable
▪ [index: string]: any
Table of contents
Properties
Constructors
Methods
Properties
keyPrefix
• keyPrefix: String
First part of redis key. It's identifier for model class
Defined in
keyUnique
• keyUnique: undefined | String
Second part of redis key. It's identifier for record
Defined in
schema
• schema: Schema
Object struct model
Defined in
redisClient
• redisClient: IRedisAdaptor
Defined in
flexSchema
• flexSchema: undefined | Boolean
you can't define any key except the fields in schema, but if this value is true, you can only add a value to the schema by giving it keyUnique
Defined in
Constructors
constructor
• new default(schema, keyPrefix?, modelOption?)
Represents a Metronom ORM Model
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
schema | Schema | undefined | Record's key-value schema |
keyPrefix | string | 'object' | Record unique key's prefix. "users:1234" --> "keyPrefix:keyUnique" |
modelOption? | ModelOptions | undefined | Optional model settings. It's include 3 key. + keyUnique: it's unique part of model key + flexSchema: Normally, you can't define any key except the fields in schema, but if this value is true, you can only add a value to the schema by giving it keyUnique + redisClientOptions: node-redis client options. |
Methods
create
▸ create(valueObject): Promise<default>
Creates ModelInstance by parameter then saves it to Redis and returns it
Parameters
| Name | Type | Description |
|---|---|---|
valueObject | Object | data to be saved according to the Model.schema |
Returns
Promise<default>
new ModelInstance
findById
▸ findById(id): Promise<null | default>
Fetches record by keyUnique
Parameters
| Name | Type | Description |
|---|---|---|
id | any | keyUnique |
Returns
Promise<null | default>
ModelInstance or null
getAll
▸ getAll(options?): Promise<[] | default[]>
Fetches all records with the same keyPrefix value
Parameters
| Name | Type |
|---|---|
options? | FilterOptions |
Returns
Promise<[] | default[]>
List of ModelInstance
filter
▸ filter(filterFunction): Promise<[] | default[]>
Filters in the same way as Array.filter, pulling all records with the same keyPrefix value
Parameters
| Name | Type | Description |
|---|---|---|
filterFunction | FilterFunction | It takes the values (value, index, array) and returns true then the record is filtered. It can be asynchronous function |
Returns
Promise<[] | default[]>
Filtred ModelInstances or empty array
deleteById
▸ deleteById(id): Promise<number>
delete record by keyUnique
Parameters
| Name | Type | Description |
|---|---|---|
id | any | keyUnique |
Returns
Promise<number>
deleted records count it always '1' if it succesfull
deleteAll
▸ deleteAll(options?): Promise<number>
Delete all records with the same keyPrefix value
Parameters
| Name | Type |
|---|---|
options? | any |
Returns
Promise<number>
deleted records count or 0
runCommand
▸ runCommand(commands): Promise<any>
Redis command executer
Example
runCommand(['hget', 'user:1234', 'name'])
Parameters
| Name | Type | Description |
|---|---|---|
commands | any | Redis command list. |
Returns
Promise<any>
metronom