GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — remix/packages/data-table-mysql at main · swernerx/remix

Expand file tree

/

data-table-mysql

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

data-table-mysql

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
.changes
.changes
 
 
src
src
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package.json
package.json
 
 
remix-test.config.ts
remix-test.config.ts
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 

README.md

Outline

data-table-mysql

MySQL adapter for remix/data-table. Use this package when you want data-table APIs backed by mysql2.

Features

  • Native mysql2 Integration: Works with mysql2/promise Pool and PoolConnection instances
  • Full data-table API Support: Queries, relations, writes, and transactions
  • Adapter-Owned Compiler: SQL compilation lives in this adapter, with optional shared pure helpers from data-table
  • Multi-Statement Migrations: executeScript() runs up.sql / down.sql files via mysql2 (requires multipleStatements: true)
  • MySQL Capabilities Enabled By Default:
    • returning: false
    • savepoints: true
    • upsert: true
    • transactionalDdl: false
    • migrationLock: true

Installation

npm i remix mysql2

Usage

import { createPool } from 'mysql2/promise'
import { createDatabase } from 'remix/data-table'
import { createMysqlDatabaseAdapter } from 'remix/data-table/mysql'

let pool = createPool(process.env.DATABASE_URL as string)
let db = createDatabase(createMysqlDatabaseAdapter(pool))

Use db.query(...), relation loading, and transactions from remix/data-table. Import any driver-specific types you need directly from mysql2/promise.

Adapter Capabilities

data-table-mysql reports this capability set by default:

  • returning: false
  • savepoints: true
  • upsert: true
  • transactionalDdl: false
  • migrationLock: true

Advanced Usage

Multi-Statement Migrations

remix/data-table/migrations sends each migration to the adapter as a single multi-statement SQL script. mysql2 only accepts multi-statement scripts when the connection is created with multipleStatements: true:

import { createPool } from 'mysql2/promise'

let pool = createPool({
  uri: process.env.DATABASE_URL,
  multipleStatements: true,
})

returning On MySQL

MySQL does not natively support SQL RETURNING. In this adapter, using returning on write operations throws DataTableQueryError.

Use write metadata (affectedRows, insertId) on MySQL, or switch adapters when returned rows are required.

import { DataTableQueryError } from 'remix/data-table'

try {
  await db
    .query(Accounts)
    .insert({ email: '[email protected]', status: 'active' }, { returning: ['id'] })
} catch (error) {
  if (error instanceof DataTableQueryError) {
    // insert() returning is not supported by this adapter
  }
}

Running integration tests locally

To start a local MySQL container matching CI:

podman run --name mysql \
  -e MYSQL_ROOT_PASSWORD=root \
  -e MYSQL_DATABASE=remix \
  -p 3306:3306 \
  -d mysql:8

Then run:

REMIX_DATA_TABLE_MYSQL_TEST_URL=mysql://root:[email protected]:3306/remix \
pnpm test src/lib/adapter.integration.test.ts

Remove the container when you are done:

podman rm -f mysql

Related Packages

  • data-table - Core query/relations API
  • data-schema - Schema parsing and validation
  • data-table-postgres - PostgreSQL adapter
  • data-table-sqlite - SQLite adapter

License

See LICENSE

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.