@drizzle-adapter/mysql-core

中文文档
1.1.2发布于 2026/09/25MITTypeScriptES Module近 30 天下载 3.3万
原始使用文档
文档目录10 节
  1. Overview
  2. Purpose
  3. Installation
  4. For Adapter Developers
  5. Data Types
  6. Error Handling
  7. Query Building
  8. Type Mapping
  9. Contributing
  10. Related Packages

@drizzle-adapter/mysql-core

Shared MySQL functionality for the Drizzle Adapter ecosystem.

Overview

The @drizzle-adapter/mysql-core package provides shared MySQL functionality used by MySQL-compatible adapters in the Drizzle Adapter ecosystem. This package is an internal dependency used by:

Purpose

This package standardizes MySQL-specific functionality across different MySQL-compatible adapters:

  • Common MySQL data type definitions
  • Shared MySQL query building logic
  • Unified MySQL error handling
  • Common MySQL utility functions

Installation

# This package is typically not installed directly but as a dependency of MySQL adapters
pnpm install @drizzle-adapter/mysql-core

For Adapter Developers

If you're developing a new MySQL-compatible adapter for the Drizzle Adapter ecosystem, you should use this package to ensure consistency with other MySQL adapters:

import { MySQLDrizzleDataTypes } from '@drizzle-adapter/mysql-core';

export class YourMySQLAdapter implements DrizzleAdapterInterface {
  public getDataTypes(): MySQLDrizzleDataTypes {
    return new MySQLDrizzleDataTypes();
  }
  
  // ... rest of your adapter implementation
}

Data Types

The package provides standardized MySQL data type definitions:

const dataTypes = new MySQLDrizzleDataTypes();

const table = dataTypes.dbTable('example', {
  // Numeric types
  id: dataTypes.dbBigInt('id', { mode: 'number' }).primaryKey().autoincrement(),
  count: dataTypes.dbInt('count'),
  price: dataTypes.dbDecimal('price', { precision: 10, scale: 2 }),
  
  // String types
  name: dataTypes.dbVarChar('name', { length: 255 }),
  description: dataTypes.dbText('description'),
  
  // Date/Time types
  createdAt: dataTypes.dbTimestamp('created_at').defaultNow(),
  updatedAt: dataTypes.dbTimestamp('updated_at').onUpdateNow(),
  
  // Other types
  status: dataTypes.dbEnum('status', ['active', 'inactive']),
  metadata: dataTypes.dbJson('metadata'),
  isEnabled: dataTypes.dbBoolean('is_enabled')
});

Error Handling

The package provides unified error handling for MySQL-specific errors:

import { handleMySQLError } from '@drizzle-adapter/mysql-core';

try {
  // Your database operation
} catch (error) {
  throw handleMySQLError(error);
}

Query Building

The package includes utilities for building MySQL-specific queries:

import { 
  buildInsertQuery,
  buildUpdateQuery,
  buildDeleteQuery,
  buildSelectQuery
} from '@drizzle-adapter/mysql-core';

// Build INSERT query
const insertQuery = buildInsertQuery(table, data);

// Build UPDATE query with JSON operations
const updateQuery = buildUpdateQuery(table, {
  metadata: sql`JSON_SET(metadata, '$.key', 'value')`
});

// Build DELETE query with conditions
const deleteQuery = buildDeleteQuery(table, conditions);

// Build SELECT query with joins
const selectQuery = buildSelectQuery({
  table,
  joins: [...],
  conditions: [...],
  orderBy: [...]
});

Type Mapping

The package handles MySQL-specific type mapping:

import { mapMySQLType } from '@drizzle-adapter/mysql-core';

// Map JavaScript types to MySQL types
const mysqlType = mapMySQLType(value);

// Map MySQL types to JavaScript types
const jsValue = mapToJavaScript(mysqlValue, mysqlType);

Contributing

This package is maintained as part of the Drizzle Adapter ecosystem. If you'd like to contribute:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

版本与发布记录

@drizzle-adapter/mysql-core 共发布 13 个版本,首次发布于 2024/12/03;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.1.2latest2026/09/251 个月前
1.1.12026/03/267 个月前
1.0.142025/07/171.3 年前
1.0.122025/07/121.3 年前
1.0.102025/07/121.3 年前
1.0.92025/04/201.6 年前

关于 @drizzle-adapter/mysql-core 的常见问题

如何安装 @drizzle-adapter/mysql-core?

在项目目录运行 npm install @drizzle-adapter/mysql-core,或使用 pnpm add / yarn add / bun add。

@drizzle-adapter/mysql-core 支持 TypeScript 吗?

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

@drizzle-adapter/mysql-core 支持 ESM 还是 CommonJS?

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

@drizzle-adapter/mysql-core 可以商用吗?

@drizzle-adapter/mysql-core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@drizzle-adapter/mysql-core 的下载量有多少?

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

@drizzle-adapter/mysql-core 还在维护吗?

最新版本 1.1.2 发布于 2026/09/25(1 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 2 个;首次发布于 2024/12/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。