npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alemonjs/db

v0.0.17

Published

数据库连接

Readme

https://alemonjs.com/

提供 Redis 和 Sequelize 连接。

当前 SQL 方言支持:

  • pgsql
  • mysql
  • sqlite
import { getIoRedis, getSequelize } from '@alemonjs/db';

export const Redis = getIoRedis();
export const sequelize = getSequelize();

安装

yarn add @alemonjs/db -W

@alemonjs/db 不再内置 SQL 驱动。
如果你要使用 SQL 能力,需要按实际方言额外安装对应包:

# PostgreSQL
yarn add pg -W

# MySQL
yarn add mysql2 -W

# SQLite
yarn add sqlite3 -W

方言选择规则

1. 代码显式传入 dialect

const sequelize = getSequelize({
  dialect: 'pgsql'
});

优先级最高。

  • 如果对应驱动已安装,直接使用该方言
  • 如果对应驱动未安装,不会立即中断
  • 会打印 warn
  • 然后尝试回退到 sqlite
  • 如果 sqlite3 也未安装,则提示当前环境无法使用 SQL 能力

2. 配置文件显式写了 db.dialect

db:
  dialect: pgsql

语义与代码显式指定一致:

  • 缺驱动时打印 warn
  • 尝试回退到 sqlite
  • 如果 sqlite3 也不可用,则提示无法使用

3. 完全未指定 dialect

框架会自动探测:

  1. 已配置且可用的 pgsql
  2. 已配置且可用的 mysql
  3. sqlite

如果一个可用 SQL 驱动都没有,则提示安装:

  • pg
  • mysql2
  • sqlite3

配置示例

PostgreSQL

db:
  dialect: pgsql
  pgsql:
    host: '127.0.0.1'
    port: 5432
    user: 'postgres'
    password: 'Postgres123456!'
    database: 'alemonjs'
  redis:
    host: '127.0.0.1'
    port: 6379
    password: ''
    db: 0

MySQL

db:
  dialect: mysql
  mysql:
    host: '127.0.0.1'
    port: 3306
    user: 'root'
    password: 'Mysql123456!'
    database: 'alemonjs'

SQLite

db:
  dialect: sqlite
  sqlite:
    storage: './data/alemonapp.db'

使用示例

import { getSequelize } from '@alemonjs/db';

export const sequelize = getSequelize({
  dialect: 'pgsql'
});

如果你明确写了 dialect: 'pgsql',但没有安装 pg,框架会:

  1. 打印 warning
  2. 尝试使用 sqlite
  3. sqlite3 也未安装,则提示无法使用 SQL 能力

Redis 说明

Redis 仍然内置使用 ioredis,不需要额外安装驱动。