🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@alemonjs/db

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alemonjs/db

数据库连接

latest
Source
npmnpm
Version
0.0.17
Version published
Weekly downloads
141
127.42%
Maintainers
2
Weekly downloads
 
Created
Source

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

框架会自动探测:

  • 已配置且可用的 pgsql
  • 已配置且可用的 mysql
  • 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,框架会:

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

Redis 说明

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

Keywords

alemonjs

FAQs

Package last updated on 15 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts