@elysiumjs/mnemosyne

中文文档
0.8.1发布于 2026/11/12Apache-2.0TypeScriptES Module近 30 天下载 3741

Database and caching for Elysium.js applications

此软件包已被标记为弃用

has moved into @elysiumjs/olympus: import from @elysiumjs/olympus/mnemosyne; the Redis cache store is in @elysiumjs/redis.

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Seeders
  4. Listings
  5. License

@elysiumjs/mnemosyne

Database abstractions and caching for Elysium.js applications.

Installation

bun add @elysiumjs/mnemosyne

Usage

MnemosyneModule provides the caches (Cache.redis and Cache.memory) and the db:seed command. Database driver modules such as DrizzleModule from @elysiumjs/mnemosyne-drizzle import it for you, so you only add it yourself when you want to configure the caches or use them without a database:

import { Application, RedisModule } from '@elysiumjs/core';
import { MnemosyneModule } from '@elysiumjs/mnemosyne';

@Application.register({
    modules: [
        RedisModule.with({
            default: 'cache',
            connections: { cache: { url: process.env.REDIS_URL! } }
        }),
        // Opt out of a cache with `redis: false` or `memory: false`.
        MnemosyneModule.with({ cache: { memory: { ttl: 60_000, lruSize: 5000 } } })
    ]
})
export class App extends Application {}

Any Keyv store can back a cache of its own with stores, read with Cache.store(name). On Cloudflare Workers, KeyvWorkersKV from @elysiumjs/runtime-workers stores entries in a KV namespace:

import { KeyvWorkersKV } from '@elysiumjs/runtime-workers';

MnemosyneModule.with({
    cache: { redis: false, stores: { kv: () => new KeyvWorkersKV({ binding: 'CACHE' }) } }
});

await Cache.store('kv').set('greeting', 'hello', 120_000);

Seeders

A seeder writes the rows an application needs to run, such as reference data. List it in the seeders of a module, and styx db:seed runs it inside that module, so its run method takes the module's services, in a transaction of its own:

import { Service } from '@elysiumjs/core';
import { Seeder } from '@elysiumjs/mnemosyne';

@Seeder.register()
export class CountriesSeeder extends Seeder {
    protected async run(@Service.inject() countries: CountryRepository): Promise<void> {
        await countries.upsertMany(await readCountries());
    }
}

@Seeder.register({ after: [CountriesSeeder], manual: true })
export class CitiesSeeder extends Seeder {
    protected async run(@Service.inject() cities: CityRepository): Promise<void> {
        await cities.upsertMany(await readCities(this.input.file));
    }
}

@Module.register({ services: [CountryRepository, CityRepository], seeders: [CountriesSeeder, CitiesSeeder] })
export class GeoModule extends Module {}
styx db:seed                                  # every seeder that is not manual
styx db:seed --only geo.cities --file cities.zip
styx db:seed --arg region=africa --list       # prints the order, runs nothing
  • Seeders run on every call, so write them as upserts.
  • A seeder is named after its module and class, without the Module and Seeder suffixes, in kebab case (geo.cities above). name sets another one.
  • after lists the seeder classes that run first when both run. It sets an order and does not add them: --only geo.cities runs geo.cities alone. Give a function, after: () => [CountriesSeeder], when an import cycle leaves the class undefined.
  • manual: true seeders run only when --only names them. env limits a seeder to some environments, and connection picks the connection of its transaction.
  • --file and the --arg key=value pairs reach the seeders as this.input.file and this.input.args.
  • styx make:seeder --name CountriesSeeder --module geo writes seeders/countries.seeder.ts.

Listings

Listing.define() says what clients may filter and sort a listing by, and how it pages. Listing.parse() validates the query string, and a repository's list() runs it:

import { Listing } from '@elysiumjs/mnemosyne';

const PostListing = Listing.define(Post, {
    filters: { status: ['eq', 'in'], title: ['contains'] },
    sort: ['createdAt', 'title'],
    defaultSort: '-createdAt'
});

@Http.get('/', { response: Listing.pageSchema(PostResource) })
public list(@Http.query(Listing.schema(PostListing)) query: Listing.Params<typeof PostListing>) {
    return this.posts.list(Listing.parse(PostListing, query));
}
  • Cursor pagination is the default: cursor points after the last row of the previous page, and a page gives { data, nextCursor }. Pages stay stable while rows are added, and each costs the same.
  • pagination: 'offset' numbers the pages from 1 with page, and a page gives { data, page, limit, total }, the total counting the rows the filters match. It suits tables that jump to a page.
  • Listing.pageSchema(item) and Listing.offsetPageSchema(item) describe the pages. Listing.page() and Listing.offsetPage() build them, Listing.mapPage(page, map) maps their rows, such as models to resources, and Listing.filterPage(page, keep) keeps the rows that pass a predicate.
  • Pages and their schemas are marked, so that an interceptor can render them on its own: Listing.isPage(value) and Listing.paginationOf(page) read a page, Listing.pageSchemaPagination(schema) and Listing.itemSchemaOf(schema) read a page schema.

Models and repositories are built with a driver package. See @elysiumjs/mnemosyne-drizzle.

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for more info.

版本与发布记录

@elysiumjs/mnemosyne 共发布 20 个版本,首次发布于 2026/02/24;过去 12 个月发布了 20 个版本。

版本发布日期距今
0.8.1latest2026/11/121 天前
0.8.02026/11/121 天前
0.7.32026/11/112 天前
0.7.22026/11/112 天前
0.7.12026/11/112 天前
0.7.02026/11/103 天前

关于 @elysiumjs/mnemosyne 的常见问题

@elysiumjs/mnemosyne 是什么?

Database and caching for Elysium.js applications注意:该包已被作者标记为弃用——has moved into @elysiumjs/olympus: import from @elysiumjs/olympus/mnemosyne; the Redis cache store is in @elysiumjs/redis.

如何安装 @elysiumjs/mnemosyne?

在项目目录运行 npm install @elysiumjs/mnemosyne,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@elysiumjs/core(^0.24.0)、@elysiumjs/redis(^0.1.13)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@elysiumjs/mnemosyne 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elysiumjs/mnemosyne 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@elysiumjs/mnemosyne 可以商用吗?

@elysiumjs/mnemosyne 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@elysiumjs/mnemosyne 的下载量有多少?

根据 npm 官方下载统计,@elysiumjs/mnemosyne 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,741 次,日均约 125 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elysiumjs/mnemosyne 还在维护吗?

最新版本 0.8.1 发布于 2026/11/12(1 天前);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/02/24。作者已将其标记为弃用,新项目建议寻找替代方案。