Skip to content

Latest commit

 

History

History
264 lines (156 loc) · 5.92 KB

Schema.md

File metadata and controls

264 lines (156 loc) · 5.92 KB

redis-om / Schema

Class: Schema<T>

Defines a schema that determines how an Entity is mapped to Redis data structures. Construct by passing in a schema name, a SchemaDefinition, and optionally SchemaOptions:

interface Foo extends Entity {
  aString: string,
  aNumber: number,
  aBoolean: boolean,
  someText: string,
  aPoint: Point,
  aDate: Date,
  someStrings: string[],
}

const schema = new Schema<Foo>('foo', {
  aString: { type: 'string' },
  aNumber: { type: 'number' },
  aBoolean: { type: 'boolean' },
  someText: { type: 'text' },
  aPoint: { type: 'point' },
  aDate: { type: 'date' },
  someStrings: { type: 'string[]' }
}, {
  dataStructure: 'HASH'
})

A Schema is primarily used by a Repository which requires a Schema in its constructor.

Type parameters

Name Type
T extends Entity = Record<string, any>

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

new Schema<T>(schemaName, schemaDef, options?)

Constructs a Schema.

Type parameters

Name Type
T extends Entity = Record<string, any>

Parameters

Name Type Description
schemaName string The name of the schema. Prefixes the ID when creating Redis keys.
schemaDef SchemaDefinition<T> Defines all of the fields for the Schema and how they are mapped to Redis.
options? SchemaOptions Additional options for this Schema.

Defined in

lib/schema/schema.ts:59

Accessors

dataStructure

get dataStructure(): DataStructure

The configured data structure, a string with the value of either HASH or JSON, that this Schema uses to store Entities in Redis.

Returns

DataStructure

Defined in

lib/schema/schema.ts:102


fields

get fields(): Field[]

The Fields defined by this Schema.

Returns

Field[]

Defined in

lib/schema/schema.ts:78


indexHash

get indexHash(): string

A hash for this Schema that is used to determine if the Schema has been changed when calling createIndex.

Returns

string

Defined in

lib/schema/schema.ts:130


indexHashName

get indexHashName(): string

The configured name for the RediSearch index hash for this Schema.

Returns

string

Defined in

lib/schema/schema.ts:96


indexName

get indexName(): string

The configured name for the RediSearch index for this Schema.

Returns

string

Defined in

lib/schema/schema.ts:93


schemaName

get schemaName(): string

The name of the schema. Prefixes the ID when creating Redis keys. Combined with the results of idStrategy to generate a key. If name is foo and idStrategy returns 12345 then the generated key would be foo:12345.

Returns

string

Defined in

lib/schema/schema.ts:73


stopWords

get stopWords(): string[]

The configured stop words. Ignored if useStopWords is anything other than CUSTOM.

Returns

string[]

Defined in

lib/schema/schema.ts:114


useStopWords

get useStopWords(): StopWordOptions

The configured usage of stop words, a string with the value of either OFF, DEFAULT, or CUSTOM. See SchemaOptions for more details.

Returns

StopWordOptions

Defined in

lib/schema/schema.ts:108

Methods

fieldByName

fieldByName(name): null | Field

Gets a single Field defined by this Schema.

Parameters

Name Type Description
name Exclude<keyof T, keyof EntityInternal> The name of the Field in this Schema.

Returns

null | Field

The Field, or null of not found.

Defined in

lib/schema/schema.ts:88


generateId

generateId(): Promise<string>

Generates a unique string using the configured IdStrategy.

Returns

Promise<string>

The generated id.

Defined in

lib/schema/schema.ts:121