Skip to content
项目

关于

MySQL ORM tool

数据

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
正在收集历史
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

@axiosleo/orm-mysql

NPM version npm download node version License FOSSA Status

Installation

npm install @axiosleo/orm-mysql

Usage

const { createClient, QueryHandler } = require("@axiosleo/orm-mysql");

const conn = createClient({
  host: process.env.MYSQL_HOST,
  port: process.env.MYSQL_PORT,
  user: process.env.MYSQL_USER,
  password: process.env.MYSQL_PASS,
  database: process.env.MYSQL_DB,
});

const db = new QueryHandler(conn);

// SELECT
const users = await db.table("users")
  .where("age", ">", 18)
  .orderBy("name", "asc")
  .limit(10)
  .select("id", "name", "age");

// FIND single row
const user = await db.table("users").where("id", 1).find();

// INSERT
await db.table("users").insert({ name: "Joe", age: 18 });

// UPDATE
await db.table("users").where("id", 1).update({ name: "Joe", age: 19 });

// DELETE
await db.table("users").where("id", 1).delete();

// COUNT
const total = await db.table("users").where("age", ">", 18).count();

// TRANSACTION
const tx = await db.beginTransaction({ level: "RC" });
try {
  await tx.table("users").insert({ name: "Joe", age: 18 });
  await tx.commit();
} catch (e) {
  await tx.rollback();
  throw e;
}

For complete API documentation including where conditions, joins, hooks, migrations, and more, install the AI Skills for your coding assistant, or browse the skill files in skills/.

Migration

# Generate migration script
npx orm-mysql generate <name> [dir]

# Run migration
npx orm-mysql migrate up [dir] --host=localhost --port=3306 --user=root --pass=pwd --db=mydb

Migration examples

Run migrations from code with modules that are already loaded, e.g. when the migration files are bundled into a single executable and there is no directory to scan:

const { migrateModules } = require("@axiosleo/orm-mysql");

const modules = [
  // `filename` is what gets recorded in `migrate_logs`; keep the name the file has on disk
  // so the CLI and `migrateModules` recognize each other's work
  { filename: "1706764048.init.js", ...require("./migration/1706764048.init.js") },
];

const { executed, skipped } = await migrateModules("up", modules, {
  host: "localhost",
  port: 3306,
  user: "root",
  password: "pwd",
  database: "mydb",
});

up runs the modules in the given order, down in reverse order. Each call opens its own connection and closes it before returning, so several databases can be migrated one after another in the same process. It rejects with the original error when a migration fails; migrations before the failing one stay applied and recorded.

AI Skills

This project ships with AI Skills that teach AI coding assistants how to use this library correctly. You can install them with a single command:

# Cursor
npx @axiosleo/orm-mysql skills --install=cursor

# Claude Code
npx @axiosleo/orm-mysql skills --install=claude

# Windsurf
npx @axiosleo/orm-mysql skills --install=windsurf

The command detects the locally installed version of @axiosleo/orm-mysql in your node_modules/ and copies the matching skill files. If the package is not installed locally, it will use the bundled skills and remind you to run npm install @axiosleo/orm-mysql.

To uninstall:

npx @axiosleo/orm-mysql skills --uninstall=cursor
npx @axiosleo/orm-mysql skills --uninstall=claude
npx @axiosleo/orm-mysql skills --uninstall=windsurf

Skill Files

File Content
SKILL.md Setup, class hierarchy, quick start
query-building.md table, attr, join, orderBy, limit, groupBy
where-conditions.md where, whereIn, whereLike, whereBetween
crud-operations.md select, find, insert, update, delete, incrBy
transactions.md beginTransaction, isolation levels, row locking

Manual Installation

For other AI tools, copy the skill files from node_modules/@axiosleo/orm-mysql/skills/ into your tool's custom instructions directory:

cp -r node_modules/@axiosleo/orm-mysql/skills/ .your-tool/skills/orm-mysql-usage/

License

This project is open-sourced software licensed under MIT.

FOSSA Status

探索相关项目

加载中…