Skip to content

NeoLaner/redis-om-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-om-types

License: MIT

TypeScript type definitions and utilities for Redis OM (Object Mapping), providing type-safe interactions with Redis.

Features

  • Type-safe schema definitions
  • Automatic type inference for Redis entities

Installation

npm install redis-om-types --save-dev

Usage

Import the ExtendedSchemaDefinition, RedisInferSchema types and use it in your TypeScript project:

import { ExtendedSchemaDefinition, RedisInferSchema } from "redis-om-types";
import { getRedisClient } from "@/lib/db";
import { Repository, Schema } from "redis-om";

const redis = await getRedisClient();

const artistsSchemaDefinition = {
  id: { type: "string" },
  name: { type: "text", sortable: true },
  age: { type: "number" },
  city: { type: "text" },
  services: {
    type: "string[]",
    isArray: true,
    path: "artists.services[*]",
    properties: {
      id: { type: "string" },
      name: { type: "text" },
      price: { type: "number" },
      category_id: { type: "string" },
      options: {
        type: "string[]",
        isArray: true,
        properties: {
          name: { type: "text" },
          price: { type: "number" },
        },
      },
    },
  },
} as const satisfies ExtendedSchemaDefinition;

export const artistsSchema = new Schema<
  RedisInferSchema<typeof artistsSchemaDefinition>
>("models.Artists", artistsSchemaDefinition);

export const artistsRepository = new Repository(artistsSchema, redis);
export async function getArtists() {
  const artists = await artistsRepository.search().return.all();
  console.log(artists[0]?.services[0]?.options[0]); // {name , value};
  return artists;
}

isArray and properties added in ExtendedSchemaDefinition

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Projects

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published