@drizzle-adapter/mysql-core
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

@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

Related Packages

Readme

Keywords

none

Package Sidebar

Install

npm i @drizzle-adapter/mysql-core

Weekly Downloads

8

Version

1.0.9

License

none

Unpacked Size

45.5 kB

Total Files

17

Last publish

Collaborators

  • dmitryrechkin